Search in sources :

Example 26 with SpanContext

use of com.uber.jaeger.SpanContext in project jaeger-client-java by jaegertracing.

the class TraceBehavior method observeSpan.

private ObservedSpan observeSpan() {
    com.uber.jaeger.context.TraceContext traceContext = TracingUtils.getTraceContext();
    if (traceContext.isEmpty()) {
        log.error("No span found");
        return new ObservedSpan("no span found", false, "no span found");
    }
    Span span = (Span) traceContext.getCurrentSpan();
    if (span == null) {
        log.error("No span found");
        return new ObservedSpan("no span found", false, "no span found");
    }
    SpanContext context = span.context();
    String traceId = String.format("%x", context.getTraceId());
    boolean sampled = context.isSampled();
    String baggage = span.getBaggageItem(Constants.BAGGAGE_KEY);
    return new ObservedSpan(traceId, sampled, baggage);
}
Also used : ObservedSpan(com.uber.jaeger.crossdock.api.ObservedSpan) SpanContext(com.uber.jaeger.SpanContext) ObservedSpan(com.uber.jaeger.crossdock.api.ObservedSpan) Span(com.uber.jaeger.Span)

Example 27 with SpanContext

use of com.uber.jaeger.SpanContext in project jaeger-client-java by jaegertracing.

the class B3TextMapCodecTest method testInject_rootSpan.

@Test
public void testInject_rootSpan() throws Exception {
    DelegatingTextMap textMap = new DelegatingTextMap();
    b3Codec.inject(new SpanContext(1, 1, 0, SAMPLED), textMap);
    TraceData data = takeRequestFromTextMap(textMap);
    assertEquals(1, data.getSpanId().traceId);
    assertEquals(null, data.getSpanId().nullableParentId());
    assertEquals(1, data.getSpanId().spanId);
    assertEquals(Boolean.TRUE, data.getSample());
}
Also used : SpanContext(com.uber.jaeger.SpanContext) TraceData(com.github.kristofa.brave.TraceData) Test(org.junit.Test)

Example 28 with SpanContext

use of com.uber.jaeger.SpanContext in project jaeger-client-java by jaegertracing.

the class B3TextMapCodecTest method testInject_childSpan.

@Test
public void testInject_childSpan() throws Exception {
    DelegatingTextMap textMap = new DelegatingTextMap();
    b3Codec.inject(new SpanContext(1, 2, 1, SAMPLED), textMap);
    TraceData data = takeRequestFromTextMap(textMap);
    assertEquals(1, data.getSpanId().traceId);
    assertEquals(Long.valueOf(1), data.getSpanId().nullableParentId());
    assertEquals(2, data.getSpanId().spanId);
    assertEquals(Boolean.TRUE, data.getSample());
}
Also used : SpanContext(com.uber.jaeger.SpanContext) TraceData(com.github.kristofa.brave.TraceData) Test(org.junit.Test)

Example 29 with SpanContext

use of com.uber.jaeger.SpanContext in project jaeger-client-java by jaegertracing.

the class B3TextMapCodecTest method testExtract_unsampled.

@Test
public void testExtract_unsampled() throws Exception {
    TextMap textMap = makeRequestWithSpanId(null);
    SpanContext context = b3Codec.extract(textMap);
    assertEquals(null, context);
}
Also used : SpanContext(com.uber.jaeger.SpanContext) TextMap(io.opentracing.propagation.TextMap) Test(org.junit.Test)

Aggregations

SpanContext (com.uber.jaeger.SpanContext)29 Test (org.junit.Test)25 TextMap (io.opentracing.propagation.TextMap)6 Response (javax.ws.rs.core.Response)6 Span (com.uber.jaeger.Span)5 TraceData (com.github.kristofa.brave.TraceData)3 HashMap (java.util.HashMap)3 SpanId (com.github.kristofa.brave.SpanId)2 Tracer (com.uber.jaeger.Tracer)2 Span (io.opentracing.Span)2 List (java.util.List)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 Endpoint (com.twitter.zipkin.thriftjava.Endpoint)1 ObservedSpan (com.uber.jaeger.crossdock.api.ObservedSpan)1 ConstSampler (com.uber.jaeger.samplers.ConstSampler)1 SpanRef (com.uber.jaeger.thriftjava.SpanRef)1 TextMapExtractAdapter (io.opentracing.propagation.TextMapExtractAdapter)1 TextMapInjectAdapter (io.opentracing.propagation.TextMapInjectAdapter)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1