Search in sources :

Example 1 with Continuation

use of io.opentracing.ActiveSpan.Continuation 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 Continuation

use of io.opentracing.ActiveSpan.Continuation 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 TextMapExtractAdapter(requestHeaders.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, this::getFirstValueOrEmpty))));
    ActiveSpan scope = null;
    if (parent == null) {
        scope = tracer.buildSpan(buildSpanDescription(uri.getPath(), method)).startActive();
    } else {
        scope = tracer.buildSpan(buildSpanDescription(uri.getPath(), method)).asChildOf(parent).startActive();
    }
    // Set additional tags
    scope.setTag(Tags.HTTP_METHOD.getKey(), method);
    scope.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.
    Continuation continuation = null;
    if (isAsyncResponse()) {
        // Do not modify the current context span
        continuation = scope.capture();
        propagateContinuationSpan(continuation);
        scope.deactivate();
    }
    return new TraceScopeHolder<TraceScope>(new TraceScope(scope, continuation), continuation != null);
}
Also used : TextMapExtractAdapter(io.opentracing.propagation.TextMapExtractAdapter) Continuation(io.opentracing.ActiveSpan.Continuation) SpanContext(io.opentracing.SpanContext) ActiveSpan(io.opentracing.ActiveSpan) Map(java.util.Map)

Aggregations

ActiveSpan (io.opentracing.ActiveSpan)2 Continuation (io.opentracing.ActiveSpan.Continuation)2 SpanContext (io.opentracing.SpanContext)1 TextMapExtractAdapter (io.opentracing.propagation.TextMapExtractAdapter)1 Map (java.util.Map)1 TextMapInjectAdapter (org.apache.cxf.tracing.opentracing.internal.TextMapInjectAdapter)1