/// <summary>
        ///     Extracts traceId and spanId from a WavefrontSpanContext and constructs a Jaeger
        ///     client compatible header of the form traceId:spanId:parentId:samplingDecision.
        /// </summary>
        private string ContextToTraceIdHeader(WavefrontSpanContext context)
        {
            string traceId          = GuidToHex(context.GetTraceId());
            string spanId           = GuidToHex(context.GetSpanId());
            bool   samplingDecision = context.GetSamplingDecision() ?? false;
            string decision         = samplingDecision ? "1" : "0";
            string parentId         = Guid.TryParse(context.GetBaggageItem(ParentIdKey), out Guid guid) ?
                                      GuidToHex(guid) : "0";

            return($"{traceId}:{spanId}:{parentId}:{decision}");
        }
        public void TestTraceIdExtractEncoded()
        {
            string val        = "3871de7e09c53ae8%3A7499dd16d98ab60e%3A3771de7e09c55ae8%3A1";
            var    dictionary = new Dictionary <string, string>();

            dictionary.Add(JaegerHeader, val);
            var textMapExtractAdapter = new TextMapExtractAdapter(dictionary);
            WavefrontSpanContext ctx  = wfJaegerPropagator.Extract(textMapExtractAdapter);

            Assert.NotNull(ctx);
            Assert.Equal("00000000-0000-0000-3871-de7e09c53ae8", ctx.TraceId);
            Assert.Equal("00000000-0000-0000-7499-dd16d98ab60e", ctx.SpanId);
            Assert.Equal("00000000-0000-0000-7499-dd16d98ab60e", ctx.GetBaggageItem(ParentIdKey));
            Assert.True(ctx.GetSamplingDecision() ?? false);
        }
 /// <inheritdoc />
 public void Inject <TCarrier>(WavefrontSpanContext spanContext, TCarrier carrier)
 {
     if (carrier is ITextMap textMap)
     {
         textMap.Set(traceIdHeader, ContextToTraceIdHeader(spanContext));
         foreach (var entry in spanContext.GetBaggageItems())
         {
             textMap.Set(baggagePrefix + entry.Key, entry.Value);
         }
         if (spanContext.IsSampled())
         {
             textMap.Set(SamplingDecisionKey, spanContext.GetSamplingDecision().ToString());
         }
     }
     else
     {
         throw new ArgumentException("Invalid carrier " + carrier.GetType());
     }
 }