@@ -65,6 +65,11 @@ public void BeginRequest(HttpContext httpContext, HostingApplication.Context con
65
65
66
66
if ( context . Activity is Activity activity )
67
67
{
68
+ // Add some ASP.NET Core specific properties as tags
69
+ activity . AddTag ( "aspnet.traceidentifier" , httpContext . TraceIdentifier ) ;
70
+ var path = ( httpContext . Request . PathBase . HasValue ? httpContext . Request . PathBase + httpContext . Request . Path : httpContext . Request . Path ) . ToString ( ) ;
71
+ activity . AddTag ( "aspnet.requestpath" , path ) ;
72
+
68
73
if ( httpContext . Features . Get < IHttpActivityFeature > ( ) is IHttpActivityFeature feature )
69
74
{
70
75
feature . Activity = activity ;
@@ -88,11 +93,6 @@ public void BeginRequest(HttpContext httpContext, HostingApplication.Context con
88
93
// To avoid allocation, return a null scope if the logger is not on at least to some degree.
89
94
if ( loggingEnabled )
90
95
{
91
- // Scope may be relevant for a different level of logging, so we always create it
92
- // see: https://github.com/aspnet/Hosting/pull/944
93
- // Scope can be null if logging is not on.
94
- context . Scope = Log . RequestScope ( _logger , httpContext ) ;
95
-
96
96
if ( _logger . IsEnabled ( LogLevel . Information ) )
97
97
{
98
98
if ( startTimestamp == 0 )
@@ -173,9 +173,6 @@ public void RequestEnd(HttpContext httpContext, Exception? exception, HostingApp
173
173
HostingEventSource . Log . RequestFailed ( ) ;
174
174
}
175
175
}
176
-
177
- // Logging Scope is finshed with
178
- context . Scope ? . Dispose ( ) ;
179
176
}
180
177
181
178
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
@@ -453,74 +450,4 @@ private void StopActivity(Activity activity, HttpContext httpContext)
453
450
WriteDiagnosticEvent ( _diagnosticListener , ActivityStopKey , httpContext ) ;
454
451
activity . Stop ( ) ; // Resets Activity.Current (we want this after the Write)
455
452
}
456
-
457
- private static class Log
458
- {
459
- public static IDisposable ? RequestScope ( ILogger logger , HttpContext httpContext )
460
- {
461
- return logger . BeginScope ( new HostingLogScope ( httpContext ) ) ;
462
- }
463
-
464
- private sealed class HostingLogScope : IReadOnlyList < KeyValuePair < string , object > >
465
- {
466
- private readonly string _path ;
467
- private readonly string _traceIdentifier ;
468
-
469
- private string ? _cachedToString ;
470
-
471
- public int Count => 2 ;
472
-
473
- public KeyValuePair < string , object > this [ int index ]
474
- {
475
- get
476
- {
477
- if ( index == 0 )
478
- {
479
- return new KeyValuePair < string , object > ( "RequestId" , _traceIdentifier ) ;
480
- }
481
- else if ( index == 1 )
482
- {
483
- return new KeyValuePair < string , object > ( "RequestPath" , _path ) ;
484
- }
485
-
486
- throw new ArgumentOutOfRangeException ( nameof ( index ) ) ;
487
- }
488
- }
489
-
490
- public HostingLogScope ( HttpContext httpContext )
491
- {
492
- _traceIdentifier = httpContext . TraceIdentifier ;
493
- _path = ( httpContext . Request . PathBase . HasValue
494
- ? httpContext . Request . PathBase + httpContext . Request . Path
495
- : httpContext . Request . Path ) . ToString ( ) ;
496
- }
497
-
498
- public override string ToString ( )
499
- {
500
- if ( _cachedToString == null )
501
- {
502
- _cachedToString = string . Format (
503
- CultureInfo . InvariantCulture ,
504
- "RequestPath:{0} RequestId:{1}" ,
505
- _path ,
506
- _traceIdentifier ) ;
507
- }
508
-
509
- return _cachedToString ;
510
- }
511
-
512
- public IEnumerator < KeyValuePair < string , object > > GetEnumerator ( )
513
- {
514
- for ( var i = 0 ; i < Count ; ++ i )
515
- {
516
- yield return this [ i ] ;
517
- }
518
- }
519
-
520
- IEnumerator IEnumerable . GetEnumerator ( )
521
- {
522
- return GetEnumerator ( ) ;
523
- }
524
- }
525
- }
526
453
}
0 commit comments