confighttp: route-based span naming for ServeMux #12593
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Update confighttp.ServerConfig.ToServer to handle ServeMux specially: if the handler supplied to ToServer is an http.ServeMux, we use its Handler method to determine the matching pattern and use that to name the span as described at https://opentelemetry.io/docs/specs/semconv/http/http-spans/#name. If there is no matching pattern then we fall back to "unknown route".
This approach means that everything will magically just work for components that supply a ServeMux, but there are a couple of downsides:
The alternative that I started working on before I came to this solution was to introduce a new method, ServerConfig.ToServeMux, which would not accept an
http.Handler
, and would instead return a type that wraps*http.ServeMux
, and would instrument handlers as they are registered. With that approach the instrumentation would come after the routing, and we would install a default/
NotFoundHandler that is also instrumented. This approach is a bit less magical, and a bit more efficient, but would require all the components to be updated.Link to tracking issue
Fixes #12468 (for any receiver that uses a ServeMux, like otlpreceiver)
Testing
make run
with trace telemetry enabled, exporting to consoletelemetrygen logs --otlp-http
, confirmed that a span named "POST /v1/logs" is producedcurl http://localhost:4318
, confirmed that a span named "GET unknown route" is producedDocumentation
Added doc comment to confighttp.ServerConfig.ToServer explaining the new behaviour.