brave.http.HttpClientRequest Java Examples
The following examples show how to use
brave.http.HttpClientRequest.
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 |
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 |
@Test void path() { final HttpRequest req = HttpRequest.of(HttpMethod.GET, "/foo"); final HttpClientRequest braveReq = ClientRequestContextAdapter.asHttpClientRequest( ClientRequestContext.of(req), req.headers().toBuilder()); assertThat(braveReq.path()).isEqualTo("/foo"); }
Example #3
Source File: ClientRequestContextAdapterTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void method() { final HttpRequest req = HttpRequest.of(HttpMethod.GET, "/foo"); final HttpClientRequest braveReq = ClientRequestContextAdapter.asHttpClientRequest( ClientRequestContext.of(req), req.headers().toBuilder()); assertThat(braveReq.method()).isEqualTo("GET"); }
Example #4
Source File: ClientRequestContextAdapterTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void url() { final HttpRequest req = HttpRequest.of( RequestHeaders.of(HttpMethod.GET, "/foo?name=hoge", HttpHeaderNames.SCHEME, "http", HttpHeaderNames.AUTHORITY, "example.com")); final HttpClientRequest braveReq = ClientRequestContextAdapter.asHttpClientRequest( ClientRequestContext.of(req), req.headers().toBuilder()); assertThat(braveReq.url()).isEqualTo("http://example.com/foo?name=hoge"); }
Example #5
Source File: ClientRequestContextAdapterTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void requestHeader() { final ClientRequestContext ctx = ClientRequestContext.of( HttpRequest.of(RequestHeaders.of(HttpMethod.GET, "/", "foo", "bar"))); ctx.logBuilder().endRequest(); ctx.logBuilder().endResponse(); final HttpClientRequest braveReq = ClientRequestContextAdapter.asHttpClientRequest(ctx, ctx.request().headers().toBuilder()); assertThat(braveReq.header("foo")).isEqualTo("bar"); assertThat(braveReq.header("bar")).isNull(); }
Example #6
Source File: TracingAsyncClientHttpRequestInterceptor.java From brave with Apache License 2.0 | 5 votes |
TraceListenableFutureCallback( HttpRequestWrapper request, Span span, HttpClientHandler<HttpClientRequest, HttpClientResponse> handler) { this.request = request; this.span = span; this.handler = handler; }
Example #7
Source File: TraceWebClientBeanPostProcessor.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
HttpClientHandler<HttpClientRequest, HttpClientResponse> handler() { if (this.handler == null) { this.handler = HttpClientHandler.create(this.httpTracing.get()); } return this.handler; }
Example #8
Source File: BraveClient.java From armeria with Apache License 2.0 | 4 votes |
@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); } }