public override PropagationContext Extract <T>(PropagationContext context, T carrier, Func <T, string, IEnumerable <string> > getter)
        {
            if (this.defaultContext)
            {
                return(context);
            }

            IEnumerable <string> id = getter(carrier, this.idHeaderName);

            if (id.Count() <= 0)
            {
                return(context);
            }

            var traceparentParsed = TraceContextPropagator.TryExtractTraceparent(id.First(), out var traceId, out var spanId, out var traceoptions);

            if (!traceparentParsed)
            {
                return(context);
            }

            string tracestate = string.Empty;
            IEnumerable <string> tracestateCollection = getter(carrier, this.stateHeaderName);

            if (tracestateCollection?.Any() ?? false)
            {
                TraceContextPropagator.TryExtractTracestate(tracestateCollection.ToArray(), out tracestate);
            }

            return(new PropagationContext(
                       new ActivityContext(traceId, spanId, traceoptions, tracestate),
                       context.Baggage));
        }
        public void CanParseExampleFromSpec()
        {
            var headers = new Dictionary <string, string>
            {
                { TraceParent, $"00-{TraceId}-{SpanId}-01" },
                { TraceState, $"congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4,rojo=00-{TraceId}-00f067aa0ba902b7-01" },
            };

            var f   = new TraceContextPropagator();
            var ctx = f.Extract(default, headers, Getter);
        public void InjectExtract_TextMap_Ok()
        {
            var carrier = new TextMapCarrier();

            var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None));

            var format = new TraceContextPropagator();

            var tracer = TracerProvider.Default.GetTracer(TracerName);
            var shim   = new TracerShim(tracer, format);

            // first inject
            shim.Inject(spanContextShim, BuiltinFormats.TextMap, carrier);

            // then extract
            var extractedSpanContext = shim.Extract(BuiltinFormats.TextMap, carrier);

            AssertOpenTracerSpanContextEqual(spanContextShim, extractedSpanContext);
        }
Esempio n. 4
0
 /// <summary>
 /// Extracts the specified tracer.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="tracer">The tracer.</param>
 /// <param name="headers">The headers.</param>
 /// <returns></returns>
 public static ActivityContext Extract(this IReceivedMessageInternal message, ActivitySource tracer,
                                       IStandardHeaders headers)
 {
     TextMapPropagator propagator = new TraceContextPropagator();
     var parentContext            = propagator.Extract(default, message.Headers, ExtractTraceContextFromBasicProperties);