Search in sources :

Example 21 with TextMapAdapter

use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.

the class TraceContextCodecTest method support128BitTraceIdExtraction.

@Test
public void support128BitTraceIdExtraction() {
    String hex128Bits = "463ac35c9f6413ad48485a3953bb6124";
    String parentSpan = "d1595c6ec91668af";
    String tracecontext = String.format("00-%s-%s-01", hex128Bits, parentSpan);
    TextMapAdapter textMap = new TextMapAdapter(new HashMap<>());
    textMap.put(TRACE_PARENT, tracecontext);
    JaegerSpanContext context = traceContextCodec.extract(textMap);
    assertNotNull(HexCodec.lowerHexToUnsignedLong(parentSpan));
    assertEquals(HexCodec.lowerHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdLow());
    assertEquals(HexCodec.higherHexToUnsignedLong(hex128Bits).longValue(), context.getTraceIdHigh());
    assertEquals(HexCodec.lowerHexToUnsignedLong(parentSpan).longValue(), context.getSpanId());
    assertTrue(context.isSampled());
}
Also used : TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 22 with TextMapAdapter

use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.

the class TraceContextCodecTest method testTraceStatePropagation.

@Test
public void testTraceStatePropagation() {
    Map<String, String> extractCarrier = new HashMap<>();
    TextMapAdapter textMap = new TextMapAdapter(extractCarrier);
    textMap.put(TRACE_PARENT, EXAMPLE_TRACE_PARENT);
    textMap.put(TRACE_STATE, "whatever");
    JaegerSpanContext spanContext = traceContextCodec.extract(textMap);
    Map<String, String> injectCarrier = new HashMap<>();
    traceContextCodec.inject(spanContext, new TextMapAdapter(injectCarrier));
    assertEquals(extractCarrier, injectCarrier);
}
Also used : HashMap(java.util.HashMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 23 with TextMapAdapter

use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.

the class TextMapCodecTest method testInjectDoNotEncodeSpanContext.

@Test
public void testInjectDoNotEncodeSpanContext() {
    TextMapCodec codec = new TextMapCodec(true);
    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));
    String traceId = headers.get("uber-trace-id");
    assertEquals("000000000000002a:0000000000000001:0:1", traceId);
}
Also used : HashMap(java.util.HashMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 24 with TextMapAdapter

use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.

the class TextMapCodecTest method testExtractSupportNonEncodedSpanContext.

@Test
public void testExtractSupportNonEncodedSpanContext() {
    Map<String, String> headers = new HashMap<>();
    headers.put("uber-trace-id", "2a:1:0:1");
    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 25 with TextMapAdapter

use of io.opentracing.propagation.TextMapAdapter in project jaeger-client-java by jaegertracing.

the class TextMapCodecTest method testAdhocBaggageWithoutTraceId.

/**
 * Tests that the codec will return non-null SpanContext even if the only header
 * present is "jaeger-baggage".
 */
@Test
public void testAdhocBaggageWithoutTraceId() {
    Map<String, String> headers = new HashMap<>();
    headers.put("jaeger-baggage", "k1=v1, k2 = v2, k3=v3=d3");
    TextMapCodec codec = new TextMapCodec(false);
    JaegerSpanContext context = codec.extract(new TextMapAdapter(headers));
    assertEquals("v1", context.getBaggageItem("k1"));
    assertEquals("v2", context.getBaggageItem("k2"));
    assertNull(context.getBaggageItem("k3"));
}
Also used : HashMap(java.util.HashMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) 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