Search in sources :

Example 1 with TextMapInjectAdapter

use of org.apache.cxf.tracing.opentracing.internal.TextMapInjectAdapter in project cxf by apache.

the class AbstractOpenTracingClientProvider method startTraceSpan.

protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders, URI uri, String method) {
    final ActiveSpan parent = tracer.activeSpan();
    ActiveSpan span = null;
    if (parent == null) {
        span = tracer.buildSpan(buildSpanDescription(uri.toString(), method)).startActive();
    } else {
        span = tracer.buildSpan(buildSpanDescription(uri.toString(), method)).asChildOf(parent).startActive();
    }
    // Set additional tags
    span.setTag(Tags.HTTP_METHOD.getKey(), method);
    span.setTag(Tags.HTTP_URL.getKey(), uri.toString());
    tracer.inject(span.context(), Builtin.HTTP_HEADERS, new TextMapInjectAdapter(requestHeaders));
    // In case of asynchronous client invocation, the span should be detached as JAX-RS
    // client request / response filters are going to be executed in different threads.
    Continuation continuation = null;
    if (isAsyncInvocation()) {
        continuation = span.capture();
        span.deactivate();
    }
    return new TraceScopeHolder<TraceScope>(new TraceScope(span, continuation), continuation != null);
}
Also used : Continuation(io.opentracing.ActiveSpan.Continuation) ActiveSpan(io.opentracing.ActiveSpan) TextMapInjectAdapter(org.apache.cxf.tracing.opentracing.internal.TextMapInjectAdapter)

Example 2 with TextMapInjectAdapter

use of org.apache.cxf.tracing.opentracing.internal.TextMapInjectAdapter in project cxf by apache.

the class OpenTracingTracingTest method testThatNewInnerSpanIsCreated.

@Test
public void testThatNewInnerSpanIsCreated() throws MalformedURLException {
    final SpanContext spanId = fromRandom();
    final Map<String, List<String>> headers = new HashMap<>();
    tracer.inject(spanId, Builtin.HTTP_HEADERS, new TextMapInjectAdapter(headers));
    final BookStoreService service = createJaxWsService(headers);
    assertThat(service.getBooks().size(), equalTo(2));
    assertThat(TestSender.getAllSpans().size(), equalTo(2));
    assertThat(TestSender.getAllSpans().get(0).getOperationName(), equalTo("Get Books"));
    assertThat(TestSender.getAllSpans().get(1).getOperationName(), equalTo("POST /BookStore"));
}
Also used : SpanContext(com.uber.jaeger.SpanContext) HashMap(java.util.HashMap) TextMapInjectAdapter(org.apache.cxf.tracing.opentracing.internal.TextMapInjectAdapter) BookStoreService(org.apache.cxf.systest.jaxws.tracing.BookStoreService) List(java.util.List) Test(org.junit.Test)

Aggregations

TextMapInjectAdapter (org.apache.cxf.tracing.opentracing.internal.TextMapInjectAdapter)2 SpanContext (com.uber.jaeger.SpanContext)1 ActiveSpan (io.opentracing.ActiveSpan)1 Continuation (io.opentracing.ActiveSpan.Continuation)1 HashMap (java.util.HashMap)1 List (java.util.List)1 BookStoreService (org.apache.cxf.systest.jaxws.tracing.BookStoreService)1 Test (org.junit.Test)1