brave.http.HttpClientAdapter Java Examples

The following examples show how to use brave.http.HttpClientAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractBraveClientProvider.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected TraceScopeHolder<TraceScope> startTraceSpan(final Map<String, List<String>> requestHeaders,
        URI uri, String method) {

    final Request request = HttpAdapterFactory.request(requestHeaders, uri, method);
    final HttpClientAdapter<Request, ?> adapter = HttpClientAdapterFactory.create(request);
    
    final HttpClientHandler<Request, ?> handler = HttpClientHandler.create(brave, adapter);
    final Span span = handler.handleSend(
        brave
            .tracing()
            .propagation()
            .injector(inject(requestHeaders)), 
        request);

    // 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.
    SpanInScope scope = null;
    if (!isAsyncInvocation() && span != null) {
        scope = brave.tracing().tracer().withSpanInScope(span);
    }

    return new TraceScopeHolder<TraceScope>(new TraceScope(span, scope), scope == null /* detached */);
}
 
Example #2
Source File: AbstractBraveClientProvider.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void stopTraceSpan(final TraceScopeHolder<TraceScope> holder, final int responseStatus) {
    if (holder == null) {
        return;
    }

    final TraceScope scope = holder.getScope();
    if (scope != null) {
        try {
            // If the client invocation was asynchronous , the trace span has been created
            // in another thread and should be re-attached to the current one.
            if (holder.isDetached()) {
                brave.tracing().tracer().joinSpan(scope.getSpan().context());
            }

            final Response response = HttpAdapterFactory.response(responseStatus);
            final HttpClientAdapter<?, Response> adapter = HttpClientAdapterFactory.create(response);
            
            final HttpClientHandler<?, Response> handler = HttpClientHandler.create(brave, adapter);
            handler.handleReceive(response, null, scope.getSpan());
        } finally {
            scope.close();
        }
    }
}