chore(contexts): Remove default-trace-ID option#5979
Conversation
04f1690 to
a55366d
Compare
| // If the event lacks a TraceContext, add a random one. | ||
|
|
||
| if config.derive_trace_id && !contexts.contains::<TraceContext>() { | ||
| if !contexts.contains::<TraceContext>() { |
There was a problem hiding this comment.
raised discussion about this in Slack: https://sentry.slack.com/archives/C09QBCVRCAU/p1778539337468769
There was a problem hiding this comment.
That's a good catch, also replied to it on Slack.
tldr; the SchemaProcessor will remove the TraceContext if the trace_id is missing. To not be order dependent, you probably always want to create the context and insert a trace id if it is missing.
As an example: If an SDK sends an invalid trace id, it may be empty, but with metadata attached that there was an invalid trace id.
This comes back to a previous discussion, where it would be better if the downstream consumers gracefully handle missing trace ids.
Dav1dde
left a comment
There was a problem hiding this comment.
Thanks, for coming back and cleaning this up.
You accidentally updated/reverted the submodules, sentry-conventions and sentry-native. You might be missing a git submodule update --recursive --init.
| // If the event lacks a TraceContext, add a random one. | ||
|
|
||
| if config.derive_trace_id && !contexts.contains::<TraceContext>() { | ||
| if !contexts.contains::<TraceContext>() { |
There was a problem hiding this comment.
That's a good catch, also replied to it on Slack.
tldr; the SchemaProcessor will remove the TraceContext if the trace_id is missing. To not be order dependent, you probably always want to create the context and insert a trace id if it is missing.
As an example: If an SDK sends an invalid trace id, it may be empty, but with metadata attached that there was an invalid trace id.
This comes back to a previous discussion, where it would be better if the downstream consumers gracefully handle missing trace ids.
| - Bump `sentry-conventions` to 0.6.0-4. ([#5944](https://github.com/getsentry/relay/pull/5944)) | ||
| - Enable compression for forwarded uploads. ([#5965](https://github.com/getsentry/relay/pull/5965)) | ||
| - Change the default partitioning for the envelope buffer from semantic to round-robin. ([#5967](https://github.com/getsentry/relay/pull/5967)) | ||
| - Remove option gating default-trace-ID behavior. ([#5979](https://github.com/getsentry/relay/pull/5979)) |
There was a problem hiding this comment.
| - Remove option gating default-trace-ID behavior. ([#5979](https://github.com/getsentry/relay/pull/5979)) | |
| - Unconditionally create a trace context with a trace id for errors. ([#5979](https://github.com/getsentry/relay/pull/5979)) |
I'd phrase it more to what effect the change has on users/downstream consumers.
There was a problem hiding this comment.
I chose to focus on the removal of the option, rather than the trace context / trace ID, because the option has already been launched to 100% — so there should be no effect on users/downstream consumers.
That said, this is your repo — I'll defer to your suggestion. :-)
274748d to
4654bdc
Compare
4654bdc to
de252d4
Compare
| if !contexts.contains::<TraceContext>() | ||
| || contexts | ||
| .get_or_default::<TraceContext>() | ||
| .trace_id | ||
| .0 | ||
| .is_none() | ||
| { |
| .0 | ||
| .is_none() | ||
| { | ||
| contexts.add(TraceContext::random(event_id)) |
There was a problem hiding this comment.
If there's a TraceContext with valid information but it's missing trace_id (not sure if this actually occurs in practice) - I think we'll end up overriding the entire context with a new one that has only trace_id? I think we want to get_or_default the trace context, then check whether trace_context.trace_id is null, and then set only trace_context.trace_id if so
| // If the event lacks a TraceContext, add a random one. | ||
|
|
||
| if config.derive_trace_id && !contexts.contains::<TraceContext>() { | ||
| if !contexts.contains::<TraceContext>() |
There was a problem hiding this comment.
Can we add unit tests for this logic somewhere?
There was a problem hiding this comment.
Updating the tests is what I'm working on now! :-)
There was a problem hiding this comment.
Just a drive by comment before bed, an integration test (if it doesn't already exist) would be great, we do have a decent framework for them and they work great for regression tests.
de252d4 to
9942b0b
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9942b0b. Configure here.
| let trace_ctx = contexts.get_or_default::<TraceContext>(); | ||
| if trace_ctx.trace_id.0.is_none() { | ||
| trace_ctx.trace_id = Annotated::new(TraceId::random()) | ||
| } |
There was a problem hiding this comment.
Inconsistent trace ID derivation between if/else branches
Medium Severity
When no TraceContext exists, TraceContext::random(event_id) derives the trace ID deterministically from the event_id (using TraceId::from(event_id)) and attaches a trace_id.missing remark. But when a TraceContext exists with a missing trace_id, the else branch uses TraceId::random() which generates a truly random UUID via Uuid::new_v4() and attaches no remark. This means the trace ID strategy differs depending on whether an SDK sent an empty TraceContext or none at all, and the provenance metadata is lost in the else case.
Reviewed by Cursor Bugbot for commit 9942b0b. Configure here.
| // If the event lacks a TraceContext, add a random one. | ||
|
|
||
| if config.derive_trace_id && !contexts.contains::<TraceContext>() { | ||
| if !contexts.contains::<TraceContext>() { |
There was a problem hiding this comment.
You can unify the branches with let trace_ctx = contexts.get_or_default::<TraceContext>()


Shipped this a week ago and have seen no problems. 👍