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);
}
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"));
}
Aggregations