44using System ;
55using System . Collections ;
66using System . Collections . Generic ;
7- using System . Diagnostics ;
87using System . Globalization ;
98using System . Reflection ;
109using Microsoft . AspNetCore . Http ;
@@ -14,9 +13,9 @@ namespace Microsoft.AspNetCore.Hosting
1413{
1514 internal static class HostingLoggerExtensions
1615 {
17- public static IDisposable RequestScope ( this ILogger logger , HttpContext httpContext , Activity activity )
16+ public static IDisposable RequestScope ( this ILogger logger , HttpContext httpContext , string activityId )
1817 {
19- return logger . BeginScope ( new HostingLogScope ( httpContext , activity ) ) ;
18+ return logger . BeginScope ( new HostingLogScope ( httpContext , activityId ) ) ;
2019 }
2120
2221 public static void ApplicationError ( this ILogger logger , Exception exception )
@@ -97,15 +96,15 @@ private class HostingLogScope : IReadOnlyList<KeyValuePair<string, object>>
9796 {
9897 private readonly string _path ;
9998 private readonly string _traceIdentifier ;
100- private readonly Activity _activity ;
99+ private readonly string _activityId ;
101100
102101 private string _cachedToString ;
103102
104103 public int Count
105104 {
106105 get
107106 {
108- return 5 ;
107+ return 3 ;
109108 }
110109 }
111110
@@ -123,29 +122,20 @@ public KeyValuePair<string, object> this[int index]
123122 }
124123 else if ( index == 2 )
125124 {
126- return new KeyValuePair < string , object > ( "SpanId" , _activity . GetSpanId ( ) ) ;
127- }
128- else if ( index == 3 )
129- {
130- return new KeyValuePair < string , object > ( "TraceId" , _activity . GetTraceId ( ) ) ;
131- }
132- else if ( index == 4 )
133- {
134- return new KeyValuePair < string , object > ( "ParentId" , _activity . GetParentId ( ) ) ;
125+ return new KeyValuePair < string , object > ( "ActivityId" , _activityId ) ;
135126 }
136127
137128 throw new ArgumentOutOfRangeException ( nameof ( index ) ) ;
138129 }
139130 }
140131
141- public HostingLogScope ( HttpContext httpContext , Activity activity )
132+ public HostingLogScope ( HttpContext httpContext , string activityId )
142133 {
143134 _traceIdentifier = httpContext . TraceIdentifier ;
144135 _path = ( httpContext . Request . PathBase . HasValue
145136 ? httpContext . Request . PathBase + httpContext . Request . Path
146137 : httpContext . Request . Path ) . ToString ( ) ;
147-
148- _activity = activity ;
138+ _activityId = activityId ;
149139 }
150140
151141 public override string ToString ( )
@@ -154,12 +144,10 @@ public override string ToString()
154144 {
155145 _cachedToString = string . Format (
156146 CultureInfo . InvariantCulture ,
157- "RequestPath:{0} RequestId:{1}, SpanId :{2}, TraceId:{3}, ParentId:{4 }" ,
147+ "RequestPath:{0} RequestId:{1}, ActivityId :{2}" ,
158148 _path ,
159149 _traceIdentifier ,
160- _activity . GetSpanId ( ) ,
161- _activity . GetTraceId ( ) ,
162- _activity . GetParentId ( ) ) ;
150+ _activityId ) ;
163151 }
164152
165153 return _cachedToString ;
0 commit comments