Skip to content

chore(contexts): Remove default-trace-ID option#5979

Open
thetruecpaul wants to merge 1 commit into
masterfrom
cpaul/051126/ship-default-trace-id
Open

chore(contexts): Remove default-trace-ID option#5979
thetruecpaul wants to merge 1 commit into
masterfrom
cpaul/051126/ship-default-trace-id

Conversation

@thetruecpaul
Copy link
Copy Markdown
Contributor

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

@thetruecpaul thetruecpaul requested a review from a team May 11, 2026 22:08
@thetruecpaul thetruecpaul requested a review from a team as a code owner May 11, 2026 22:08
@thetruecpaul thetruecpaul force-pushed the cpaul/051126/ship-default-trace-id branch from 04f1690 to a55366d Compare May 11, 2026 22:12
// If the event lacks a TraceContext, add a random one.

if config.derive_trace_id && !contexts.contains::<TraceContext>() {
if !contexts.contains::<TraceContext>() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

@Dav1dde Dav1dde left a comment

Choose a reason for hiding this comment

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

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>() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread CHANGELOG.md Outdated
- 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))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
- 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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. :-)

@thetruecpaul thetruecpaul force-pushed the cpaul/051126/ship-default-trace-id branch 2 times, most recently from 274748d to 4654bdc Compare May 12, 2026 17:50
Comment thread relay-event-normalization/src/event.rs
@thetruecpaul thetruecpaul force-pushed the cpaul/051126/ship-default-trace-id branch from 4654bdc to de252d4 Compare May 12, 2026 19:38
Comment thread relay-event-normalization/src/event.rs Outdated
Comment thread relay-event-normalization/src/event.rs Outdated
Comment thread relay-event-normalization/src/event.rs Outdated
Comment on lines +1371 to +1377
if !contexts.contains::<TraceContext>()
|| contexts
.get_or_default::<TraceContext>()
.trace_id
.0
.is_none()
{
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See changes

.0
.is_none()
{
contexts.add(TraceContext::random(event_id))
Copy link
Copy Markdown
Member

@shashjar shashjar May 12, 2026

Choose a reason for hiding this comment

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

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

Comment thread relay-event-normalization/src/event.rs Outdated
// If the event lacks a TraceContext, add a random one.

if config.derive_trace_id && !contexts.contains::<TraceContext>() {
if !contexts.contains::<TraceContext>()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we add unit tests for this logic somewhere?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updating the tests is what I'm working on now! :-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@thetruecpaul thetruecpaul force-pushed the cpaul/051126/ship-default-trace-id branch from de252d4 to 9942b0b Compare May 12, 2026 23:27
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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())
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Fix in Cursor Fix in Web

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>() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can unify the branches with let trace_ctx = contexts.get_or_default::<TraceContext>()

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.

3 participants