public class HttpServerPropagator extends Object
Example instrumentation for synchronous server code:
HttpServerRequestAdapter adaptedHttpRequest = new HttpServerRequestAdapter(actualHttpRequest);
HttpServerResponseAdapter adaptedHttpResponse = null;
Throwable error = null;
Span span = serverPropagator.startPropagation(adaptedHttpRequest);
try {
actualHttpResponse = doServerWork(actualHttpRequest);
adaptedHttpResponse = new HttpServerResponseAdapter(actualHttpResponse);
} catch (Exception ex) {
error = ex;
throw ex;
} finally {
serverPropagator.endPropagation(adaptedHttpResponse, error, span);
}
The API is based on Brave's HTTP utilities under brave.http
.
Modifier and Type | Field | Description |
---|---|---|
static String |
OPERATION_TYPE_HTTP_SERVER |
Modifier | Constructor | Description |
---|---|---|
|
HttpServerPropagator(Beeline beeline,
String serviceName,
Function<HttpServerRequestAdapter,String> requestToSpanName) |
Create an HttpServerPropagator for tracing requests received by an HTTP server.
|
protected |
HttpServerPropagator(String serviceName,
Function<HttpServerRequestAdapter,String> requestToSpanName,
HttpServerRequestSpanCustomizer spanCustomizer,
PropagationCodec<String> propagationCodec,
Beeline beeline) |
Modifier and Type | Method | Description |
---|---|---|
void |
endPropagation(HttpServerResponseAdapter httpResponse,
Throwable error,
Span span) |
Adds standard span fields based on data in the HTTP response or the
error . |
Span |
startPropagation(HttpServerRequestAdapter httpRequest) |
Creates a root span for this HTTP server call and adds the standardized fields to it.
|
public static final String OPERATION_TYPE_HTTP_SERVER
public HttpServerPropagator(Beeline beeline, String serviceName, Function<HttpServerRequestAdapter,String> requestToSpanName)
requestToSpanName
allows you to dynamically name the HTTP server span such that the name
reflects the operation, e.g. based on HTTP method or request path used.
beeline
- the beelineserviceName
- the service namerequestToSpanName
- a function from an HTTP request to a span nameprotected HttpServerPropagator(String serviceName, Function<HttpServerRequestAdapter,String> requestToSpanName, HttpServerRequestSpanCustomizer spanCustomizer, PropagationCodec<String> propagationCodec, Beeline beeline)
public Span startPropagation(HttpServerRequestAdapter httpRequest)
httpRequest
- the adapted HTTP requestpublic void endPropagation(HttpServerResponseAdapter httpResponse, Throwable error, Span span)
error
.
Closes the HTTP server 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 when the HTTP server was processing the HTTP request, may be null
span
- the span for the HTTP server callCopyright © 2019–2020 Honeycomb. All rights reserved.