sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

OpenTelemetry span names for URLs are shortened

Open adinauer opened this issue 7 months ago • 1 comments

Integration

sentry-opentelemetry-agent

Java Version

any

Version

8

Steps to Reproduce

Have an endpoint like /person/extra/long/path and send a request in.

Expected Result

A meaningful transaction name.

Actual Result

The transaction name is shortened to GET /**.

We are using the http.route span attribute which contains above value.

adinauer avatar May 22 '25 13:05 adinauer

When the URL has a corresponding route, then the http.route is populated with the correct value. When there is no corresponding route/mapping for a specific URL, then http.route will contain GET /**.

In our SpanDescriptionExtractor we prioritize http.route. Perhaps we could detect if http.route contains a * (or for stricter matching, if it matches exactly /**) and use url.path instead. This is not perfect because the server might be mapped only to a specific path (not necessarily the apex) and with url.path we would report the whole path in the URL.

On a related note, this happens also in Servlet instrumentation, where http.route contains the path that the servlet is mapped to. See this recent issue about it https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/13802.

In my opinion, this behavior of setting http.route to e.g. GET /** for servlets is not conforming to the OTEL spec, because it says "MUST NOT be populated when this is not supported by the HTTP server framework".

lcian avatar May 28 '25 08:05 lcian

If we consider the cardinality concern valid, then we should keep it as GET /**
If, instead, we think it's more valuable to have GET <full url> despite cardinality issues, then we could prioritize url.path when we detect that the url has been shortened.

lcian avatar Jul 07 '25 15:07 lcian

Closing this issue as not planned because:

  • we currently set the span name to {method} {http.route} which is in accordance to the OTEL convention
  • the only usecase I can think of for having the full URL as the span name is to perform filtering/aggregation based on that value, in which case it's possible to filter/aggregate on the url.path attribute instead

lcian avatar Aug 08 '25 12:08 lcian