Allow mutation of span operation name
slashmo opened this issue · 0 comments
We might want to consider offering an API to rename an already started span. This is part of the OTel spec but comes with a disadvantage for sampling.
Use-Case: HTTP Server
HTTP servers might want to rename a span after creation, because they can come up with a more relevant span in the meantime.
- Immediately start span when receiving a request (
operationName
=request.head.uri
) - Route request
2.1. Route Not Found --> Record error
2.2 Route Found --> Rename to route (/users/1
becomes/users/:userID
) - End span
This approach has one disadvantage. In a typical tracer with head-first sampling, sampling decisions based on the operationName
of a span will potentially not be accurate as the sampler won't be invoked after the rename.
Alternatives: Start spans after the fact
As mentioned in OTel Spec: Span.UpdateName
an alternative to renaming an already started span would be to record the timestamp whenever the span should have been started, and then passing that timestamp to the startSpan
call.
- Get current timestamp
- Route request
2.1. Route Not Found --> Start span at previous timestamp (operationName
=request.head.uri
) --> Record error
2.2 Route Found --> Start span at previous timestamp (operationName
=/users/:userID
) - End span