Search in sources :

Example 1 with JaegerSpanContext

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

the class ConfigurationTest method assertInjectExtract.

@SuppressWarnings("unchecked")
private <C> void assertInjectExtract(JaegerTracer tracer, Format<C> format, JaegerSpanContext contextToInject, boolean injectMapIsEmpty) {
    HashMap<String, String> injectMap = new HashMap<>();
    tracer.inject(contextToInject, format, (C) new TextMapAdapter(injectMap));
    assertEquals(injectMapIsEmpty, injectMap.isEmpty());
    if (injectMapIsEmpty) {
        return;
    }
    JaegerSpanContext extractedContext = tracer.extract(format, (C) new TextMapAdapter(injectMap));
    assertEquals(contextToInject.getTraceId(), extractedContext.getTraceId());
    assertEquals(contextToInject.getSpanId(), extractedContext.getSpanId());
}
Also used : HashMap(java.util.HashMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext)

Example 2 with JaegerSpanContext

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

the class ConfigurationTest method testPropagationValidFormat.

@Test
public void testPropagationValidFormat() {
    System.setProperty(Configuration.JAEGER_PROPAGATION, "jaeger,invalid");
    System.setProperty(Configuration.JAEGER_SERVICE_NAME, "Test");
    long traceIdLow = 1234;
    long spanId = 5678;
    TestTextMap textMap = new TestTextMap();
    JaegerSpanContext spanContext = new JaegerSpanContext(0, traceIdLow, spanId, 0, (byte) 0);
    Configuration.fromEnv().getTracer().inject(spanContext, Format.Builtin.TEXT_MAP, textMap);
    // Check that jaeger context still available even though invalid format specified
    assertNotNull(textMap.get("uber-trace-id"));
}
Also used : JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 3 with JaegerSpanContext

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

the class ConfigurationTest method testPropagationDefault.

@Test
public void testPropagationDefault() {
    System.setProperty(Configuration.JAEGER_SERVICE_NAME, "Test");
    long traceIdLow = 1234;
    long spanId = 5678;
    TestTextMap textMap = new TestTextMap();
    JaegerSpanContext spanContext = new JaegerSpanContext(0, traceIdLow, spanId, 0, (byte) 0);
    Configuration.fromEnv().getTracer().inject(spanContext, Format.Builtin.TEXT_MAP, textMap);
    assertNotNull(textMap.get("uber-trace-id"));
    assertNull(textMap.get("X-B3-TraceId"));
    assertNull(textMap.get("X-B3-SpanId"));
}
Also used : JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 4 with JaegerSpanContext

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

the class ConfigurationTest method testAddedCodecs.

@Test
public void testAddedCodecs() {
    Codec<TextMap> codec1 = new Codec<TextMap>() {

        @Override
        public JaegerSpanContext extract(TextMap carrier) {
            return null;
        }

        @Override
        public void inject(JaegerSpanContext spanContext, TextMap carrier) {
        }
    };
    Codec<TextMap> codec2 = new Codec<TextMap>() {

        @Override
        public JaegerSpanContext extract(TextMap carrier) {
            return null;
        }

        @Override
        public void inject(JaegerSpanContext spanContext, TextMap carrier) {
        }
    };
    Codec<Binary> codec3 = new Codec<Binary>() {

        @Override
        public JaegerSpanContext extract(Binary carrier) {
            return null;
        }

        @Override
        public void inject(JaegerSpanContext spanContext, Binary carrier) {
        }
    };
    CodecConfiguration codecConfiguration = new CodecConfiguration().withCodec(Builtin.HTTP_HEADERS, codec1).withCodec(Builtin.HTTP_HEADERS, codec2).withBinaryCodec(Builtin.BINARY, codec3);
    assertEquals(2, codecConfiguration.getCodecs().get(Builtin.HTTP_HEADERS).size());
    assertEquals(codec1, codecConfiguration.getCodecs().get(Builtin.HTTP_HEADERS).get(0));
    assertEquals(codec2, codecConfiguration.getCodecs().get(Builtin.HTTP_HEADERS).get(1));
    assertEquals(codec3, codecConfiguration.getBinaryCodecs().get(Builtin.BINARY).get(0));
    Configuration configuration = new Configuration("foo").withCodec(codecConfiguration);
    long traceIdLow = 2L;
    long spanId = 11L;
    long parentId = 22L;
    JaegerSpanContext spanContext = new JaegerSpanContext(0, traceIdLow, spanId, parentId, (byte) 0);
    assertInjectExtract(configuration.getTracer(), Builtin.TEXT_MAP, spanContext, false);
    // added codecs above overrides the default implementation
    assertInjectExtract(configuration.getTracer(), Builtin.HTTP_HEADERS, spanContext, true);
}
Also used : TraceContextCodec(io.jaegertracing.internal.propagation.TraceContextCodec) B3TextMapCodec(io.jaegertracing.internal.propagation.B3TextMapCodec) Codec(io.jaegertracing.spi.Codec) BinaryCodec(io.jaegertracing.internal.propagation.BinaryCodec) TextMapCodec(io.jaegertracing.internal.propagation.TextMapCodec) SenderConfiguration(io.jaegertracing.Configuration.SenderConfiguration) CodecConfiguration(io.jaegertracing.Configuration.CodecConfiguration) ReporterConfiguration(io.jaegertracing.Configuration.ReporterConfiguration) SamplerConfiguration(io.jaegertracing.Configuration.SamplerConfiguration) CodecConfiguration(io.jaegertracing.Configuration.CodecConfiguration) TextMap(io.opentracing.propagation.TextMap) Binary(io.opentracing.propagation.Binary) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 5 with JaegerSpanContext

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

the class ConfigurationTest method testB3CodecsWith128BitTraceId.

@Test
public void testB3CodecsWith128BitTraceId() {
    System.setProperty(Configuration.JAEGER_PROPAGATION, "b3");
    System.setProperty(Configuration.JAEGER_SERVICE_NAME, "Test");
    Configuration configuration = Configuration.fromEnv().withTraceId128Bit(true);
    long traceIdLow = 2L;
    long traceIdHigh = 3L;
    long spanId = 11L;
    long parentId = 22L;
    JaegerSpanContext spanContext = new JaegerSpanContext(traceIdHigh, traceIdLow, spanId, parentId, (byte) 0);
    assertInjectExtract(configuration.getTracer(), Builtin.TEXT_MAP, spanContext, false);
    assertInjectExtract(configuration.getTracer(), Builtin.HTTP_HEADERS, spanContext, false);
    assertBinaryInjectExtract(configuration.getTracer(), spanContext);
}
Also used : SenderConfiguration(io.jaegertracing.Configuration.SenderConfiguration) CodecConfiguration(io.jaegertracing.Configuration.CodecConfiguration) ReporterConfiguration(io.jaegertracing.Configuration.ReporterConfiguration) SamplerConfiguration(io.jaegertracing.Configuration.SamplerConfiguration) 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