public void With_prometheus_metrics()
        {
            _httpContext.SetOperation("op");

            var observer = new AspNetMetricsObserver(new AspNetMetricsOptions(), new PrometheusMetrics());

            observer.OnHttpRequestStarted(_httpContext);
            observer.OnEndpointMatched(_httpContext);
            _httpContext.Response.StatusCode = 200;
            observer.OnHttpRequestCompleted(_httpContext);
        }
        public void Sli_errors_increment_counter()
        {
            _httpContext.SetSliError(ErrorType.InternalDependency, "client-service");
            _httpContext.SetOperation("error-op");

            var observer = new AspNetMetricsObserver(new AspNetMetricsOptions(), _metrics);

            observer.OnHttpRequestStarted(_httpContext);
            observer.OnHttpRequestCompleted(_httpContext);

            var metric = _metrics.GetMetric <ICounter>("http_server_errors_total");

            metric.ShouldNotBeNull();
            metric.Collector.Verify(x => x.WithLabels("error-op", "internal_dependency", "client-service"), Times.Once);
            metric.Child.Verify(x => x.Inc(1), Times.Once);
        }
        public void Server_errors_increment_error_counter()
        {
            _httpContext.SetOperation("op");

            var observer = new AspNetMetricsObserver(new AspNetMetricsOptions(), _metrics);

            observer.OnHttpRequestStarted(_httpContext);
            observer.OnEndpointMatched(_httpContext);
            _httpContext.Response.StatusCode = 504;
            observer.OnHttpRequestCompleted(_httpContext);

            var metric = _metrics.GetMetric <ICounter>("http_server_errors_total");

            metric.ShouldNotBeNull();
            metric.Collector.Verify(x => x.WithLabels("op", "internal", String.Empty), Times.Once);
            metric.Child.Verify(x => x.Inc(1), Times.Once);
        }
        public void Can_track_requests()
        {
            _httpContext.SetOperation("op");

            var observer = new AspNetMetricsObserver(new AspNetMetricsOptions(), _metrics);

            observer.OnHttpRequestStarted(_httpContext);

            observer.OnEndpointMatched(_httpContext);

            var metric = _metrics.GetMetric <IGauge>("http_server_requests_in_progress");

            metric.ShouldNotBeNull();
            metric.Collector.Verify(x => x.WithLabels("op"), Times.Once);
            metric.Child.Verify(x => x.Inc(1), Times.Once);

            _httpContext.Response.StatusCode = 200;
            observer.OnHttpRequestCompleted(_httpContext);
        }