public ISpanContext Extract(ITextMap carrier)
        {
            SpanContext spanContext             = null;
            Dictionary <string, string> baggage = new Dictionary <string, string>();

            foreach (var item in carrier)
            {
                if (item.Key.ToLower() == _spanContextKey.ToLower())
                {
                    spanContext = SpanContext.FromString(item.Value);
                }

                baggage.Add(item.Key, item.Value);
            }

            if (spanContext is null)
            {
                return(null);
            }

            if (baggage.Any())
            {
                spanContext = spanContext.WithBaggage(baggage);
            }

            return(spanContext);
        }
Ejemplo n.º 2
0
        protected override SpanContext Extract(ITextMap carrier)
        {
            SpanContext context = null;
            Dictionary <string, string> baggage = null;
            string debugId = null;

            foreach (var entry in carrier)
            {
                // TODO there should be no lower-case here
                string key = entry.Key.ToLowerInvariant();
                if (string.Equals(key, _contextKey, StringComparison.Ordinal))
                {
                    context = SpanContext.ContextFromString(DecodedValue(entry.Value));
                }
                else if (string.Equals(key, Constants.DebugIdHeaderKey, StringComparison.Ordinal))
                {
                    debugId = DecodedValue(entry.Value);
                }
                else if (key.StartsWith(_baggagePrefix, StringComparison.Ordinal))
                {
                    if (baggage == null)
                    {
                        baggage = new Dictionary <string, string>();
                    }
                    baggage[Keys.UnprefixedKey(key, _baggagePrefix)] = DecodedValue(entry.Value);
                }
            }
            if (context == null)
            {
                if (debugId != null)
                {
                    return(SpanContext.WithDebugId(debugId));
                }
                return(null);
            }
            if (baggage == null)
            {
                return(context);
            }
            return(context.WithBaggage(baggage));
        }