Пример #1
0
        public void CompositePropagator_UsingSameTag()
        {
            const string header01 = "custom-tracestate-01";
            const string header02 = "custom-tracestate-02";

            var compositePropagator = new CompositePropagator(new List <ITextFormat>
            {
                new TestPropagator("custom-traceparent", header01, true),
                new TestPropagator("custom-traceparent", header02),
            });

            var activityContext = new ActivityContext(this.traceId, this.spanId, ActivityTraceFlags.Recorded, traceState: null);
            var carrier         = new Dictionary <string, string>();

            compositePropagator.Inject(activityContext, carrier, Setter);
            Assert.Contains(carrier, kv => kv.Key == "custom-traceparent");

            // checking if the latest propagator is the one with the data. So, it will replace the previous one.
            Assert.Equal($"00-{this.traceId}-{this.spanId}-{header02.Split('-').Last()}", carrier["custom-traceparent"]);

            bool isInjected = compositePropagator.IsInjected(carrier, Getter);

            Assert.True(isInjected);

            // resetting counter
            count = 0;
            ActivityContext newContext = compositePropagator.Extract(default, carrier, Getter);
Пример #2
0
        public void CompositePropagator_TestPropagator()
        {
            var compositePropagator = new CompositePropagator(new List <IPropagator>
            {
                new TestPropagator("custom-traceparent-1", "custom-tracestate-1"),
                new TestPropagator("custom-traceparent-2", "custom-tracestate-2"),
            });

            var activityContext = new ActivityContext(this.traceId, this.spanId, ActivityTraceFlags.Recorded, traceState: null);
            PropagationContext propagationContext = new PropagationContext(activityContext, default);
            var carrier  = new Dictionary <string, string>();
            var activity = new Activity("test");

            compositePropagator.Inject(propagationContext, carrier, Setter);
            Assert.Contains(carrier, kv => kv.Key == "custom-traceparent-1");
            Assert.Contains(carrier, kv => kv.Key == "custom-traceparent-2");
        }
Пример #3
0
        public void CompositePropagator_TestPropagator()
        {
            var compositePropagator = new CompositePropagator(new List <ITextFormat>
            {
                new TestPropagator("custom-traceparent-1", "custom-tracestate-1"),
                new TestPropagator("custom-traceparent-2", "custom-tracestate-2"),
            });

            var activityContext = new ActivityContext(this.traceId, this.spanId, ActivityTraceFlags.Recorded, traceState: null);
            var carrier         = new Dictionary <string, string>();

            compositePropagator.Inject(activityContext, carrier, Setter);
            Assert.Contains(carrier, kv => kv.Key == "custom-traceparent-1");
            Assert.Contains(carrier, kv => kv.Key == "custom-traceparent-2");

            bool isInjected = compositePropagator.IsInjected(carrier, Getter);

            Assert.True(isInjected);
        }