Exemple #1
0
        public void InjectTraceContext()
        {
            var opts = GetOptions();
            OpenCensusTracing tracing = new OpenCensusTracing(opts, null);
            var obs     = new HttpClientCoreObserver(opts, tracing);
            var request = GetHttpRequestMessage();

            tracing.Tracer.SpanBuilder("MySpan").StartScopedSpan(out ISpan span);

            obs.InjectTraceContext(request, null);

            Assert.True(request.Headers.Contains(B3Constants.XB3TraceId));
            Assert.True(request.Headers.Contains(B3Constants.XB3SpanId));
            Assert.False(request.Headers.Contains(B3Constants.XB3ParentSpanId));

            var spanId = request.Headers.GetValues(B3Constants.XB3SpanId).Single();

            Assert.Equal(span.Context.SpanId.ToLowerBase16(), spanId);

            var traceId  = request.Headers.GetValues(B3Constants.XB3TraceId).Single();
            var expected = GetTraceId(opts, span.Context);

            Assert.Equal(expected, traceId);

            if (span.Context.TraceOptions.IsSampled)
            {
                Assert.True(request.Headers.Contains(B3Constants.XB3Sampled));
            }
        }
        public void InjectTraceContext()
        {
            var opts    = GetOptions();
            var tracing = new OpenTelemetryTracing(opts, null);
            var obs     = new HttpClientCoreObserver(opts, tracing);
            var request = GetHttpRequestMessage();

            // tracing.Tracer.SpanBuilder("MySpan").StartScopedSpan(out ISpan span);
            tracing.Tracer.StartActiveSpan("MySpan", out var span);

            obs.InjectTraceContext(request, null);

            Assert.True(request.Headers.Contains(B3Constants.XB3TraceId));
            Assert.True(request.Headers.Contains(B3Constants.XB3SpanId));
            Assert.False(request.Headers.Contains(B3Constants.XB3ParentSpanId));

            var spanId = request.Headers.GetValues(B3Constants.XB3SpanId).Single();

            Assert.Equal(span.ToSpanData().Context.SpanId.ToHexString(), spanId);

            var traceId  = request.Headers.GetValues(B3Constants.XB3TraceId).Single();
            var expected = GetTraceId(opts, span.Context);

            Assert.Equal(expected, traceId);

            if (span.IsRecording)
            {
                Assert.True(request.Headers.Contains(B3Constants.XB3Sampled));
            }
        }
Exemple #3
0
        public void InjectTraceContext()
        {
            var opts = GetOptions();
            OpenCensusTracing tracing = new OpenCensusTracing(opts, null);
            var obs     = new HttpClientCoreObserver(opts, tracing);
            var request = GetHttpRequestMessage();

            var span = tracing.Tracer.SpanBuilder("MySpan").StartSpan() as Span;

            AsyncLocalContext.CurrentSpan = span;

            obs.InjectTraceContext(request, null);

            Assert.True(request.Headers.Contains(B3Format.X_B3_TRACE_ID));
            Assert.True(request.Headers.Contains(B3Format.X_B3_SPAN_ID));
            Assert.False(request.Headers.Contains(B3Format.X_B3_PARENT_SPAN_ID));

            var spanId = request.Headers.GetValues(B3Format.X_B3_SPAN_ID).Single();

            Assert.Equal(span.Context.SpanId.ToLowerBase16(), spanId);

            var traceId  = request.Headers.GetValues(B3Format.X_B3_TRACE_ID).Single();
            var expected = GetTraceId(opts, span.Context);

            Assert.Equal(expected, traceId);

            if (span.Context.TraceOptions.IsSampled)
            {
                Assert.True(request.Headers.Contains(B3Format.X_B3_SAMPLED));
            }
        }