protected override void Inject(SpanContext spanContext, ITextMap carrier)
 {
     carrier.Set(TraceIdName, HexCodec.ToLowerHex(spanContext.TraceId.High, spanContext.TraceId.Low));
     if (spanContext.ParentId != 0L)
     {
         // Conventionally, parent id == 0 means the root span
         carrier.Set(ParentSpanIdName, HexCodec.ToLowerHex(spanContext.ParentId));
     }
     carrier.Set(SpanIdName, HexCodec.ToLowerHex(spanContext.SpanId));
     carrier.Set(SampledName, spanContext.IsSampled ? "1" : "0");
     if (spanContext.IsDebug)
     {
         carrier.Set(FlagsName, "1");
     }
 }
        protected override SpanContext Extract(ITextMap carrier)
        {
            long?            traceId  = null;
            long?            spanId   = null;
            long?            parentId = 0L; // Conventionally, parent id == 0 means the root span
            SpanContextFlags flags    = SpanContextFlags.None;

            foreach (var entry in carrier)
            {
                if (string.Equals(entry.Key, SampledName, StringComparison.OrdinalIgnoreCase))
                {
                    string value = entry.Value;
                    if (string.Equals(value, "1", StringComparison.Ordinal) || string.Equals(value, "true", StringComparison.OrdinalIgnoreCase))
                    {
                        flags |= SpanContextFlags.Sampled;
                    }
                }
                else if (string.Equals(entry.Key, TraceIdName, StringComparison.OrdinalIgnoreCase))
                {
                    traceId = HexCodec.LowerHexToUnsignedLong(entry.Value);
                }
                else if (string.Equals(entry.Key, ParentSpanIdName, StringComparison.OrdinalIgnoreCase))
                {
                    parentId = HexCodec.LowerHexToUnsignedLong(entry.Value);
                }
                else if (string.Equals(entry.Key, SpanIdName, StringComparison.OrdinalIgnoreCase))
                {
                    spanId = HexCodec.LowerHexToUnsignedLong(entry.Value);
                }
                else if (string.Equals(entry.Key, FlagsName, StringComparison.OrdinalIgnoreCase))
                {
                    if (string.Equals(entry.Value, "1", StringComparison.OrdinalIgnoreCase))
                    {
                        flags |= SpanContextFlags.Debug;
                    }
                }
            }

            if (traceId != null && parentId != null && spanId != null)
            {
                return(new SpanContext(new TraceId(traceId.Value), new SpanId(spanId.Value), new SpanId(parentId.Value), flags));
            }
            return(null);
        }