Class TracedHttpClient
java.lang.Object
codes.grow.packages.skywalking.tracing.TracedHttpClient
Wraps a
HttpClient: every request runs in a client span and carries the propagation
headers. The span records method, redacted URL, server address/port and the response status
(4xx/5xx = error).
TracedHttpClient http = TracedHttpClient.wrap(HttpClient.newHttpClient());
HttpResponse<String> res = http.send(request, HttpResponse.BodyHandlers.ofString());
-
Method Summary
Modifier and TypeMethodDescriptiondelegate()The wrapped client.<T> HttpResponse<T> send(HttpRequest request, HttpResponse.BodyHandler<T> handler) Sends synchronously in a client span.<T> CompletableFuture<HttpResponse<T>> sendAsync(HttpRequest request, HttpResponse.BodyHandler<T> handler) Sends asynchronously in a client span that ends when the response arrives.static TracedHttpClientwrap(HttpClient delegate) Wraps a client using the helpers' tracer and propagators.static TracedHttpClientwrap(HttpClient delegate, io.opentelemetry.api.trace.Tracer tracer, io.opentelemetry.context.propagation.ContextPropagators propagators) Wraps a client with an explicit tracer and propagators.
-
Method Details
-
wrap
Wraps a client using the helpers' tracer and propagators.- Parameters:
delegate- client- Returns:
- traced client
-
wrap
public static TracedHttpClient wrap(HttpClient delegate, io.opentelemetry.api.trace.Tracer tracer, io.opentelemetry.context.propagation.ContextPropagators propagators) Wraps a client with an explicit tracer and propagators.- Parameters:
delegate- clienttracer- tracer (nullfor the default)propagators- propagators (nullfor the default)- Returns:
- traced client
-
delegate
The wrapped client.- Returns:
- client
-
send
public <T> HttpResponse<T> send(HttpRequest request, HttpResponse.BodyHandler<T> handler) throws IOException, InterruptedException Sends synchronously in a client span.- Type Parameters:
T- body type- Parameters:
request- requesthandler- body handler- Returns:
- response
- Throws:
IOException- on I/O errorsInterruptedException- when interrupted
-
sendAsync
public <T> CompletableFuture<HttpResponse<T>> sendAsync(HttpRequest request, HttpResponse.BodyHandler<T> handler) Sends asynchronously in a client span that ends when the response arrives.- Type Parameters:
T- body type- Parameters:
request- requesthandler- body handler- Returns:
- future response
-