Пример #1
0
        public void TextMapPropagationRegistry_Inject_HttpHeaders_SetsTheRightHeadersWithTheRightData()
        {
            var carrier = new DictionaryTextMap();

            _propagationRegistry.Inject(_spanContext, BuiltinFormats.HttpHeaders, carrier);

            var carrierDict = carrier.ToDictionary(c => c.Key, c => c.Value);

            Assert.Equal(_spanContext.GetType().FullName, carrierDict[Constants.TraceContextHeaderName]); // cannot mock ToString
            Assert.Equal(HttpUtility.UrlEncode(_baggage["key1"]), carrierDict[$"{Constants.TraceBaggageHeaderPrefix}-key1"]);
            Assert.Equal(HttpUtility.UrlEncode(_baggage["key2"]), carrierDict[$"{Constants.TraceBaggageHeaderPrefix}-key2"]);
        }
Пример #2
0
        public void TextMapPropagator_Inject_SetsTheRightHeadersWithTheRightData()
        {
            var headersConfig = new HeadersConfig("TraceContextHeaderName", "TraceBaggageHeaderPrefix");
            var propagator    = new TextMapPropagator(headersConfig, (val) => val, (val) => val);
            var baggage       = new Dictionary <string, string> {
                { "key1", "value1" }, { "key2", "value2" }
            };
            var spanContext = Substitute.For <ILetsTraceSpanContext>();
            var carrier     = new DictionaryTextMap();

            spanContext.GetBaggageItems().Returns(baggage);

            propagator.Inject(spanContext, carrier);

            var carrierDict = carrier.ToDictionary(c => c.Key, c => c.Value);

            Assert.Equal(spanContext.GetType().FullName, carrierDict[headersConfig.TraceContextHeaderName]); // cannot mock ToString
            Assert.Equal(baggage["key1"], carrierDict[$"{headersConfig.TraceBaggageHeaderPrefix}-key1"]);
            Assert.Equal(baggage["key2"], carrierDict[$"{headersConfig.TraceBaggageHeaderPrefix}-key2"]);
        }