use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class V2SpanConverterTest method testRpcChildSpanHasTheSameId.
@Test
@SuppressWarnings("Duplicates")
public void testRpcChildSpanHasTheSameId() {
String expectedOperation = "parent";
JaegerSpan client = tracer.buildSpan(expectedOperation).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start();
Map<String, String> map = new HashMap<>();
TextMap carrier = new TextMapAdapter(map);
tracer.inject(client.context(), Format.Builtin.TEXT_MAP, carrier);
JaegerSpanContext ctx = tracer.extract(Format.Builtin.TEXT_MAP, carrier);
JaegerSpanContext clientCtx = client.context();
assertEquals(clientCtx.getSpanId(), ctx.getSpanId());
JaegerSpan server = tracer.buildSpan("child").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).asChildOf(ctx).start();
JaegerSpanContext serverCtx = server.context();
assertEquals("client and server must have the same span ID", clientCtx.getSpanId(), serverCtx.getSpanId());
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TraceContextCodecTest method testInvalidParentId.
@Test
public void testInvalidParentId() {
TextMapAdapter textMap = new TextMapAdapter(new HashMap<>());
textMap.put(TRACE_PARENT, "00-00000000000000000000000000000001-0000000000000000-00");
JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
assertNull(spanContext);
verifyWarningPresent();
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TraceContextCodecTest method testInject.
@Test
public void testInject() {
Map<String, String> carrier = new HashMap<>();
TextMapAdapter textMap = new TextMapAdapter(carrier);
long traceIdLow = 1;
long spanId = 2;
long parentId = 3;
long traceIdHigh = HexCodec.hexToUnsignedLong("c281c27976c85681", 0, 16);
JaegerSpanContext spanContext = new JaegerSpanContext(traceIdHigh, traceIdLow, spanId, parentId, (byte) 0);
traceContextCodec.inject(spanContext, textMap);
String expectedTraceContextHeader = "00-c281c27976c856810000000000000001-0000000000000002-00";
assertEquals(1, carrier.size());
assertNotNull(carrier.get(TRACE_PARENT));
assertEquals(expectedTraceContextHeader, carrier.get(TRACE_PARENT));
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TraceContextCodecTest method testDebugIdWithTraceHeader.
@Test
public void testDebugIdWithTraceHeader() {
Map<String, String> extractCarrier = new HashMap<>();
TextMapAdapter textMap = new TextMapAdapter(extractCarrier);
textMap.put(TRACE_PARENT, EXAMPLE_TRACE_PARENT);
textMap.put(Constants.DEBUG_ID_HEADER_KEY, EXAMPLE_DEBUG_ID);
JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
JaegerTracer tracer = new JaegerTracer.Builder("service").withReporter(new InMemoryReporter()).build();
assertEquals("0000000000000001", spanContext.getTraceId());
JaegerSpan child = tracer.buildSpan("span").asChildOf(spanContext).start();
assertFalse(child.context().isDebug());
child.finish();
tracer.close();
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TraceContextCodecTest method testExtractWithCapitalizedTraceHeaders.
@Test
public void testExtractWithCapitalizedTraceHeaders() {
Map<String, String> extractCarrier = new HashMap<>();
TextMapAdapter textMap = new TextMapAdapter(extractCarrier);
textMap.put("Traceparent", EXAMPLE_TRACE_PARENT);
textMap.put("Tracestate", "whatever");
JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
assertEquals("0000000000000001:0000000000000002:0:0", spanContext.toString());
assertEquals("whatever", spanContext.getTraceState());
}
Aggregations