Skip to content

Commit

Permalink
make B3 header checking case-insensitive (#29)
Browse files Browse the repository at this point in the history
Replaces #23
  • Loading branch information
Aaronontheweb committed Nov 18, 2019
1 parent f1a07b8 commit ee8ae4a
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,22 @@ namespace Petabridge.Tracing.ApplicationInsights.Propagation
/// </remarks>
public sealed class B3Propagator : IPropagator<ITextMap>
{
/*
* Keep old headers for outbound
*
*/
internal const string B3TraceId = "X-B3-TraceId";
internal const string B3SpanId = "X-B3-SpanId";
internal const string B3ParentId = "X-B3-ParentSpanId";

/*
* Keep new headers for case-insensitive analysis
*
*/
internal const string B3TraceIdLower = "x-b3-traceid";
internal const string B3SpanIdLower = "x-b3-spanid";
internal const string B3ParentIdLower = "x-b3-parentspanid";

public void Inject(ApplicationInsightsSpanContext context, ITextMap carrier)
{
carrier.Set(B3TraceId, context.TraceId);
Expand All @@ -38,15 +50,15 @@ public ApplicationInsightsSpanContext Extract(ITextMap carrier)
string spanId = null;
string parentId = null;
foreach (var entry in carrier)
switch (entry.Key)
switch (entry.Key.ToLowerInvariant())
{
case B3TraceId:
case B3TraceIdLower:
traceId = entry.Value;
break;
case B3SpanId:
case B3SpanIdLower:
spanId = entry.Value;
break;
case B3ParentId:
case B3ParentIdLower:
parentId = entry.Value;
break;
}
Expand Down

0 comments on commit ee8ae4a

Please sign in to comment.