Search in sources :

Example 1 with TextMap

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

the class B3TextMapCodecTest method testExtract_childSpan.

@Test
public void testExtract_childSpan() throws Exception {
    SpanId spanId = SpanId.builder().spanId(2L).traceId(1L).parentId(1L).build();
    TextMap textMap = makeRequestWithSpanId(spanId);
    SpanContext context = b3Codec.extract(textMap);
    assertEquals(1, context.getTraceId());
    assertEquals(1, context.getParentId());
    assertEquals(2, context.getSpanId());
    // sampled
    assertEquals(1, context.getFlags());
}
Also used : SpanContext(com.uber.jaeger.SpanContext) TextMap(io.opentracing.propagation.TextMap) SpanId(com.github.kristofa.brave.SpanId) Test(org.junit.Test)

Example 2 with TextMap

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

the class B3TextMapCodecTest method testExtract_rootSpan.

@Test
public void testExtract_rootSpan() throws Exception {
    SpanId spanId = SpanId.builder().spanId(1L).traceId(1L).parentId(null).build();
    TextMap textMap = makeRequestWithSpanId(spanId);
    SpanContext context = b3Codec.extract(textMap);
    assertEquals(1, context.getTraceId());
    // parentID==0 means root span
    assertEquals(0, context.getParentId());
    assertEquals(1, context.getSpanId());
    // sampled
    assertEquals(1, context.getFlags());
}
Also used : SpanContext(com.uber.jaeger.SpanContext) TextMap(io.opentracing.propagation.TextMap) SpanId(com.github.kristofa.brave.SpanId) Test(org.junit.Test)

Example 3 with TextMap

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

the class TextMapCodec method extract.

@Override
public SpanContext extract(TextMap carrier) {
    SpanContext context = null;
    Map<String, String> baggage = null;
    String debugId = null;
    for (Map.Entry<String, String> entry : carrier) {
        // TODO there should be no lower-case here
        String key = entry.getKey().toLowerCase(Locale.ROOT);
        if (key.equals(contextKey)) {
            context = SpanContext.contextFromString(decodedValue(entry.getValue()));
        } else if (key.equals(Constants.DEBUG_ID_HEADER_KEY)) {
            debugId = decodedValue(entry.getValue());
        } else if (key.startsWith(baggagePrefix)) {
            if (baggage == null) {
                baggage = new HashMap<String, String>();
            }
            baggage.put(keys.unprefixedKey(key, baggagePrefix), decodedValue(entry.getValue()));
        }
    }
    if (context == null) {
        if (debugId != null) {
            return SpanContext.withDebugId(debugId);
        }
        return null;
    }
    if (baggage == null) {
        return context;
    }
    return context.withBaggage(baggage);
}
Also used : SpanContext(com.uber.jaeger.SpanContext) TextMap(io.opentracing.propagation.TextMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with TextMap

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

the class TracerTest method testRegisterInjector.

@Test
public void testRegisterInjector() {
    @SuppressWarnings("unchecked") Injector<TextMap> injector = mock(Injector.class);
    Tracer tracer = new Tracer.Builder("TracerTestService", new InMemoryReporter(), new ConstSampler(true)).withMetrics(new Metrics(new InMemoryMetricsFactory())).registerInjector(Format.Builtin.TEXT_MAP, injector).build();
    Span span = (Span) tracer.buildSpan("leela").start();
    TextMap carrier = mock(TextMap.class);
    tracer.inject(span.context(), Format.Builtin.TEXT_MAP, carrier);
    verify(injector).inject(any(SpanContext.class), any(TextMap.class));
}
Also used : InMemoryReporter(com.uber.jaeger.reporters.InMemoryReporter) Metrics(com.uber.jaeger.metrics.Metrics) InMemoryMetricsFactory(com.uber.jaeger.metrics.InMemoryMetricsFactory) ConstSampler(com.uber.jaeger.samplers.ConstSampler) TextMap(io.opentracing.propagation.TextMap) Builder(com.uber.jaeger.Tracer.Builder) Test(org.junit.Test)

Example 5 with TextMap

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

the class B3TextMapCodecResiliencyTest method shouldFallbackWhenMaliciousInput.

@Test
@UseDataProvider("maliciousInputs")
public void shouldFallbackWhenMaliciousInput(String headerName, String maliciousInput) {
    TextMap maliciousCarrier = validHeaders();
    maliciousCarrier.put(headerName, maliciousInput);
    // when
    SpanContext extract = sut.extract(maliciousCarrier);
    // then
    assertNull(extract);
}
Also used : SpanContext(com.uber.jaeger.SpanContext) TextMap(io.opentracing.propagation.TextMap) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

TextMap (io.opentracing.propagation.TextMap)29 Test (org.junit.Test)16 HashMap (java.util.HashMap)14 Map (java.util.Map)7 SpanContext (com.uber.jaeger.SpanContext)6 JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)6 ConstSampler (com.uber.jaeger.samplers.ConstSampler)3 Format (io.opentracing.propagation.Format)3 TextMapAdapter (io.opentracing.propagation.TextMapAdapter)3 SpanId (com.github.kristofa.brave.SpanId)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Metrics (com.uber.jaeger.metrics.Metrics)2 InMemoryReporter (com.uber.jaeger.reporters.InMemoryReporter)2 RequestTraceSpanContext (fish.payara.notification.requesttracing.RequestTraceSpanContext)2 JaegerSpan (io.jaegertracing.internal.JaegerSpan)2 TextMapExtractAdapter (io.opentracing.propagation.TextMapExtractAdapter)2 MultiMap (io.vertx.core.MultiMap)2 ByteBuffer (java.nio.ByteBuffer)2 Iterator (java.util.Iterator)2 Entry (java.util.Map.Entry)2