Search in sources :

Example 31 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project cxf by apache.

the class OpenTracingTracingTest method testThatOuterSpanIsCreatedUsingAsyncInvocation.

@Test
public void testThatOuterSpanIsCreatedUsingAsyncInvocation() {
    final JaegerSpanContext spanId = fromRandom();
    final Response r = withTrace(createWebClient("/bookstore/books/async/notrace"), spanId).get();
    assertEquals(Status.OK.getStatusCode(), r.getStatus());
    assertThat(REPORTER.getSpans().size(), equalTo(1));
    assertThat(REPORTER.getSpans().get(0).getOperationName(), equalTo("GET /bookstore/books/async/notrace"));
}
Also used : Response(javax.ws.rs.core.Response) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 32 with JaegerSpanContext

use of io.jaegertracing.internal.JaegerSpanContext in project cxf by apache.

the class OpenTracingTracingTest method testThatNewInnerSpanIsCreated.

@Test
public void testThatNewInnerSpanIsCreated() {
    final JaegerSpanContext spanId = fromRandom();
    final Response r = withTrace(createWebClient("/bookstore/books"), spanId).get();
    assertEquals(Status.OK.getStatusCode(), r.getStatus());
    assertThat(REPORTER.getSpans().size(), equalTo(2));
    assertThat(REPORTER.getSpans().get(0).getOperationName(), equalTo("Get Books"));
    assertThat(REPORTER.getSpans().get(1).getOperationName(), equalTo("GET /bookstore/books"));
}
Also used : Response(javax.ws.rs.core.Response) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Example 33 with JaegerSpanContext

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

the class TextMapCodec method extract.

@Override
public JaegerSpanContext extract(TextMap carrier) {
    JaegerSpanContext context = null;
    Map<String, String> baggage = null;
    String debugId = null;
    for (Map.Entry<String, String> entry : carrier) {
        String key = entry.getKey();
        if (key.equalsIgnoreCase(contextKey)) {
            context = contextFromString(decodedValue(entry.getValue()));
        } else if (key.equalsIgnoreCase(Constants.DEBUG_ID_HEADER_KEY)) {
            debugId = decodedValue(entry.getValue());
        } else if (key.regionMatches(true, 0, baggagePrefix, 0, baggagePrefix.length())) {
            if (baggage == null) {
                baggage = new HashMap<>();
            }
            baggage.put(keys.unprefixedKey(key.toLowerCase(Locale.ROOT), baggagePrefix), decodedValue(entry.getValue()));
        } else if (key.equalsIgnoreCase(Constants.BAGGAGE_HEADER_KEY)) {
            baggage = parseBaggageHeader(decodedValue(entry.getValue()), baggage);
        }
    }
    if (debugId == null && baggage == null) {
        return context;
    }
    return objectFactory.createSpanContext(context == null ? 0L : context.getTraceIdHigh(), context == null ? 0L : context.getTraceIdLow(), context == null ? 0L : context.getSpanId(), context == null ? 0L : context.getParentId(), context == null ? (byte) 0 : context.getFlags(), baggage, debugId);
}
Also used : HashMap(java.util.HashMap) TextMap(io.opentracing.propagation.TextMap) Map(java.util.Map) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext)

Example 34 with JaegerSpanContext

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

the class ConfigurationTest method testPropagationB3Only.

@Test
public void testPropagationB3Only() {
    System.setProperty(Configuration.JAEGER_PROPAGATION, "b3");
    System.setProperty(Configuration.JAEGER_SERVICE_NAME, "Test");
    long traceIdLow = 1234L;
    long spanId = 5678L;
    TestTextMap textMap = new TestTextMap();
    JaegerSpanContext spanContext = new JaegerSpanContext(0, traceIdLow, spanId, 0, (byte) 0);
    JaegerTracer tracer = Configuration.fromEnv().getTracer();
    tracer.inject(spanContext, Format.Builtin.TEXT_MAP, textMap);
    assertNotNull(textMap.get("X-B3-TraceId"));
    assertNotNull(textMap.get("X-B3-SpanId"));
    assertNull(textMap.get("uber-trace-id"));
    JaegerSpanContext extractedContext = tracer.extract(Format.Builtin.TEXT_MAP, textMap);
    assertEquals(traceIdLow, extractedContext.getTraceIdLow());
    assertEquals(0, extractedContext.getTraceIdHigh());
    assertEquals(spanId, extractedContext.getSpanId());
}
Also used : JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Example 35 with JaegerSpanContext

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

the class TraceContextCodec method extractContextFromTraceParent.

private JaegerSpanContext extractContextFromTraceParent(String traceparent, String tracestate, String debugId) {
    // TODO(bdrutu): Do we need to verify that version is hex and that
    // for the version the length is the expected one?
    boolean isValid = traceparent != null && traceparent.charAt(TRACE_OPTION_OFFSET - 1) == TRACEPARENT_DELIMITER && (traceparent.length() == TRACEPARENT_HEADER_SIZE || (traceparent.length() > TRACEPARENT_HEADER_SIZE && traceparent.charAt(TRACEPARENT_HEADER_SIZE) == TRACEPARENT_DELIMITER)) && traceparent.charAt(SPAN_ID_OFFSET - 1) == TRACEPARENT_DELIMITER && traceparent.charAt(TRACE_OPTION_OFFSET - 1) == TRACEPARENT_DELIMITER;
    if (!isValid) {
        log.warn("Unparseable traceparent header. Returning null span context.");
        return null;
    }
    Long traceIdHigh = HexCodec.hexToUnsignedLong(traceparent, TRACE_ID_OFFSET, TRACE_ID_OFFSET + 16);
    Long traceIdLow = HexCodec.hexToUnsignedLong(traceparent, TRACE_ID_OFFSET + 16, TRACE_ID_OFFSET + 32);
    Long spanId = HexCodec.hexToUnsignedLong(traceparent, SPAN_ID_OFFSET, SPAN_ID_OFFSET + 16);
    boolean sampled = false;
    long traceContextFlags = HexCodec.hexToUnsignedLong(traceparent, TRACE_OPTION_OFFSET, TRACE_OPTION_OFFSET + 2);
    if ((traceContextFlags & SAMPLED_FLAG) == SAMPLED_FLAG) {
        sampled = true;
    }
    if (traceIdLow == null || traceIdLow == 0 || spanId == null || spanId == 0) {
        log.warn("Unparseable traceparent header. Returning null span context.");
        return null;
    }
    JaegerSpanContext spanContext = this.objectFactory.createSpanContext(traceIdHigh, traceIdLow, spanId, 0, sampled ? (byte) 1 : (byte) 0, Collections.<String, String>emptyMap(), debugId);
    return spanContext.withTraceState(tracestate);
}
Also used : JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext)

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