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); } }
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); }
public void PropagatorStackInTracerShouldInjectAndExtract() { var ps = new PropagatorStack(BuiltinFormats.HttpHeaders); ps.AddPropagator(new B3Propagator()); ps.AddPropagator(new HttpHeadersPropagator()); ps.AddPropagator(new TextMapPropagator()); var sr = new SimpleMockRecorder(); var satOpts = new SatelliteOptions("localhost", 80, true); var tracerOpts = new Options("TEST", satOpts); tracerOpts.Run = false; var tracer = new Tracer(tracerOpts, sr, ps); var span = tracer.BuildSpan("propTest").Start(); var traceId = span.TypedContext().TraceId; var spanId = span.TypedContext().SpanId; var hexTraceId = Convert.ToUInt64(traceId).ToString("X"); var hexSpanId = Convert.ToUInt64(spanId).ToString("X"); var data = new Dictionary <string, string>(); tracer.Inject(span.Context, BuiltinFormats.HttpHeaders, new TextMapInjectAdapter(data)); Assert.Equal(traceId, data["ot-tracer-traceid"]); Assert.Equal(hexTraceId, data["X-B3-TraceId"]); Assert.Equal(spanId, data["ot-tracer-spanid"]); Assert.Equal(hexSpanId, data["X-B3-SpanId"]); span.Finish(); var ctx = tracer.Extract(BuiltinFormats.HttpHeaders, new TextMapExtractAdapter(data)); Assert.Equal(ctx.SpanId, spanId); Assert.Equal(ctx.TraceId, traceId); }
public void PropagatorStackShouldThrowOnNullPropagator() { var ps = new PropagatorStack(BuiltinFormats.TextMap); Assert.Throws <ArgumentNullException>(() => ps.AddPropagator(null)); }