From fd7976dbff1818bf58af4c4ec4b01c4d0f43f20d Mon Sep 17 00:00:00 2001 From: Aaron Stannard Date: Mon, 18 Nov 2019 16:40:02 -0600 Subject: [PATCH] make B3 header checking case-insensitive Replaces #23 --- .../Propagation/B3Propagation.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Petabridge.Tracing.ApplicationInsights/Propagation/B3Propagation.cs b/src/Petabridge.Tracing.ApplicationInsights/Propagation/B3Propagation.cs index 7562575..526df21 100644 --- a/src/Petabridge.Tracing.ApplicationInsights/Propagation/B3Propagation.cs +++ b/src/Petabridge.Tracing.ApplicationInsights/Propagation/B3Propagation.cs @@ -20,10 +20,22 @@ namespace Petabridge.Tracing.ApplicationInsights.Propagation /// public sealed class B3Propagator : IPropagator { + /* + * 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); @@ -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; }