use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TraceContextCodecTest method testDebugIdWithoutTraceHeader.
@Test
public void testDebugIdWithoutTraceHeader() {
Map<String, String> extractCarrier = new HashMap<>();
TextMapAdapter textMap = new TextMapAdapter(extractCarrier);
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();
JaegerSpan child = tracer.buildSpan("span").asChildOf(spanContext).start();
assertTrue(child.context().isDebug());
child.finish();
tracer.close();
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TextMapCodecTest method testExtractSupportEncodedSpanContext.
@Test
public void testExtractSupportEncodedSpanContext() {
Map<String, String> headers = new HashMap<>();
headers.put("uber-trace-id", "2a%3A1%3A0%3A1");
TextMapCodec codec = new TextMapCodec(true);
JaegerSpanContext context = codec.extract(new TextMapAdapter(headers));
assertEquals(42, context.getTraceIdLow());
assertEquals(0L, context.getTraceIdHigh());
assertEquals(1L, context.getSpanId());
assertTrue(context.isSampled());
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class TextMapCodecTest method testAdhocBaggageWithTraceId.
/**
* Tests that the codec will include baggage from header "jaeger-baggage".
*/
@Test
public void testAdhocBaggageWithTraceId() {
TextMapCodec codec = new TextMapCodec(false);
Map<String, String> headers = new HashMap<>();
long traceIdLow = 42;
long spanId = 1;
long parentId = 0;
codec.inject(new JaegerSpanContext(0L, traceIdLow, spanId, parentId, (byte) 1), new TextMapAdapter(headers));
headers.put("jaeger-baggage", "k1=v1, k2 = v2");
JaegerSpanContext context = codec.extract(new TextMapAdapter(headers));
assertEquals("must have trace ID", 42, context.getTraceIdLow());
assertEquals("must have trace ID", 0L, context.getTraceIdHigh());
assertEquals("must have bagggae", "v1", context.getBaggageItem("k1"));
assertEquals("must have bagggae", "v2", context.getBaggageItem("k2"));
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class AdhocHeadersTest method testJoinTraceWithAdhocBaggage.
@Test
public void testJoinTraceWithAdhocBaggage() {
Span span = tracer.buildSpan("test").start();
Map<String, String> headers = new HashMap<String, String>();
tracer.inject(span.context(), Format.Builtin.HTTP_HEADERS, new TextMapAdapter(headers));
assertEquals(1, headers.size());
traceWithAdhocBaggage(headers);
}
use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.
the class AdhocHeadersTest method testDebugCorrelationId.
@Test
public void testDebugCorrelationId() {
Map<String, String> headers = Collections.singletonMap(Constants.DEBUG_ID_HEADER_KEY, "Coraline");
TextMap carrier = new TextMapAdapter(headers);
JaegerSpanContext inboundSpanContext = tracer.extract(Format.Builtin.TEXT_MAP, carrier);
assertNotNull(inboundSpanContext);
assertFalse(inboundSpanContext.hasTrace());
assertEquals("Coraline", inboundSpanContext.getDebugId());
JaegerSpan span = tracer.buildSpan("span").asChildOf(inboundSpanContext).start();
JaegerSpanContext serverSpanContext = span.context();
assertTrue(serverSpanContext.isSampled());
assertTrue(serverSpanContext.isDebug());
assertEquals("Coraline", span.getTags().get(Constants.DEBUG_ID_HEADER_KEY));
}
Aggregations