Search in sources :

Example 11 with TextMapAdapter

use of io.opentracing.propagation.TextMapAdapter in project cxf by apache.

the class AbstractOpenTracingProvider method startTraceSpan.

protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders, URI uri, String method) {
    SpanContext parent = tracer.extract(Builtin.HTTP_HEADERS, new TextMapAdapter(requestHeaders.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, this::getFirstValueOrEmpty))));
    final Span activeSpan;
    final Scope scope;
    if (parent == null) {
        activeSpan = tracer.buildSpan(buildSpanDescription(uri.getPath(), method)).start();
        scope = tracer.scopeManager().activate(activeSpan);
    } else {
        activeSpan = tracer.buildSpan(buildSpanDescription(uri.getPath(), method)).asChildOf(parent).start();
        scope = tracer.scopeManager().activate(activeSpan);
    }
    // Set additional tags
    activeSpan.setTag(Tags.HTTP_METHOD.getKey(), method);
    activeSpan.setTag(Tags.HTTP_URL.getKey(), uri.toString());
    // If the service resource is using asynchronous processing mode, the trace
    // scope will be closed in another thread and as such should be detached.
    Span span = null;
    if (isAsyncResponse()) {
        // Do not modify the current context span
        span = activeSpan;
        propagateContinuationSpan(span);
        scope.close();
    }
    return new TraceScopeHolder<TraceScope>(new TraceScope(activeSpan, scope), span != null);
}
Also used : SpanContext(io.opentracing.SpanContext) Scope(io.opentracing.Scope) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) Map(java.util.Map) Span(io.opentracing.Span)

Example 12 with TextMapAdapter

use of io.opentracing.propagation.TextMapAdapter in project brave by openzipkin.

the class OpenTracingAdapterTest method injectRemoteSpanTraceContext.

@Test
public void injectRemoteSpanTraceContext() {
    BraveSpan openTracingSpan = opentracing.buildSpan("encode").withTag("lc", "codec").withTag(Tags.SPAN_KIND, Tags.SPAN_KIND_PRODUCER).withStartTimestamp(1L).start();
    Map<String, String> map = new LinkedHashMap<>();
    TextMapAdapter request = new TextMapAdapter(map);
    opentracing.inject(openTracingSpan.context(), Format.Builtin.HTTP_HEADERS, request);
    assertThat(map).containsOnlyKeys("b3");
    openTracingSpan.unwrap().abandon();
}
Also used : TextMapAdapter(io.opentracing.propagation.TextMapAdapter) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 13 with TextMapAdapter

use of io.opentracing.propagation.TextMapAdapter in project brave by openzipkin.

the class OpenTracingAdapterTest method injectTraceContext.

@Test
public void injectTraceContext() {
    TraceContext context = TraceContext.newBuilder().traceId(1L).spanId(2L).sampled(true).build();
    Map<String, String> map = new LinkedHashMap<>();
    TextMapAdapter request = new TextMapAdapter(map);
    opentracing.inject(new BraveSpanContext(context), Format.Builtin.HTTP_HEADERS, request);
    assertThat(map).containsExactly(entry("X-B3-TraceId", "0000000000000001"), entry("X-B3-SpanId", "0000000000000002"), entry("X-B3-Sampled", "1"));
}
Also used : TraceContext(brave.propagation.TraceContext) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 14 with TextMapAdapter

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

the class AdhocHeadersTest method traceWithAdhocBaggage.

private void traceWithAdhocBaggage(Map<String, String> headers) {
    headers.put("jaeger-baggage", "k1=v1, k2 = v2");
    JaegerSpanContext parent = tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapAdapter(headers));
    JaegerSpan span = tracer.buildSpan("test").asChildOf(parent).start();
    assertTrue(span.context().isSampled());
    assertEquals("must have baggage", "v1", span.getBaggageItem("k1"));
    assertEquals("must have baggage", "v2", span.getBaggageItem("k2"));
}
Also used : TextMapAdapter(io.opentracing.propagation.TextMapAdapter)

Example 15 with TextMapAdapter

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

the class ThriftSpanConverterTest method testRpcChildSpanHasTheSameId.

@Test
public void testRpcChildSpanHasTheSameId() {
    String expectedOperation = "parent";
    JaegerSpan client = tracer.buildSpan(expectedOperation).withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).start();
    Map<String, String> map = new HashMap<>();
    TextMap carrier = new TextMapAdapter(map);
    tracer.inject(client.context(), Format.Builtin.TEXT_MAP, carrier);
    JaegerSpanContext ctx = tracer.extract(Format.Builtin.TEXT_MAP, carrier);
    JaegerSpanContext clientCtx = client.context();
    assertEquals(clientCtx.getSpanId(), ctx.getSpanId());
    JaegerSpan server = tracer.buildSpan("child").withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER).asChildOf(ctx).start();
    JaegerSpanContext serverCtx = server.context();
    assertEquals("client and server must have the same span ID", clientCtx.getSpanId(), serverCtx.getSpanId());
}
Also used : HashMap(java.util.HashMap) JaegerSpan(io.jaegertracing.internal.JaegerSpan) TextMap(io.opentracing.propagation.TextMap) TextMapAdapter(io.opentracing.propagation.TextMapAdapter) JaegerSpanContext(io.jaegertracing.internal.JaegerSpanContext) Test(org.junit.Test)

Aggregations

TextMapAdapter (io.opentracing.propagation.TextMapAdapter)26 Test (org.junit.Test)23 JaegerSpanContext (io.jaegertracing.internal.JaegerSpanContext)19 HashMap (java.util.HashMap)16 JaegerSpan (io.jaegertracing.internal.JaegerSpan)4 TextMap (io.opentracing.propagation.TextMap)3 LinkedHashMap (java.util.LinkedHashMap)3 JaegerTracer (io.jaegertracing.internal.JaegerTracer)2 InMemoryReporter (io.jaegertracing.internal.reporters.InMemoryReporter)2 Span (io.opentracing.Span)2 TraceContext (brave.propagation.TraceContext)1 Scope (io.opentracing.Scope)1 SpanContext (io.opentracing.SpanContext)1 Map (java.util.Map)1