Search in sources :

Example 1 with Codec

use of io.jaegertracing.spi.Codec 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)

Aggregations

CodecConfiguration (io.jaegertracing.Configuration.CodecConfiguration)1 ReporterConfiguration (io.jaegertracing.Configuration.ReporterConfiguration)1 SamplerConfiguration (io.jaegertracing.Configuration.SamplerConfiguration)1 SenderConfiguration (io.jaegertracing.Configuration.SenderConfiguration)1 JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)1 B3TextMapCodec (io.jaegertracing.internal.propagation.B3TextMapCodec)1 BinaryCodec (io.jaegertracing.internal.propagation.BinaryCodec)1 TextMapCodec (io.jaegertracing.internal.propagation.TextMapCodec)1 TraceContextCodec (io.jaegertracing.internal.propagation.TraceContextCodec)1 Codec (io.jaegertracing.spi.Codec)1 Binary (io.opentracing.propagation.Binary)1 TextMap (io.opentracing.propagation.TextMap)1 Test (org.junit.Test)1