feat: Add "transaction" pointer on Span #552
Closed
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.
A proposal that we haven't really discussed in details, but was straightforward to implement to showcase. Needed for OTel work (#537).
Problem
Spans know whether they are transactions (e.g. root spans) thanks to
isTransaction
flag, but there's no nice way to actually "reach" the transaction from a child span. It is needed, for instance, to get a dynamic sampling context for a nested span, in case we want to propagate it to other services.Proposal
Introduce
transaction
(name tentative) attribute onSpan
, that always points to the root span of the local span tree. For actual root spans,transaction
is set tonil
. With that attribute in place, we can also get rid ofisTransaction
flag.Notes and Caveats
isTransaction
and introducingtransaction
is that naively created Spans will be transactions by default (since they'll have an emptytransaction
). We don't really promote or support this usecase anywhere (people should be usingStartTransaction
andStartSpan
), but a thing to keep in mind.transaction
can store a pointer to itself, and notnil
. A small downside is that it will be impossible to create a root levelSpan
instance in one go: it'll be something liket := Span{..}; t.transaction = &t
in tests or elsewhere.