< Summary

Information
Class: System.Net.Http.ConnectionSetupDistributedTracing
Assembly: System.Net.Http
File(s): D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\ConnectionPool\ConnectionSetupDistributedTracing.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 62
Coverable lines: 62
Total lines: 96
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 28
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%110%
StartConnectionSetupActivity(...)0%880%
StopConnectionSetupActivity(...)0%660%
ReportError(...)0%440%
StartWaitForConnectionActivity(...)0%220%
AddConnectionLinkToRequestActivity(...)0%880%

File(s)

D:\runner\runtime\src\libraries\System.Net.Http\src\System\Net\Http\SocketsHttpHandler\ConnectionPool\ConnectionSetupDistributedTracing.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.Collections.Generic;
 5using System.Diagnostics;
 6using System.Threading;
 7
 8namespace System.Net.Http
 9{
 10    // Implements distributed tracing logic for managing the "HTTP connection_setup" and "HTTP wait_for_connection" Acti
 11    internal static class ConnectionSetupDistributedTracing
 12    {
 013        private static readonly ActivitySource s_connectionsActivitySource = new ActivitySource(DiagnosticsHandlerLoggin
 14
 15        public static Activity? StartConnectionSetupActivity(bool isSecure, string? serverAddress, int port)
 016        {
 017            Activity? activity = null;
 018            if (s_connectionsActivitySource.HasListeners())
 019            {
 20                // Connection activities should be new roots and not parented under whatever
 21                // request happens to be in progress when the connection is started.
 022                Activity.Current = null;
 023                activity = s_connectionsActivitySource.StartActivity(DiagnosticsHandlerLoggingStrings.ConnectionSetupAct
 024            }
 25
 026            if (activity is not null)
 027            {
 028                Debug.Assert(serverAddress is not null, "serverAddress should not be null when System.Net.Http.EnableAct
 029                activity.DisplayName = $"HTTP connection_setup {serverAddress}:{port}";
 030                if (activity.IsAllDataRequested)
 031                {
 032                    activity.SetTag("server.address", serverAddress);
 033                    activity.SetTag("server.port", port);
 034                    activity.SetTag("url.scheme", isSecure ? "https" : "http");
 035                }
 036            }
 37
 038            return activity;
 039        }
 40
 41        public static void StopConnectionSetupActivity(Activity activity, Exception? exception, IPEndPoint? remoteEndPoi
 042        {
 043            Debug.Assert(activity is not null);
 044            if (exception is not null)
 045            {
 046                ReportError(activity, exception);
 047            }
 48            else
 049            {
 050                if (activity.IsAllDataRequested && remoteEndPoint is not null)
 051                {
 052                    activity.SetTag("network.peer.address", remoteEndPoint.Address.ToString());
 053                }
 054            }
 55
 056            activity.Stop();
 057        }
 58
 59        public static void ReportError(Activity? activity, Exception exception)
 060        {
 061            Debug.Assert(exception is not null);
 062            if (activity is null) return;
 063            activity.SetStatus(ActivityStatusCode.Error);
 64
 065            if (activity.IsAllDataRequested)
 066            {
 067                DiagnosticsHelper.TryGetErrorType(null, exception, out string? errorType);
 068                Debug.Assert(errorType is not null, "DiagnosticsHelper.TryGetErrorType() should succeed whenever an exce
 069                activity.SetTag("error.type", errorType);
 070            }
 071        }
 72
 73        public static Activity? StartWaitForConnectionActivity(HttpAuthority authority)
 074        {
 075            Activity? activity = s_connectionsActivitySource.StartActivity(DiagnosticsHandlerLoggingStrings.WaitForConne
 076            activity?.DisplayName = $"HTTP wait_for_connection {authority.HostValue}:{authority.Port}";
 77
 078            return activity;
 079        }
 80
 81        public static void AddConnectionLinkToRequestActivity(Activity connectionSetupActivity)
 082        {
 083            Debug.Assert(connectionSetupActivity is not null);
 84
 85            // We only support links for request activities created by the "System.Net.Http" ActivitySource.
 086            if (GlobalHttpSettings.DiagnosticsHandler.EnableActivityPropagation && DiagnosticsHandler.s_activitySource.H
 087            {
 088                Activity? requestActivity = Activity.Current;
 089                if (requestActivity?.Source == DiagnosticsHandler.s_activitySource)
 090                {
 091                    requestActivity.AddLink(new ActivityLink(connectionSetupActivity.Context));
 092                }
 093            }
 094        }
 95    }
 96}