public class HttpClientPropagator extends Object
Example instrumentation for a synchronous client call:
HttpClientRequestAdapter adaptedHttpRequest = new HttpClientRequestAdapter(actualHttpRequest);
HttpClientResponseAdapter adaptedHttpResponse = null;
Throwable error = null;
Span span = clientPropagator.startPropagation(adaptedHttpRequest);
try {
actualHttpResponse = makeClientCall(actualHttpRequest);
adaptedHttpResponse = new HttpClientResponseAdapter(actualHttpResponse);
} catch (Exception ex) {
error = ex;
throw ex;
} finally {
clientPropagator.endPropagation(adaptedHttpResponse, error, span);
}
The API is based on Brave's HTTP utilities under brave.http
.
Modifier and Type | Field | Description |
---|---|---|
static String |
HTTP_CLIENT_SPAN_TYPE |
Modifier | Constructor | Description |
---|---|---|
protected |
HttpClientPropagator(Tracer tracer,
PropagationCodec<String> propagationCodec,
Function<HttpClientRequestAdapter,String> requestToSpanName) |
|
|
HttpClientPropagator(Tracer tracer,
Function<HttpClientRequestAdapter,String> requestToSpanName) |
Create an HttpClientPropagator for tracing HTTP client requests.
|
Modifier and Type | Method | Description |
---|---|---|
void |
endPropagation(HttpClientResponseAdapter httpResponse,
Throwable error,
Span span) |
Adds standard span fields based on data in the HTTP response or the
error . |
Span |
startPropagation(HttpClientRequestAdapter httpRequest) |
Creates a child span for this HTTP client request and adds the standardized fields to it.
|
public static final String HTTP_CLIENT_SPAN_TYPE
public HttpClientPropagator(Tracer tracer, Function<HttpClientRequestAdapter,String> requestToSpanName)
requestToSpanName
allows you to dynamically name the HTTP client spans such that the name
reflects the operation, e.g. based on HTTP method or request path used.
tracer
- the tracerrequestToSpanName
- a function from request to span nameprotected HttpClientPropagator(Tracer tracer, PropagationCodec<String> propagationCodec, Function<HttpClientRequestAdapter,String> requestToSpanName)
public Span startPropagation(HttpClientRequestAdapter httpRequest)
httpRequest
- the adapted HTTP client requestpublic void endPropagation(HttpClientResponseAdapter httpResponse, Throwable error, Span span)
error
.
Closes the HTTP client call span.
The httpResponse
and the error
are both allowed to be null
.
httpResponse
- the adapted HTTP response, may be null
error
- an error that was thrown during the HTTP client call, may be null
span
- the span for the HTTP client callCopyright © 2019–2020 Honeycomb. All rights reserved.