public void Extract_ArgumentValidation() { var tracer = TracerProvider.Default.GetTracer(TracerName); var shim = new TracerShim(tracer, new TextMapPropagator()); Assert.Throws <ArgumentNullException>(() => shim.Extract(null, new Mock <ITextMap>().Object)); Assert.Throws <ArgumentNullException>(() => shim.Extract(new Mock <IFormat <ITextMap> >().Object, null)); }
public void Extract_ArgumentValidation() { var tracerMock = new Mock <Trace.Tracer>(); var shim = new TracerShim(tracerMock.Object, new TraceContextFormat(), new BinaryFormat()); Assert.Throws <ArgumentNullException>(() => shim.Extract(null, new Mock <ITextMap>().Object)); Assert.Throws <ArgumentNullException>(() => shim.Extract(new Mock <IFormat <ITextMap> >().Object, null)); }
public void Extract_UnknownFormatIgnored() { var tracer = TracerProvider.Default.GetTracer(TracerName); var shim = new TracerShim(tracer, new TextMapPropagator()); var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None)); // Only two specific types of ITextMap are supported, and neither is a Mock. var mockCarrier = new Mock <ITextMap>(); var context = shim.Extract(new Mock <IFormat <ITextMap> >().Object, mockCarrier.Object); // Verify that the carrier mock was never called. mockCarrier.Verify(x => x.GetEnumerator(), Times.Never); }
public void Extract_UnknownFormatIgnored() { var tracerMock = new Mock <Trace.Tracer>(); var shim = new TracerShim(tracerMock.Object, new TraceContextFormat(), new BinaryFormat()); var spanContextShim = new SpanContextShim(Defaults.GetOpenTelemetrySpanContext()); // Only two specific types of ITextMap are supported, and neither is a Mock. var mockCarrier = new Mock <ITextMap>(); var context = shim.Extract(new Mock <IFormat <ITextMap> >().Object, mockCarrier.Object); // Verify that the carrier mock was never called. mockCarrier.Verify(x => x.GetEnumerator(), Times.Never); }
public void InjectExtract_TextMap_Ok() { var carrier = new TextMapCarrier(); var spanContextShim = new SpanContextShim(new SpanContext(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None)); var format = new TextMapPropagator(); var tracer = TracerProvider.Default.GetTracer(TracerName); var shim = new TracerShim(tracer, format); // first inject shim.Inject(spanContextShim, BuiltinFormats.TextMap, carrier); // then extract var extractedSpanContext = shim.Extract(BuiltinFormats.TextMap, carrier); AssertOpenTracerSpanContextEqual(spanContextShim, extractedSpanContext); }
public void InjectExtract_Binary_Ok() { var tracerMock = new Mock <Trace.Tracer>(); var carrier = new BinaryCarrier(); var spanContextShim = new SpanContextShim(Defaults.GetOpenTelemetrySpanContext()); var format = new BinaryFormat(); var shim = new TracerShim(tracerMock.Object, new TraceContextFormat(), format); // first inject shim.Inject(spanContextShim, BuiltinFormats.Binary, carrier); // then extract var extractedSpanContext = shim.Extract(BuiltinFormats.Binary, carrier); AssertOpenTracerSpanContextEqual(spanContextShim, extractedSpanContext); }
public void Extract_InvalidTraceParent() { var tracer = TracerProvider.Default.GetTracer(TracerName); var shim = new TracerShim(tracer, new TextMapPropagator()); var mockCarrier = new Mock <ITextMap>(); // The ProxyTracer uses OpenTelemetry.Context.Propagation.TextMapPropagator, so we need to satisfy the traceparent key at the least var carrierMap = new Dictionary <string, string> { // This is an invalid traceparent value { "traceparent", "unused" }, }; mockCarrier.Setup(x => x.GetEnumerator()).Returns(carrierMap.GetEnumerator()); var spanContextShim = shim.Extract(BuiltinFormats.TextMap, mockCarrier.Object) as SpanContextShim; // Verify that the carrier was called mockCarrier.Verify(x => x.GetEnumerator(), Times.Once); Assert.Null(spanContextShim); }