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(tracing): Introduce span.SetContext #599

Merged
merged 2 commits into from Mar 14, 2023
Merged

feat(tracing): Introduce span.SetContext #599

merged 2 commits into from Mar 14, 2023

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Mar 8, 2023

ref #596

This PR adds the SetContext struct method to the span struct.

This allows us to remove the usage of setting context on the scope in the OpenTelemetry span processor

@AbhiPrasad AbhiPrasad requested a review from cleptric March 8, 2023 16:40
@codecov
Copy link

codecov bot commented Mar 8, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.04 🎉

Comparison is base (1ffabde) 78.88% compared to head (cb8f9a0) 78.93%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #599      +/-   ##
==========================================
+ Coverage   78.88%   78.93%   +0.04%     
==========================================
  Files          38       38              
  Lines        3860     3869       +9     
==========================================
+ Hits         3045     3054       +9     
  Misses        712      712              
  Partials      103      103              
Impacted Files Coverage Δ
otel/span_processor.go 91.81% <100.00%> (ø)
tracing.go 88.14% <100.00%> (+0.23%) ⬆️

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.

Copy link
Member

@cleptric cleptric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments. We need to find a solution for https://github.com/getsentry/sentry-go/blob/master/otel/span_processor.go#L148 as well, as the initial issue with not having any otel context being present will persist.

@@ -236,6 +241,10 @@ func (s *Span) SetData(name, value string) {
s.Data[name] = value
}

func (s *Span) SetContext(key string, value Context) {
s.contexts[key] = value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// span context, can only be set on transactions

Should we guard against this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but decided against this for now since this field is a) private and b) only used when calling .toEvent().

for k, v := range s.contexts {
contexts[k] = v
}
contexts["trace"] = s.traceContext().Map()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might overwrite the trace key, is this a concern?

Copy link
Member Author

@AbhiPrasad AbhiPrasad Mar 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, we want to make sure the trace key is always being set by the transaction itself, and not overwritten by setContext.

@@ -484,17 +493,21 @@ func (s *Span) toEvent() *Event {
s.dynamicSamplingContext = DynamicSamplingContextFromTransaction(s)
}

contexts := map[string]Context{}
for k, v := range s.contexts {
contexts[k] = v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth adding a test here as well.

@AbhiPrasad AbhiPrasad self-assigned this Mar 8, 2023
@cleptric
Copy link
Member

cleptric commented Mar 8, 2023

Might be worth adding a new field to Span which includes the transaction name.

@AbhiPrasad
Copy link
Member Author

Might be worth adding a new field to Span which includes the transaction name.

Let's do this in a follow up PR?

@AbhiPrasad AbhiPrasad marked this pull request as ready for review March 9, 2023 12:46
@smeubank smeubank linked an issue Mar 10, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OTel Context Missing
2 participants