public static IObservabilityBuilder AddAspNetMetrics(this IObservabilityBuilder builder, Action <AspNetMetricsOptions>?configureOptions = null)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var options = new AspNetMetricsOptions();

            configureOptions?.Invoke(options);

            return(builder.AddDiagnosticSource("Microsoft.AspNetCore", new AspNetMetricsObserver(options)));
        }
Exemple #2
0
        public AspNetMetricsObserver(AspNetMetricsOptions options, IMetrics metrics)
        {
            _options = options ?? throw new ArgumentNullException(nameof(options));
            _metrics = metrics ?? throw new ArgumentNullException(nameof(metrics));

            // Support overrides here
            _httpErrorsTotalMetric        = CreateErrorTotalCounter();
            _httpRequestsInProgressMetric = CreateRequestsInProgressGauge();

            _httpRequestDurationMetric = options.RequestDurationMetricType switch
            {
                ObserverMetricType.Summary => CreateHttpRequestDurationSummary(),
                _ => CreateHttpRequestDurationHistogram()
            };
        }
Exemple #3
0
 public AspNetMetricsObserver(AspNetMetricsOptions options)
     : this(options, new PrometheusMetrics())
 {
 }