public override void OnHttpRequestCompleted(HttpContext httpContext) { if (!_options.ShouldInstrument(httpContext.Request.Path)) { return; } string?operation = httpContext.GetOperation(); if (operation is null) { return; // We don't care if this isn't a genuine operation // Should we be tracking missed operations? } _httpRequestDurationMetric .WithLabels(operation, httpContext.Response.StatusCode.ToString()) .Observe(httpContext.GetRequestDuration().TotalSeconds); if (HasError(httpContext, out (ErrorType Type, string?Dependency)? error)) { _httpErrorsTotalMetric .WithLabels(operation, error !.Value.Type.GetStringValue(), error !.Value.Dependency ?? string.Empty) .Inc(); } _httpRequestsInProgressMetric .WithLabels(operation) .Dec(); }
public override void OnEndpointMatched(HttpContext httpContext) { if (!_options.ShouldInstrument(httpContext.Request.Path)) { return; } string?operation = GetOperation(httpContext); if (operation is null) { return; } httpContext.SetOperation(operation); // Avoids calculating again later _httpRequestsInProgressMetric .WithLabels(operation) .Inc(); }