Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add "transaction" pointer on Span #552

Closed
wants to merge 2 commits into from

Conversation

tonyo
Copy link
Contributor

@tonyo tonyo commented Jan 27, 2023

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 on Span, that always points to the root span of the local span tree. For actual root spans, transaction is set to nil. With that attribute in place, we can also get rid of isTransaction flag.

Notes and Caveats

  1. A side-effect of removing isTransaction and introducing transaction is that naively created Spans will be transactions by default (since they'll have an empty transaction). We don't really promote or support this usecase anywhere (people should be using StartTransaction and StartSpan), but a thing to keep in mind.
  2. Alternatively, for transaction spans, transaction can store a pointer to itself, and not nil. A small downside is that it will be impossible to create a root level Span instance in one go: it'll be something like t := Span{..}; t.transaction = &t in tests or elsewhere.

@codecov
Copy link

codecov bot commented Jan 27, 2023

Codecov Report

Base: 76.46% // Head: 76.63% // Increases project coverage by +0.16% 🎉

Coverage data is based on head (f7a6643) compared to base (f39baef).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #552      +/-   ##
==========================================
+ Coverage   76.46%   76.63%   +0.16%     
==========================================
  Files          30       30              
  Lines        3387     3398      +11     
==========================================
+ Hits         2590     2604      +14     
+ Misses        699      697       -2     
+ Partials       98       97       -1     
Impacted Files Coverage Δ
tracing.go 88.28% <100.00%> (+0.29%) ⬆️
transport.go 79.21% <0.00%> (+0.84%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@tonyo
Copy link
Contributor Author

tonyo commented Jan 27, 2023

Ah, scratch that. Just realized we already have the root span info in spanRecorder. Let me think this over again.

@tonyo tonyo marked this pull request as draft January 27, 2023 13:02
@tonyo tonyo closed this Jan 30, 2023
@tonyo tonyo deleted the tonyo/span-transaction-ptr branch January 31, 2023 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant