Class HttpServerParser
- java.lang.Object
-
- brave.http.HttpParser
-
- brave.http.HttpServerParser
-
public class HttpServerParser extends HttpParser
Parses the request and response into reasonable defaults for http server spans. Subclass to customize, for example, to add tags based on user ID.
-
-
Constructor Summary
Constructors Constructor Description HttpServerParser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <Req> voidrequest(HttpAdapter<Req,?> adapter, Req req, brave.SpanCustomizer customizer)Customizes the span based on the request received from the client.<Resp> voidresponse(HttpAdapter<?,Resp> adapter, Resp res, java.lang.Throwable error, brave.SpanCustomizer customizer)Customizes the span based on the response sent to the client.-
Methods inherited from class brave.http.HttpParser
error, errorParser, spanName
-
-
-
-
Method Detail
-
request
public <Req> void request(HttpAdapter<Req,?> adapter, Req req, brave.SpanCustomizer customizer)
Customizes the span based on the request received from the client.Override to change what data from the http request are parsed into the span representing it. By default, this sets the span name to the http method and tags "http.method" and "http.path".
If you only want to change the span name, you can override
HttpParser.spanName(HttpAdapter, Object)instead.- Overrides:
requestin classHttpParser- See Also:
HttpParser.spanName(HttpAdapter, Object)
-
response
public <Resp> void response(HttpAdapter<?,Resp> adapter, @Nullable Resp res, @Nullable java.lang.Throwable error, brave.SpanCustomizer customizer)
Customizes the span based on the response sent to the client.Override to change what data from the http response or error are parsed into the span modeling it.
By default, this tags "http.status_code" when it is not 2xx. If there's an exception or the status code is neither 2xx nor 3xx, it tags "error". This also overrides the span name based on the
HttpAdapter.methodFromResponse(Object)andHttpAdapter.route(Object)where possible (ex "get /users/:userId").If routing is supported, and a GET didn't match due to 404, the span name will be "get not_found". If it didn't match due to redirect, the span name will be "get redirected". If routing is not supported, the span name is left alone.
If you only want to change how exceptions are parsed, override
HttpParser.error(Integer, Throwable, SpanCustomizer)instead.Note: Either the response or error parameters may be null, but not both.
- Overrides:
responsein classHttpParser- See Also:
HttpParser.error(Integer, Throwable, SpanCustomizer)
-
-