public async Task Invoke(HttpContext context) { // TODO: Use pathstrings instead? string route = context.Request.Path.ToString().ToLower(); if (_options.IgnoreRoutesStartWith != null && _options.IgnoreRoutesStartWith.Any(i => route.StartsWith(i))) { await _next.Invoke(context); return; } if (_options.IgnoreRoutesContains != null && _options.IgnoreRoutesContains.Any(i => route.Contains(i))) { await _next.Invoke(context); return; } if (_options.IgnoreRoutesConcrete != null && _options.IgnoreRoutesConcrete.Any(i => route == i)) { await _next.Invoke(context); return; } var watch = Stopwatch.StartNew(); await _next.Invoke(context); watch.Stop(); var labelValues = new string[_labelsCount]; var index = 0; if (_options.IncludeStatusCode) { labelValues[index++] = context.Response.StatusCode.ToString(); } if (_options.IncludeMethod) { labelValues[index++] = context.Request.Method; } if (_options.IncludePath) { labelValues[index++] = route; } if (_options.CustomLabels != null) { foreach (var customLabel in _options.CustomLabels) { labelValues[index++] = customLabel.Value; } } _requestDurations.WithLabels(labelValues).Observe(watch.Elapsed.TotalSeconds); }