public MetricsMiddleware(RequestDelegate next, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider, MetricsMiddlewareOptions options)
        {
            _next = next;
            _actionDescriptorCollectionProvider = actionDescriptorCollectionProvider;
            _options = options;

            ErrorRequestsProcessed   = Metrics.CreateCounter("server_request_error_total", "Number of unsuccessfull processed requests.", "method", "error_code");
            OngoingRequests          = Metrics.CreateGauge("server_request_in_progress", "Number of ongoing requests.", "method");
            RequestResponseHistogram = Metrics.CreateHistogram("server_request_duration_seconds", "Histogram of request duration in seconds.",
                                                               new HistogramConfiguration()
            {
                LabelNames = new string[] { "method" },
                Buckets    = _options.Buckets
            });
        }
 public static IApplicationBuilder UseMetricsMiddleware(this IApplicationBuilder builder, MetricsMiddlewareOptions options = null)
 {
     return(builder.UseMiddleware <MetricsMiddleware>(options ?? new MetricsMiddlewareOptions()));
 }