Search in sources :

Example 6 with TextMapAdapter

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();
}
Also used : InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) HashMap(java.util.HashMap) JaegerSpan(io.jaegertracing.internal.JaegerSpan) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Example 7 with TextMapAdapter

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());
}
Also used : HashMap(java.util.HashMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 8 with TextMapAdapter

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"));
}
Also used : HashMap(java.util.HashMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 9 with TextMapAdapter

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);
}
Also used : HashMap(java.util.HashMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) Span(io.opentracing.Span) Test(org.junit.Test)

Example 10 with TextMapAdapter

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));
}
Also used : TextMap(io.opentracing.propagation.TextMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) Test(org.junit.Test)

Aggregations

TextMapAdapter (io.opentracing.propagation.TextMapAdapter)26 Test (org.junit.Test)23 JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)19 HashMap (java.util.HashMap)16 JaegerSpan (io.jaegertracing.internal.JaegerSpan)4 TextMap (io.opentracing.propagation.TextMap)3 LinkedHashMap (java.util.LinkedHashMap)3 JaegerTracer (io.jaegertracing.internal.JaegerTracer)2 InMemoryReporter (io.jaegertracing.internal.reporters.InMemoryReporter)2 Span (io.opentracing.Span)2 TraceContext (brave.propagation.TraceContext)1 Scope (io.opentracing.Scope)1 SpanContext (io.opentracing.SpanContext)1 Map (java.util.Map)1