@@ -307,20 +307,6 @@ public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, Wai
307307 finally
308308 {
309309 waitForConnectionActivity . Stop ( request , Pool , exception ) ;
310- waitForConnectionActivity ? . Stop ( ) ;
311- if ( queueStartingTimestamp != 0 )
312- {
313- TimeSpan duration = Stopwatch . GetElapsedTime ( queueStartingTimestamp ) ;
314- if ( GlobalHttpSettings . MetricsHandler . IsGloballyEnabled )
315- {
316- _pool . Settings . _metrics ! . RequestLeftQueue ( request , Pool , duration , versionMajor : 3 ) ;
317- }
318-
319- if ( HttpTelemetry . Log . IsEnabled ( ) )
320- {
321- HttpTelemetry . Log . RequestLeftQueue ( versionMajor : 3 , duration ) ;
322- }
323- }
324310 }
325311
326312 if ( quicStream == null )
@@ -959,12 +945,12 @@ async ValueTask SkipUnknownPayloadAsync(long payloadLength)
959945 /// </summary>
960946 internal struct WaitForHttp3ConnectionActivity
961947 {
962- private readonly SocketsHttpHandlerMetrics _metrics ;
948+ private readonly SocketsHttpHandlerMetrics ? _metrics ;
963949 private readonly HttpAuthority _authority ;
964950 private Activity ? _activity ;
965951 private long _startTimestamp ;
966952
967- public WaitForHttp3ConnectionActivity ( SocketsHttpHandlerMetrics metrics , HttpAuthority authority )
953+ public WaitForHttp3ConnectionActivity ( SocketsHttpHandlerMetrics ? metrics , HttpAuthority authority )
968954 {
969955 _metrics = metrics ;
970956 _authority = authority ;
@@ -975,7 +961,7 @@ public WaitForHttp3ConnectionActivity(SocketsHttpHandlerMetrics metrics, HttpAut
975961 public void Start ( )
976962 {
977963 Debug . Assert ( ! Started ) ;
978- _startTimestamp = HttpTelemetry . Log . IsEnabled ( ) || _metrics ! . RequestsQueueDuration . Enabled ? Stopwatch . GetTimestamp ( ) : 0 ;
964+ _startTimestamp = HttpTelemetry . Log . IsEnabled ( ) || ( GlobalHttpSettings . MetricsHandler . IsGloballyEnabled && _metrics ! . RequestsQueueDuration . Enabled ) ? Stopwatch . GetTimestamp ( ) : 0 ;
979965 _activity = ConnectionSetupDistributedTracing . StartWaitForConnectionActivity ( _authority ) ;
980966 Started = true ;
981967 }
@@ -992,14 +978,19 @@ public void Stop(HttpRequestMessage request, HttpConnectionPool pool, Exception?
992978 if ( _startTimestamp != 0 )
993979 {
994980 TimeSpan duration = Stopwatch . GetElapsedTime ( _startTimestamp ) ;
995- _metrics ! . RequestLeftQueue ( request , pool , duration , versionMajor : 3 ) ;
981+
982+ if ( GlobalHttpSettings . MetricsHandler . IsGloballyEnabled )
983+ {
984+ _metrics ! . RequestLeftQueue ( request , pool , duration , versionMajor : 3 ) ;
985+ }
996986 if ( HttpTelemetry . Log . IsEnabled ( ) )
997987 {
998988 HttpTelemetry . Log . RequestLeftQueue ( 3 , duration ) ;
999989 }
1000990 }
1001991 }
1002992
993+ [ Conditional ( "DEBUG" ) ]
1003994 public void AssertActivityNotRunning ( )
1004995 {
1005996 Debug . Assert ( _activity ? . IsStopped != false ) ;
0 commit comments