brave.http.HttpClientResponse Java Examples

The following examples show how to use brave.http.HttpClientResponse. 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 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 #2
Source File: ClientRequestContextAdapterTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Test
void statusCode() {
    final HttpRequest req = HttpRequest.of(HttpMethod.GET, "/");
    final ClientRequestContext ctx = ClientRequestContext.of(req);
    ctx.logBuilder().endRequest();
    ctx.logBuilder().responseHeaders(ResponseHeaders.of(HttpStatus.OK));
    ctx.logBuilder().endResponse();

    final HttpClientResponse res =
            ClientRequestContextAdapter.asHttpClientResponse(ctx.log().ensureComplete(), null);

    assertThat(res.statusCode()).isEqualTo(200);
}
 
Example #3
Source File: TracingAsyncClientHttpRequestInterceptor.java    From brave with Apache License 2.0 5 votes vote down vote up
TraceListenableFutureCallback(
  HttpRequestWrapper request, Span span,
  HttpClientHandler<HttpClientRequest, HttpClientResponse> handler) {
  this.request = request;
  this.span = span;
  this.handler = handler;
}
 
Example #4
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 #5
Source File: BraveClient.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
public HttpResponse execute(ClientRequestContext ctx, HttpRequest req) throws Exception {
    final RequestHeadersBuilder newHeaders = req.headers().toBuilder();
    final HttpClientRequest braveReq = ClientRequestContextAdapter.asHttpClientRequest(ctx, newHeaders);
    final Span span = handler.handleSend(braveReq);
    req = req.withHeaders(newHeaders);
    ctx.updateRequest(req);

    // For no-op spans, we only need to inject into headers and don't set any other attributes.
    if (span.isNoop()) {
        try (SpanInScope ignored = tracer.withSpanInScope(span)) {
            return unwrap().execute(ctx, req);
        }
    }

    ctx.log().whenComplete().thenAccept(log -> {
        span.start(log.requestStartTimeMicros());

        final Long wireSendTimeNanos = log.requestFirstBytesTransferredTimeNanos();
        if (wireSendTimeNanos != null) {
            SpanTags.logWireSend(span, wireSendTimeNanos, log);
        } else {
            // The request might have failed even before it's sent,
            // e.g. validation failure, connection error.
        }

        final Long wireReceiveTimeNanos = log.responseFirstBytesTransferredTimeNanos();
        if (wireReceiveTimeNanos != null) {
            SpanTags.logWireReceive(span, wireReceiveTimeNanos, log);
        } else {
            // If the client timed-out the request, we will have never received any response data at all.
        }

        SpanTags.updateRemoteEndpoint(span, ctx);

        final ClientConnectionTimings timings = log.connectionTimings();
        if (timings != null) {
            logTiming(span, "connection-acquire.start", "connection-acquire.end",
                      timings.connectionAcquisitionStartTimeMicros(),
                      timings.connectionAcquisitionDurationNanos());
            if (timings.dnsResolutionDurationNanos() != -1) {
                logTiming(span, "dns-resolve.start", "dns-resolve.end",
                          timings.dnsResolutionStartTimeMicros(),
                          timings.dnsResolutionDurationNanos());
            }
            if (timings.socketConnectDurationNanos() != -1) {
                logTiming(span, "socket-connect.start", "socket-connect.end",
                          timings.socketConnectStartTimeMicros(),
                          timings.socketConnectDurationNanos());
            }
            if (timings.pendingAcquisitionDurationNanos() != -1) {
                logTiming(span, "connection-reuse.start", "connection-reuse.end",
                          timings.pendingAcquisitionStartTimeMicros(),
                          timings.pendingAcquisitionDurationNanos());
            }
        }

        final HttpClientResponse braveRes = ClientRequestContextAdapter.asHttpClientResponse(log, braveReq);
        handler.handleReceive(braveRes, span);
    });

    try (SpanInScope ignored = tracer.withSpanInScope(span)) {
        return unwrap().execute(ctx, req);
    }
}