< Summary

Information
Class: System.Net.Http.Metrics.SocketsHttpHandlerMetrics
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\Metrics\SocketsHttpHandlerMetrics.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 41
Coverable lines: 41
Total lines: 64
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
RequestLeftQueue(...)0%12120%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\Metrics\SocketsHttpHandlerMetrics.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Diagnostics;
 5using System.Diagnostics.Metrics;
 6
 7namespace System.Net.Http.Metrics
 8{
 09    internal sealed class SocketsHttpHandlerMetrics(Meter meter)
 10    {
 011        public readonly UpDownCounter<long> OpenConnections = meter.CreateUpDownCounter<long>(
 012            name: "http.client.open_connections",
 013            unit: "{connection}",
 014            description: "Number of outbound HTTP connections that are currently active or idle on the client.");
 15
 016        public readonly Histogram<double> ConnectionDuration = meter.CreateHistogram<double>(
 017            name: "http.client.connection.duration",
 018            unit: "s",
 019            description: "The duration of successfully established outbound HTTP connections.",
 020            advice: new InstrumentAdvice<double>()
 021            {
 022                // These values are not based on a standard and may change in the future.
 023                HistogramBucketBoundaries = [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 30, 60, 120, 300]
 024            });
 25
 026        public readonly Histogram<double> RequestsQueueDuration = meter.CreateHistogram<double>(
 027            name: "http.client.request.time_in_queue",
 028            unit: "s",
 029            description: "The amount of time requests spent on a queue waiting for an available connection.",
 030            advice: DiagnosticsHelper.ShortHistogramAdvice);
 31
 32        public void RequestLeftQueue(HttpRequestMessage request, HttpConnectionPool pool, TimeSpan duration, int version
 033        {
 034            Debug.Assert(versionMajor is 1 or 2 or 3);
 35
 036            if (RequestsQueueDuration.Enabled)
 037            {
 038                TagList tags = default;
 39
 40                // While requests may report HTTP/1.0 as the protocol, we treat all HTTP/1.X connections as HTTP/1.1.
 041                tags.Add("network.protocol.version", versionMajor switch
 042                {
 043                    1 => "1.1",
 044                    2 => "2",
 045                    _ => "3"
 046                });
 47
 048                tags.Add("url.scheme", pool.IsSecure ? "https" : "http");
 49
 050                Debug.Assert(pool.TelemetryServerAddress is not null, "TelemetryServerAddress should not be null when Sy
 051                tags.Add("server.address", pool.TelemetryServerAddress);
 52
 053                if (!pool.IsDefaultPort)
 054                {
 055                    tags.Add("server.port", pool.OriginAuthority.Port);
 056                }
 57
 058                tags.Add(DiagnosticsHelper.GetMethodTag(request.Method, out _));
 59
 060                RequestsQueueDuration.Record(duration.TotalSeconds, tags);
 061            }
 062        }
 63    }
 64}