Java Code Examples for brave.http.HttpClientHandler#create()

The following examples show how to use brave.http.HttpClientHandler#create() . 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: TraceAdapterMonitor.java    From mdw with Apache License 2.0 6 votes vote down vote up
/**
 * Only for HTTP.
 */
@Override
public Object onRequest(ActivityRuntimeContext context, Object content, Map<String,String> headers, Object connection) {
    if (connection instanceof HttpConnection) {
        HttpConnection httpConnection = (HttpConnection)connection;
        Tracing tracing = TraceHelper.getTracing("mdw-adapter");
        HttpTracing httpTracing = HttpTracing.create(tracing).toBuilder()
                .clientParser(new HttpClientParser() {
                    public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) {
                        // customize span name
                        customizer.name(context.getActivity().oneLineName());
                    }
                })
                .build();
        Tracer tracer = httpTracing.tracing().tracer();
        handler = HttpClientHandler.create(httpTracing, new ClientAdapter());
        injector = httpTracing.tracing().propagation().injector((httpRequest, key, value) -> headers.put(key, value));
        span = handler.handleSend(injector, new HttpRequest(httpConnection));
        scope = tracer.withSpanInScope(span);
    }
    return null;
}
 
Example 2
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 3
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();
        }
    }
}
 
Example 4
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 Throwable ex) {
    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 HttpClientHandler<HttpClientRequest, HttpClientResponse> handler = 
                    HttpClientHandler.create(brave);
            handler.handleReceive(null, ex, scope.getSpan());
        } finally {
            scope.close();
        }
    }
}
 
Example 5
Source File: ZipkinHttpClientImpl.java    From ratpack-zipkin with Apache License 2.0 5 votes vote down vote up
@Inject
public ZipkinHttpClientImpl(final HttpClient delegate, final HttpTracing httpTracing) {
    this.delegate = delegate;
    this.threadLocalSpan = ThreadLocalSpan.create(httpTracing.tracing().tracer());
    this.currentTraceContext = httpTracing.tracing().currentTraceContext();
    this.nextThreadLocalSpan = new NextSpan(threadLocalSpan, httpTracing.clientSampler());
    this.handler = HttpClientHandler.create(httpTracing, ADAPTER);
    this.injector = httpTracing.tracing().propagation().injector(MutableHeaders::set);
}
 
Example 6
Source File: TraceRequestHttpHeadersFilter.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
AbstractHttpHeadersFilter(HttpTracing httpTracing) {
	this.tracer = httpTracing.tracing().tracer();
	this.extractor = httpTracing.tracing().propagation()
			.extractor(HttpClientRequest::header);
	this.handler = HttpClientHandler.create(httpTracing);
	this.httpTracing = httpTracing;
}
 
Example 7
Source File: TracingFeignClient.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
TracingFeignClient(HttpTracing httpTracing, Client delegate) {
	this.currentTraceContext = httpTracing.tracing().currentTraceContext();
	this.handler = HttpClientHandler.create(httpTracing);
	Client delegateTarget = ProxyUtils.getTargetObject(delegate);
	this.delegate = delegateTarget instanceof TracingFeignClient
			? ((TracingFeignClient) delegateTarget).delegate : delegateTarget;
}
 
Example 8
Source File: TracingMainExec.java    From brave with Apache License 2.0 5 votes vote down vote up
TracingMainExec(HttpTracing httpTracing, ClientExecChain mainExec) {
  this.tracer = httpTracing.tracing().tracer();
  this.currentTraceContext = httpTracing.tracing().currentTraceContext();
  this.serverName = "".equals(httpTracing.serverName()) ? null : httpTracing.serverName();
  this.handler = HttpClientHandler.create(httpTracing);
  this.mainExec = mainExec;
}
 
Example 9
Source File: BraveClient.java    From armeria with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new instance.
 */
private BraveClient(HttpClient delegate, HttpTracing httpTracing) {
    super(delegate);
    tracer = httpTracing.tracing().tracer();
    handler = HttpClientHandler.create(httpTracing);
}
 
