Skip to content

Commit d1485d3

Browse files
andrewlockclaude
andcommitted
Collapse B3 single-header extract around spans
Delete the NETCOREAPP/net461 ifdef in TryExtract and keep only the span-based path. Both HexString.TryParseTraceId and TryParseUInt64 already have ReadOnlySpan<char> overloads, so the shared path works on every TFM — saving two substring allocations per B3 single-header extraction on net461. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9ceacaf commit d1485d3

1 file changed

Lines changed: 0 additions & 40 deletions

File tree

tracer/src/Datadog.Trace/Propagators/B3SingleHeaderContextPropagator.cs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public bool TryExtract<TCarrier, TCarrierGetter>(TCarrier carrier, TCarrierGette
6262
return false;
6363
}
6464

65-
#if NETCOREAPP
6665
ReadOnlySpan<char> rawTraceId;
6766
ReadOnlySpan<char> rawSpanId;
6867
char rawSampled;
@@ -100,45 +99,6 @@ public bool TryExtract<TCarrier, TCarrierGetter>(TCarrier carrier, TCarrierGette
10099

101100
var samplingPriority = rawSampled == '1' ? 1 : 0;
102101
var spanContext = new SpanContext(traceId, parentId, samplingPriority, serviceName: null, null, rawTraceId.ToString(), rawSpanId.ToString(), isRemote: true);
103-
#else
104-
string? rawTraceId;
105-
string? rawSpanId;
106-
char rawSampled;
107-
108-
if (brValue.Length > 50 && brValue[32] == '-' && brValue[49] == '-')
109-
{
110-
// 128-bit trace id
111-
rawTraceId = brValue.Substring(0, 32);
112-
rawSpanId = brValue.Substring(33, 16);
113-
rawSampled = brValue[50];
114-
}
115-
else if (brValue.Length > 34 && brValue[16] == '-' && brValue[33] == '-')
116-
{
117-
// 64-bit trace id
118-
rawTraceId = brValue.Substring(0, 16);
119-
rawSpanId = brValue.Substring(17, 16);
120-
rawSampled = brValue[34];
121-
}
122-
else
123-
{
124-
return false;
125-
}
126-
127-
var success = HexString.TryParseTraceId(rawTraceId, out var traceId);
128-
129-
if (!success || traceId == TraceId.Zero)
130-
{
131-
return false;
132-
}
133-
134-
if (!HexString.TryParseUInt64(rawSpanId, out var parentId))
135-
{
136-
parentId = 0;
137-
}
138-
139-
var samplingPriority = rawSampled == '1' ? 1 : 0;
140-
var spanContext = new SpanContext(traceId, parentId, samplingPriority, serviceName: null, null, rawTraceId, rawSpanId, isRemote: true);
141-
#endif
142102

143103
context = new PropagationContext(spanContext, baggage: null);
144104

0 commit comments

Comments
 (0)