コード例 #1
0
        public SpanContext Extract(IPropagatorMap propagatorMap)
        {
            if (propagatorMap == null)
            {
                throw new ArgumentNullException(nameof(propagatorMap));
            }

            TraceId?traceId = null;
            ulong?  spanId = null, parentId = null;
            bool    sampled = false, debug = false;;

            foreach (var entry in propagatorMap)
            {
                if (string.Equals(entry.Key, TraceIdHeader, StringComparison.OrdinalIgnoreCase))
                {
                    if (TraceId.TryParse(entry.Value, out var _trace))
                    {
                        traceId = _trace;
                    }
                }
                else if (string.Equals(entry.Key, SpanIdHeader, StringComparison.OrdinalIgnoreCase))
                {
                    if (ulong.TryParse(entry.Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var _spanId))
                    {
                        spanId = _spanId;
                    }
                }
                else if (string.Equals(entry.Key, ParentIdHeader, StringComparison.OrdinalIgnoreCase))
                {
                    if (ulong.TryParse(entry.Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var _parent))
                    {
                        parentId = _parent;
                    }
                }
                else if (string.Equals(entry.Key, SampledHeader, StringComparison.OrdinalIgnoreCase))
                {
                    sampled = string.Equals(entry.Value, SampledTrue);
                }
                else if (string.Equals(entry.Key, DebugHeader, StringComparison.OrdinalIgnoreCase))
                {
                    debug = string.Equals(entry.Value, SampledTrue);
                }
            }
            if (traceId == null || spanId == null)
            {
                return(null);
            }
            return(new SpanContext(traceId.Value,
                                   spanId.Value,
                                   parentId,
                                   sampled,
                                   debug,
                                   shared: false));
        }
コード例 #2
0
 public void Inject(SpanContext spanContext, IPropagatorMap propagatorMap)
 {
     propagatorMap[TraceIdHeader] = spanContext.TraceId.ToString();
     propagatorMap[SpanIdHeader]  = spanContext.SpanId.ToString(IdFormat, CultureInfo.InvariantCulture);
     if (spanContext.ParentId.HasValue)
     {
         propagatorMap[ParentIdHeader] = spanContext.ParentId.Value.ToString(IdFormat, CultureInfo.InvariantCulture);
     }
     if (spanContext.Debug)
     {
         propagatorMap[DebugHeader] = SampledTrue;
     }
     else
     {
         if (spanContext.Sampled)
         {
             propagatorMap[SampledHeader] = SampledTrue;
         }
         else
         {
             propagatorMap[SampledHeader] = SampledFalse;
         }
     }
 }
コード例 #3
0
ファイル: Adapt.cs プロジェクト: lulzzz/Jasiri
 public static ITextMap ToTextMap(IPropagatorMap propagatorMap)
 => new TextMapAdapter(propagatorMap);
コード例 #4
0
 public TextMapAdapter(IPropagatorMap propagatorMap)
 {
     this.propagatorMap = propagatorMap ?? throw new ArgumentNullException(nameof(propagatorMap));
 }