예제 #1
0
        public void TextMapCode_Injects_Extracts_Successful_With_Encoding()
        {
            var dict = new Dictionary <string, string>();
            var map  = new Mock <ITextMap>();

            map.Setup(c => c.Set(It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string>((c1, c2) => dict.Add(c1, c2));
            map.Setup(c => c.GetEntries()).Returns(dict);

            var codec = new TextMapCodec(true);

            //inject is successful
            codec.Inject(SpanContext.Parse("1:2:3:4"), map.Object);
            Assert.Single(dict);
            Assert.True(dict.ContainsKey(TextMapCodec.SPAN_CONTEXT_KEY));
            Assert.Equal("1%3A2%3A3%3A4", dict[TextMapCodec.SPAN_CONTEXT_KEY]);

            //extract is successful
            var context = codec.Extract(map.Object);

            Assert.NotNull(context);
            Assert.Equal(1, context.TraceId);
            Assert.Equal(2, context.SpanId);
            Assert.Equal(3, context.ParentId);
            Assert.Equal(4, context.Flags);
            Assert.Empty(context.Baggage);
        }
예제 #2
0
        public void TextCodec_Injects_Context_AsString_Using_SuppliedKey()
        {
            var dict = new Dictionary <string, string>();
            var map  = new Mock <ITextMap>();

            map.Setup(c => c.Set(It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string>((c1, c2) => dict.Add(c1, c2));
            var codec = new TextMapCodec(false, contextKey: "context", baggagePrefix: "baggage");

            codec.Inject(SpanContext.Parse("1:2:3:4"), map.Object);
            Assert.Single(dict);
            Assert.True(dict.ContainsKey("context"));
            Assert.Equal("1:2:3:4", dict["context"]);
        }
예제 #3
0
        public void Text_Codec_Injects_Context_AsString_To_Carrier()
        {
            var dict = new Dictionary <string, string>();
            var map  = new Mock <ITextMap>();

            map.Setup(c => c.Set(It.IsAny <string>(), It.IsAny <string>()))
            .Callback <string, string>((c1, c2) => dict.Add(c1, c2));
            var codec = new TextMapCodec(false);

            codec.Inject(SpanContext.Parse("1:2:3:4"), map.Object);
            Assert.Single(dict);
            Assert.True(dict.ContainsKey(TextMapCodec.SPAN_CONTEXT_KEY));
            Assert.Equal("1:2:3:4", dict[TextMapCodec.SPAN_CONTEXT_KEY]);
        }