public void PropagatorStackShouldInjectExtractAllPropagators()
        {
            var ps             = new PropagatorStack(BuiltinFormats.TextMap);
            var httpPropagator = new HttpHeadersPropagator();
            var b3Propagator   = new B3Propagator();
            var textPropagator = new TextMapPropagator();

            ps.AddPropagator(httpPropagator);
            ps.AddPropagator(b3Propagator);
            ps.AddPropagator(textPropagator);

            var carrier = new Dictionary <string, string>();
            var context = new SpanContext(0, 0);

            ps.Inject(context, BuiltinFormats.TextMap, new TextMapInjectAdapter(carrier));

            var propagators = new List <IPropagator> {
                httpPropagator, b3Propagator, textPropagator
            };

            foreach (var t in propagators)
            {
                var extractedContext =
                    t.Extract(BuiltinFormats.TextMap, new TextMapExtractAdapter(carrier));
                Assert.NotNull(extractedContext);
                Assert.Equal(context.TraceId, extractedContext.TraceId);
                Assert.Equal(context.SpanId, extractedContext.SpanId);
            }
        }
Exemplo n.º 2
0
        public void PropagatorSkipsParentIdIfParentIdIsNull()
        {
            var propatagor = new B3Propagator();
            var map        = new Dictionary <string, string>();

            propatagor.Inject(new SpanContext(1, 323423, null, false, true, false), new DictionaryPropagatorMap(map));
            Assert.False(map.TryGetValue("X-B3-ParentSpanId", out var _));
        }
Exemplo n.º 3
0
        public void DebugContextPropagateFlagsWithoutSampled()
        {
            var propatagor = new B3Propagator();
            var map        = new Dictionary <string, string>();

            propatagor.Inject(new SpanContext(1, 323423, 4343, true, true, false), new DictionaryPropagatorMap(map));
            Assert.False(map.TryGetValue("X-B3-Sampled", out var _));
            Assert.Equal("1", map["X-B3-Flags"]);
        }
        public void PropagatorStackShouldAddPropagator()
        {
            var b3Propagator = new B3Propagator();
            var ps           = new PropagatorStack(BuiltinFormats.HttpHeaders);

            Assert.Equal(ps.AddPropagator(Propagators.HttpHeadersPropagator), ps);
            Assert.Equal(ps.AddPropagator(b3Propagator), ps);
            Assert.Equal(2, ps.Propagators.Count);
            Assert.Equal(ps.Propagators[0], Propagators.HttpHeadersPropagator);
            Assert.Equal(ps.Propagators[1], b3Propagator);
        }
Exemplo n.º 5
0
        public void PropagatorInsertsAllSpanContextFields()
        {
            var propatagor = new B3Propagator();
            var map        = new Dictionary <string, string>();

            propatagor.Inject(new SpanContext(1, 323423, 4343, true, false, false), new DictionaryPropagatorMap(map));
            Assert.Equal(4, map.Count);
            Assert.Equal(1.ToString("x16"), map["X-B3-TraceId"]);
            Assert.Equal(323423.ToString("x16"), map["X-B3-SpanId"]);
            Assert.Equal(4343.ToString("x16"), map["X-B3-ParentSpanId"]);
            Assert.Equal("1", map["X-B3-Sampled"]);
        }
Exemplo n.º 6
0
        public void SampledContextEncodingIsHandledCorrectly()
        {
            var propatagor = new B3Propagator();
            var map        = new Dictionary <string, string>();

            propatagor.Inject(new SpanContext(1, 323423, 4343, true, false, false), new DictionaryPropagatorMap(map));
            Assert.Equal("1", map["X-B3-Sampled"]);

            map.Clear();

            propatagor.Inject(new SpanContext(1, 344332, 98, false, false, false), new DictionaryPropagatorMap(map));
            Assert.Equal("0", map["X-B3-Sampled"]);
        }
Exemplo n.º 7
0
        public void PropagatorExtractsContextWithNoParentId()
        {
            var propatagor = new B3Propagator();
            var map        = new Dictionary <string, string>();

            propatagor.Inject(new SpanContext(189879, 46764, null, true, false, false), new DictionaryPropagatorMap(map));

            var context = propatagor.Extract(new DictionaryPropagatorMap(map)) as SpanContext;

            Assert.NotNull(context);

            Assert.Equal <ulong>(189879, context.TraceId.TraceIdLow);
            Assert.Equal <ulong>(46764, context.SpanId);
            Assert.False(context.ParentId.HasValue);
            Assert.True(context.Sampled);
            Assert.False(context.Debug);
            Assert.False(context.Shared);
        }
Exemplo n.º 8
0
        public void PropagatorExtractsContextFromFullTextMap()
        {
            var propatagor = new B3Propagator();
            var map        = new Dictionary <string, string>();

            propatagor.Inject(new SpanContext(1, 323423, 4343, true, false, false), new DictionaryPropagatorMap(map));

            var context = propatagor.Extract(new DictionaryPropagatorMap(map)) as SpanContext;

            Assert.NotNull(context);

            Assert.Equal <ulong>(1, context.TraceId.TraceIdLow);
            Assert.Equal <ulong>(323423, context.SpanId);
            Assert.Equal <ulong>(4343, context.ParentId.Value);
            Assert.True(context.Sampled);
            Assert.False(context.Debug);
            Assert.False(context.Shared);
        }
        public void B3PropagatorShouldHandle128bitTraceIds()
        {
            var propagator       = new B3Propagator();
            var traceId          = "aef5705a090040838f1359ebafa5c0c6";
            var truncatedTraceId = "8f1359ebafa5c0c6";
            var spanId           = "1";

            var headers = new Dictionary <string, string>
            {
                { B3Propagator.TraceIdName, traceId },
                { B3Propagator.SpanIdName, spanId }
            };
            var extractedContext = propagator.Extract(BuiltinFormats.TextMap, new TextMapExtractAdapter(headers));

            Assert.Equal(traceId, extractedContext.OriginalTraceId);
            Assert.Equal(truncatedTraceId, extractedContext.TraceId);
            Assert.Equal(spanId, extractedContext.SpanId);

            headers.Clear();
            propagator.Inject(extractedContext, BuiltinFormats.TextMap, new TextMapInjectAdapter(headers));
            Assert.Equal(traceId, headers[B3Propagator.TraceIdName]);
            Assert.Equal(spanId, headers[B3Propagator.SpanIdName]);
        }