Example 10
Source File: TracingClientHttpRequestInterceptor.java    From brave with Apache License 2.0 4 votes vote down vote up
@Autowired TracingClientHttpRequestInterceptor(HttpTracing httpTracing) {
  currentTraceContext = httpTracing.tracing().currentTraceContext();
  handler = HttpClientHandler.create(httpTracing);
}
 
Example 11
Source File: TracingAsyncClientHttpRequestInterceptor.java    From brave with Apache License 2.0 4 votes vote down vote up
@Autowired TracingAsyncClientHttpRequestInterceptor(HttpTracing httpTracing) {
  currentTraceContext = httpTracing.tracing().currentTraceContext();
  handler = HttpClientHandler.create(httpTracing);
}
 
Example 12
Source File: TracingHttpAsyncClientBuilder.java    From brave with Apache License 2.0 4 votes vote down vote up
TracingHttpAsyncClientBuilder(HttpTracing httpTracing) { // intentionally hidden
  if (httpTracing == null) throw new NullPointerException("httpTracing == null");
  this.currentTraceContext = httpTracing.tracing().currentTraceContext();
  this.handler = HttpClientHandler.create(httpTracing);
}
 
Example 13
Source File: TracingInterceptor.java    From brave with Apache License 2.0 4 votes vote down vote up
TracingInterceptor(HttpTracing httpTracing) {
  tracer = httpTracing.tracing().tracer();
  handler = HttpClientHandler.create(httpTracing);
}
 
Example 14
Source File: TracingProtocolExec.java    From brave with Apache License 2.0 4 votes vote down vote up
TracingProtocolExec(HttpTracing httpTracing, ClientExecChain protocolExec) {
  this.tracer = httpTracing.tracing().tracer();
  this.httpSampler = httpTracing.clientRequestSampler();
  this.handler = HttpClientHandler.create(httpTracing);
  this.protocolExec = protocolExec;
}
 
Example 15
Source File: ZipkinConsumerDelegate.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
ZipkinConsumerDelegate(HttpTracing httpTracing) {
  this.httpTracing = httpTracing;
  this.injector = httpTracing.tracing().propagation().injector(injector());
  this.handler = HttpClientHandler.create(httpTracing, new ConsumerInvocationAdapter());
}
 
Example 16
Source File: TraceWebClientBeanPostProcessor.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
HttpClientHandler<HttpClientRequest, HttpClientResponse> handler() {
	if (this.handler == null) {
		this.handler = HttpClientHandler.create(this.httpTracing.get());
	}
	return this.handler;
}
 
Example 17
Source File: TracingInterceptor.java    From brave with Apache License 2.0 4 votes vote down vote up
TracingInterceptor(HttpTracing httpTracing) {
  if (httpTracing == null) throw new NullPointerException("HttpTracing == null");
  currentTraceContext = httpTracing.tracing().currentTraceContext();
  handler = HttpClientHandler.create(httpTracing);
}
 
Example 18
Source File: HttpClientBeanPostProcessor.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
HttpClientHandler<brave.http.HttpClientRequest, brave.http.HttpClientResponse> handler() {
	if (this.handler == null) {
		this.handler = HttpClientHandler.create(httpTracing.get());
	}
	return this.handler;
}
 
Example 19
Source File: TracingClientFilter.java    From brave with Apache License 2.0 4 votes vote down vote up
@Inject TracingClientFilter(HttpTracing httpTracing) {
  if (httpTracing == null) throw new NullPointerException("HttpTracing == null");
  tracer = httpTracing.tracing().tracer();
  handler = HttpClientHandler.create(httpTracing);
}
 
Example 20
Source File: TracingExecutionInterceptor.java    From zipkin-aws with Apache License 2.0 4 votes vote down vote up
TracingExecutionInterceptor(HttpTracing httpTracing) {
  this.handler = HttpClientHandler.create(httpTracing);
}