@@ -47,20 +47,19 @@ public static void ActivityStarted<T>(string sourceName, T activity, OpenTelemet
4747 string ? rawTraceId = null ;
4848 string ? rawSpanId = null ;
4949
50- // for non-IW3CActivity interfaces we'll use Activity.Id and string.Empty as the key as they don't have a guaranteed TraceId+SpanId
51- // for IW3CActivity interfaces we'll use the Activity.TraceId + Activity.SpanId as the key
52- // have to also validate that the TraceId and SpanId actually exist and aren't null - as they can be in some cases
50+ // for non-W3C activities using Hierarchical IDs (both IW3CActivity and IActivity) we use Activity.Id and string.Empty
51+ // for W3C ID activities (always IW3CActivity) we'll use the Activity.TraceId + Activity.SpanId as the key
5352 ActivityKey ? activityKey = null ;
5453
55- if ( activity is IW3CActivity w3cActivity )
54+ if ( activity is IW3CActivity activity3 )
5655 {
57- var activityTraceId = w3cActivity . TraceId ;
58- var activitySpanId = w3cActivity . SpanId ;
56+ var activityTraceId = activity3 . TraceId ;
57+ var activitySpanId = activity3 . SpanId ;
5958
6059 if ( ! StringUtil . IsNullOrEmpty ( activityTraceId ) )
6160 {
6261 // W3C ID
63- if ( w3cActivity is { ParentSpanId : { } parentSpanId } )
62+ if ( activity3 is { ParentSpanId : { } parentSpanId } )
6463 {
6564 // This will be true for activities using W3C IDs which have a parent span.
6665 // The ParentSpanId will be created from the Parent if that is set (or parsed out of _parentId if necessary)
@@ -91,7 +90,7 @@ public static void ActivityStarted<T>(string sourceName, T activity, OpenTelemet
9190 else
9291 {
9392 // No traceID, so much be Hierarchical ID
94- if ( w3cActivity . ParentSpanId is { } parentSpanId )
93+ if ( activity3 . ParentSpanId is { } parentSpanId )
9594 {
9695 // This is a weird scenario - we're in a hierarchical ID, we don't have a trace ID, but we _do_ have a _parentSpanID?!
9796 // should never hit this path unless we've gone wrong somewhere
@@ -100,7 +99,7 @@ public static void ActivityStarted<T>(string sourceName, T activity, OpenTelemet
10099 else
101100 {
102101 // Since _parentSpanID is null, this either grabs _parentId, or Parent.Id, depending on what was set
103- var parentId = w3cActivity . ParentId ;
102+ var parentId = activity3 . ParentId ;
104103 if ( ! StringUtil . IsNullOrEmpty ( parentId ) && ActivityMappingById . TryGetValue ( new ActivityKey ( parentId ) , out ActivityMapping mapping ) )
105104 {
106105 parent = mapping . Scope . Span . Context ;
@@ -117,15 +116,15 @@ public static void ActivityStarted<T>(string sourceName, T activity, OpenTelemet
117116 // We ensure the activity follows the same TraceId as the span
118117 // And marks the ParentId the current spanId
119118 // TraceId (always 32 chars long even when using 64-bit ids)
120- w3cActivity . TraceId = activeSpan . Context . RawTraceId ;
121- activityTraceId = w3cActivity . TraceId ;
119+ activity3 . TraceId = activeSpan . Context . RawTraceId ;
120+ activityTraceId = activity3 . TraceId ;
122121
123122 // SpanId (always 16 chars long)
124- w3cActivity . RawParentSpanId = activeSpan . Context . RawSpanId ;
123+ activity3 . RawParentSpanId = activeSpan . Context . RawSpanId ;
125124
126125 // We clear internals Id and ParentId values to force recalculation.
127- w3cActivity . RawId = null ;
128- w3cActivity . RawParentId = null ;
126+ activity3 . RawId = null ;
127+ activity3 . RawParentId = null ;
129128
130129 // Avoid recalculation of the traceId.
131130 traceId = activeSpan . TraceId128 ;
0 commit comments