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

Fix applying the trace context on events #888

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,15 @@
}

for key, value := range scope.contexts {
if key == "trace" && event.Type == transactionType {
// Do not override trace context of
// transactions, otherwise it breaks the
// transaction event representation.
// For error events, the trace context is used
// to link errors and traces/spans in Sentry.
continue

Check warning on line 392 in scope.go

View check run for this annotation

Codecov / codecov/patch

scope.go#L392

Added line #L392 was not covered by tests
}

// Ensure we are not overwriting event fields
if _, ok := event.Contexts[key]; !ok {
event.Contexts[key] = cloneContext(value)
Expand All @@ -395,7 +404,9 @@
}

if scope.span != nil {
event.Contexts["trace"] = scope.span.traceContext().Map()
if _, ok := event.Contexts["trace"]; !ok {
event.Contexts["trace"] = scope.span.traceContext().Map()
}

transaction := scope.span.GetTransaction()
if transaction != nil {
Expand Down
3 changes: 2 additions & 1 deletion tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,11 @@ func (s *Span) toEvent() *Event {
s.dynamicSamplingContext = DynamicSamplingContextFromTransaction(s)
}

contexts := make(map[string]Context, len(s.contexts))
contexts := make(map[string]Context, len(s.contexts)+1)
for k, v := range s.contexts {
contexts[k] = cloneContext(v)
}
contexts["trace"] = s.traceContext().Map()

// Make sure that the transaction source is valid
transactionSource := s.Source
Expand Down
Loading