Search in sources :

Example 11 with JaegerSpanContext

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

the class B3TextMapCodec method extract.

@Override
public JaegerSpanContext extract(TextMap carrier) {
    Long traceIdLow = null;
    // It's enough to check for a null low trace id
    Long traceIdHigh = 0L;
    Long spanId = null;
    // Conventionally, parent id == 0 means the root span
    Long parentId = 0L;
    byte flags = 0;
    Map<String, String> baggage = null;
    for (Map.Entry<String, String> entry : carrier) {
        if (entry.getKey().equalsIgnoreCase(SAMPLED_NAME)) {
            String value = entry.getValue();
            if ("1".equals(value) || "true".equalsIgnoreCase(value)) {
                flags |= SAMPLED_FLAG;
            }
        } else if (entry.getKey().equalsIgnoreCase(TRACE_ID_NAME)) {
            traceIdLow = HexCodec.lowerHexToUnsignedLong(entry.getValue());
            traceIdHigh = HexCodec.higherHexToUnsignedLong(entry.getValue());
        } else if (entry.getKey().equalsIgnoreCase(PARENT_SPAN_ID_NAME)) {
            parentId = HexCodec.lowerHexToUnsignedLong(entry.getValue());
        } else if (entry.getKey().equalsIgnoreCase(SPAN_ID_NAME)) {
            spanId = HexCodec.lowerHexToUnsignedLong(entry.getValue());
        } else if (entry.getKey().equalsIgnoreCase(FLAGS_NAME)) {
            if (entry.getValue().equals("1")) {
                flags |= DEBUG_FLAG;
            }
        } else if (entry.getKey().startsWith(baggagePrefix)) {
            if (baggage == null) {
                baggage = new HashMap<String, String>();
            }
            baggage.put(keys.unprefixedKey(entry.getKey(), baggagePrefix), entry.getValue());
        }
    }
    if (null != traceIdLow && null != parentId && null != spanId) {
        JaegerSpanContext spanContext = objectFactory.createSpanContext(traceIdHigh, traceIdLow, spanId, parentId, flags, Collections.<String, String>emptyMap(), // debugId
        null);
        if (baggage != null) {
            spanContext = spanContext.withBaggage(baggage);
        }
        return spanContext;
    }
    return null;
}
Also used : HashMap(java.util.HashMap) TextMap(io.opentracing.propagation.TextMap) Map(java.util.Map) HashMap(java.util.HashMap) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext)

Example 12 with JaegerSpanContext

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

the class JaegerTracerResiliencyTest method shouldFallbackWhenInjectingWithFaultyCodec.

@Test
public void shouldFallbackWhenInjectingWithFaultyCodec() {
    JaegerSpanContext context = tracer.buildSpan("test-span").start().context();
    tracer.inject(context, Builtin.TEXT_MAP, new NoopTextMap());
}
Also used : JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 13 with JaegerSpanContext

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

the class JaegerTracerResiliencyTest method shouldFallbackWhenExtractingWithFaultyCodec.

@Test
public void shouldFallbackWhenExtractingWithFaultyCodec() {
    JaegerSpanContext span = tracer.extract(Builtin.TEXT_MAP, new NoopTextMap());
    assertNull(span);
}
Also used : JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 14 with JaegerSpanContext

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

the class BaggageSetterTest method testOverrideBaggage.

@Test
public void testOverrideBaggage() {
    when(mgr.getRestriction(SERVICE, KEY)).thenReturn(Restriction.of(true, 5));
    final String value = "value";
    JaegerSpanContext ctx = setter.setBaggage(jaegerSpan, KEY, value);
    JaegerSpan child = tracer.buildSpan("some-operation").asChildOf(ctx).start();
    ctx = setter.setBaggage(child, KEY, value);
    assertBaggageLogs(child, KEY, value, false, true, false);
    assertEquals(value, ctx.getBaggageItem(KEY));
    assertEquals(2, metricsFactory.getCounter("jaeger_tracer_baggage_updates", "result=ok"));
}
Also used : JaegerSpan(io.jaegertracing.internal.JaegerSpan) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 15 with JaegerSpanContext

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

the class BaggageSetterTest method testUnsampledSpan.

@Test
public void testUnsampledSpan() {
    tracer = new JaegerTracer.Builder(SERVICE).withReporter(reporter).withSampler(new ConstSampler(false)).withMetrics(metrics).build();
    jaegerSpan = tracer.buildSpan("some-operation").start();
    when(mgr.getRestriction(SERVICE, KEY)).thenReturn(Restriction.of(true, 5));
    final String value = "value";
    JaegerSpanContext ctx = setter.setBaggage(jaegerSpan, KEY, value);
    assertEquals(value, ctx.getBaggageItem(KEY));
    // No logs should be written if the span is not sampled
    assertNull(jaegerSpan.getLogs());
}
Also used : ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) JaegerTracer(io.jaegertracing.internal.JaegerTracer) 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