/** * Customizes the span based on the request received from the client. * * <p>{@inheritDoc} */ @Override public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) { super.request(adapter, req, customizer); }
if (res != null) { statusCode = adapter.statusCodeAsInt(res); String nameFromRoute = spanNameFromRoute(adapter, res, statusCode); if (nameFromRoute != null) customizer.name(nameFromRoute); String maybeStatus = maybeStatusAsString(statusCode, 299); if (maybeStatus != null) customizer.tag("http.status_code", maybeStatus); error(statusCode, error, customizer);
/** * Override to change what data from the http error are parsed into the span modeling it. By * default, this tags "error" as the exception or the status code if it is neither 2xx nor 3xx. * * <p>Note: Either the httpStatus or error parameters may be null, but not both * * <p>Conventionally associated with the tag key "error" */ // BRAVE6: httpStatus is a Integer, not a int. We can't change this api as users expect this to be // called by default. Unfortunately, this implies boxing until we can change it. protected void error(@Nullable Integer httpStatus, @Nullable Throwable error, SpanCustomizer customizer) { if (error != null) { errorParser().error(error, customizer); } else if (httpStatus != null) { String maybeErrorStatus = maybeStatusAsString(httpStatus, 399); if (maybeErrorStatus != null) customizer.tag("error", maybeErrorStatus); } }
/** * Customizes the span based on the response received from the server. * * <p>{@inheritDoc} */ @Override public <Resp> void response(HttpAdapter<?, Resp> adapter, @Nullable Resp res, @Nullable Throwable error, SpanCustomizer customizer) { super.response(adapter, res, error, customizer); } }
/** * 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". * * <p>If you only want to change the span name, you can override {@link #spanName(HttpAdapter, * Object)} instead. * * @see #spanName(HttpAdapter, Object) */ // Eventhough the default span name is the method, we have no way of knowing that a user hasn't // overwritten the name to something else. If that occurs during response parsing, it is too late // to go back and get the http method. Adding http method by default ensures span naming doesn't // prevent basic HTTP info from being visible. A cost of this is another tag, but it is small with // very limited cardinality. Moreover, users who care strictly about size can override this. public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) { customizer.name(spanName(adapter, req)); String method = adapter.method(req); if (method != null) customizer.tag("http.method", method); String path = adapter.path(req); if (path != null) customizer.tag("http.path", path); }
/** * Customizes the span based on the response sent to the client. * * <p>{@inheritDoc} */ @Override public <Resp> void response(HttpAdapter<?, Resp> adapter, @Nullable Resp res, @Nullable Throwable error, SpanCustomizer customizer) { super.response(adapter, res, error, customizer); } }
/** * Customizes the span based on the request that will be sent to the server. * * <p>{@inheritDoc} */ @Override public <Req> void request(HttpAdapter<Req, ?> adapter, Req req, SpanCustomizer customizer) { super.request(adapter, req, customizer); }
void handleFinish(@Nullable Resp response, @Nullable Throwable error, Span span) { if (span.isNoop()) return; try { Scope ws = currentTraceContext.maybeScope(span.context()); try { parser.response(adapter, response, error, span.customizer()); } finally { ws.close(); // close the scope before finishing the span } } finally { finishInNullScope(span); } }
@Override void parseRequest(Req request, Span span) { span.kind(Span.Kind.SERVER); adapter.parseClientIpAndPort(request, span); parser.request(adapter, request, span.customizer()); }
@Override void parseRequest(Req request, Span span) { span.kind(Span.Kind.CLIENT); if (serverName != null) span.remoteServiceName(serverName); parser.request(adapter, request, span.customizer()); }