Search in sources :

Example 6 with SpanContext

use of com.uber.jaeger.SpanContext 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 7 with SpanContext

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

the class JaegerThriftSpanConverter method convertSpan.

public static com.uber.jaeger.thriftjava.Span convertSpan(Span span) {
    SpanContext context = span.context();
    boolean oneChildOfParent = span.getReferences().size() == 1 && References.CHILD_OF.equals(span.getReferences().get(0).getType());
    return new com.uber.jaeger.thriftjava.Span(context.getTraceId(), // TraceIdHigh is currently not supported
    0, context.getSpanId(), oneChildOfParent ? context.getParentId() : 0, span.getOperationName(), context.getFlags(), span.getStart(), span.getDuration()).setReferences(oneChildOfParent ? Collections.<SpanRef>emptyList() : buildReferences(span.getReferences())).setTags(buildTags(span.getTags())).setLogs(buildLogs(span.getLogs()));
}
Also used : SpanContext(com.uber.jaeger.SpanContext) SpanRef(com.uber.jaeger.thriftjava.SpanRef)

Example 8 with SpanContext

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

the class ThriftSpanConverter method convertSpan.

public static com.twitter.zipkin.thriftjava.Span convertSpan(Span span) {
    Tracer tracer = span.getTracer();
    Endpoint host = new Endpoint(tracer.getIpv4(), (short) 0, tracer.getServiceName());
    SpanContext context = span.context();
    return new com.twitter.zipkin.thriftjava.Span(context.getTraceId(), span.getOperationName(), context.getSpanId(), buildAnnotations(span, host), buildBinaryAnnotations(span, host)).setParent_id(context.getParentId()).setDebug(context.isDebug()).setTimestamp(span.getStart()).setDuration(span.getDuration());
}
Also used : SpanContext(com.uber.jaeger.SpanContext) Endpoint(com.twitter.zipkin.thriftjava.Endpoint) Tracer(com.uber.jaeger.Tracer) Span(com.uber.jaeger.Span)

Example 9 with SpanContext

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

the class ZipkinSenderTest method testFlushSendsSpan.

@Test
public void testFlushSendsSpan() throws Exception {
    Span expectedSpan = (Span) tracer.buildSpan("raza").startManual();
    assertEquals(0, sender.append(expectedSpan));
    assertEquals(1, sender.flush());
    List<List<zipkin.Span>> traces = zipkinRule.getTraces();
    assertEquals(traces.size(), 1);
    assertEquals(traces.get(0).size(), 1);
    zipkin.Span actualSpan = traces.get(0).get(0);
    SpanContext context = expectedSpan.context();
    assertEquals(context.getTraceId(), actualSpan.traceId);
    assertEquals(context.getSpanId(), actualSpan.id);
    assertEquals(context.getParentId(), (long) actualSpan.parentId);
    assertEquals(expectedSpan.getOperationName(), actualSpan.name);
    for (BinaryAnnotation binaryAnnotation : actualSpan.binaryAnnotations) {
        assertEquals(tracer.getServiceName(), binaryAnnotation.endpoint.serviceName);
    }
    for (Annotation annotation : actualSpan.annotations) {
        assertEquals(tracer.getServiceName(), annotation.endpoint.serviceName);
    }
}
Also used : BinaryAnnotation(zipkin.BinaryAnnotation) SpanContext(com.uber.jaeger.SpanContext) ArrayList(java.util.ArrayList) List(java.util.List) Span(com.uber.jaeger.Span) Annotation(zipkin.Annotation) BinaryAnnotation(zipkin.BinaryAnnotation) Test(org.junit.Test)

Example 10 with SpanContext

use of com.uber.jaeger.SpanContext 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";
    SpanContext ctx = setter.setBaggage(span, KEY, value);
    Span child = (Span) tracer.buildSpan("some-operation").asChildOf(ctx).startManual();
    ctx = setter.setBaggage(child, KEY, value);
    assertBaggageLogs(child, KEY, value, false, true, false);
    assertEquals(value, ctx.getBaggageItem(KEY));
    assertEquals(2, metricsFactory.getCounter("jaeger:baggage_updates", "result=ok"));
}
Also used : SpanContext(com.uber.jaeger.SpanContext) Span(com.uber.jaeger.Span) 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