Search in sources :

Example 21 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.

the class TraceContextCodecTest method testEmptyTraceStateNotPropagated.

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

Example 22 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext 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 23 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.

the class TraceBehavior method observeSpan.

private ObservedSpan observeSpan() {
    JaegerSpan span = (JaegerSpan) tracer.activeSpan();
    if (tracer.activeSpan() == null) {
        log.error("No span found");
        return new ObservedSpan("no span found", false, "no span found");
    }
    JaegerSpanContext context = span.context();
    String traceId = context.getTraceId();
    boolean sampled = context.isSampled();
    String baggage = span.getBaggageItem(Constants.BAGGAGE_KEY);
    return new ObservedSpan(traceId, sampled, baggage);
}
Also used : ObservedSpan(io.jaegertracing.crossdock.api.ObservedSpan) JaegerSpan(io.jaegertracing.internal.JaegerSpan) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext)

Example 24 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project jaeger-client-java by jaegertracing.

the class B3TextMapCodecTest method testChangeBaggagePrefix.

@Test
public void testChangeBaggagePrefix() {
    B3TextMapCodec b3Codec = new B3TextMapCodec.Builder().withBaggagePrefix("foo").build();
    DelegatingTextMap entries = new DelegatingTextMap();
    long traceIdLow = 1;
    long spanId = 2;
    long parentId = 3;
    JaegerSpanContext spanContext = new JaegerSpanContext(0L, traceIdLow, spanId, parentId, (byte) 0).withBaggageItem("foo", "bar");
    b3Codec.inject(spanContext, entries);
    assertEquals(5, entries.delegate.size());
    assertEquals("bar", entries.delegate.get("foofoo"));
}
Also used : JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 25 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext 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)

Aggregations

JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)68 Test (org.junit.Test)59 HashMap (java.util.HashMap)20 TextMapAdapter (io.opentracing.propagation.TextMapAdapter)19 JaegerSpan (io.jaegertracing.internal.JaegerSpan)10 JaegerTracer (io.jaegertracing.internal.JaegerTracer)8 Response (javax.ws.rs.core.Response)7 TextMap (io.opentracing.propagation.TextMap)6 CodecConfiguration (io.jaegertracing.Configuration.CodecConfiguration)4 ReporterConfiguration (io.jaegertracing.Configuration.ReporterConfiguration)4 SamplerConfiguration (io.jaegertracing.Configuration.SamplerConfiguration)4 SenderConfiguration (io.jaegertracing.Configuration.SenderConfiguration)4 List (java.util.List)3 ObservedSpan (io.jaegertracing.crossdock.api.ObservedSpan)2 TestBinaryCarrier (io.jaegertracing.internal.propagation.TestBinaryCarrier)2 InMemoryReporter (io.jaegertracing.internal.reporters.InMemoryReporter)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Endpoint (com.twitter.zipkin.thriftjava.Endpoint)1