Skip to content

Commit

Permalink
Make otel spans for RR clients more spec compliant
Browse files Browse the repository at this point in the history
The OpenTelementry [Spec](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.10.0/specification/trace/semantic_conventions/http.md#name) is pretty clear about not using the URI as the default span name due to its high cardinality.

> Instrumentation MUST NOT default to using URI path as span name…

This PR creates span names that always include `HTTP` and then if available the method (e.g. `GET`) and if the route template is available then that is appended too.
  • Loading branch information
kdubb committed Jul 13, 2022
1 parent f547d57 commit 2f50b08
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,19 @@ public void set(final ClientRequestContext carrier, final String key, final Stri
private static class ClientSpanNameExtractor implements SpanNameExtractor<ClientRequestContext> {
@Override
public String extract(final ClientRequestContext request) {
String pathTemplate = (String) request.getProperty("UrlPathTemplate");
if (pathTemplate != null && pathTemplate.length() > 1) {
return pathTemplate;
StringBuilder name = new StringBuilder("HTTP");

String method = request.getMethod();
if (method != null && method.length() > 1) {
name.append(" ").append(method);
}

String uriPath = request.getUri().getPath();
if (uriPath != null && uriPath.length() > 1) {
return uriPath;
String pathTemplate = (String) request.getProperty("UrlPathTemplate");
if (pathTemplate != null && pathTemplate.length() > 1) {
name.append(" ").append(pathTemplate);
}

return "HTTP " + request.getMethod();
return name.toString();
}
}

Expand Down

0 comments on commit 2f50b08

Please sign in to comment.