Search in sources :

Example 16 with TextMapAdapter

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

Example 17 with TextMapAdapter

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

Example 18 with TextMapAdapter

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

Example 19 with TextMapAdapter

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();
}
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 20 with TextMapAdapter

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());
}
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