Skip to content

fix(compose): Ensure SentryTraced spans respect ignore-by-origin requests - #6058

Merged
0xadam-brown merged 1 commit into
mainfrom
fix/sentry-traced-origin-filtering-bug
Sep 8, 2026
Merged

fix(compose): Ensure SentryTraced spans respect ignore-by-origin requests#6058
0xadam-brown merged 1 commit into
mainfrom
fix/sentry-traced-origin-filtering-bug

Conversation

@0xadam-brown

Copy link
Copy Markdown
Member

📜 Description

Fixes a bug where we set span origins for SentryTraced after their creation via the span context, resulting in our ignore-span-origins logic not being able to see them and spans being produced when they should have been ignored / suppressed.

💡 Motivation and Context

This issue has been with us for a while, but was discovered (along with a number of others) in connection with my Nav3 work.

The general rule is that we need to set span origins during creation and not afterwards via span context or else checks list ignoreSpanOrigins will be ignored.

What went wrong?

SentryTracer checks ignoredSpanOrigins during span creation, before the returned span can be mutated:

if (SpanUtils.isIgnored(scopes.getOptions().getIgnoredSpanOrigins(), spanOptions.getOrigin())) {
  return NoOpSpan.getInstance();
}

That check reads SpanOptions.origin, not the SpanContext.origin we were setting after creation.

So if a host app did this...

options.setIgnoredSpanOrigins(listOf("auto.ui.jetpack_compose"))

...it would no-op and the Compose spans were created nonetheless.

The issue affected both levels of the SentryTraced span hierarchy (ie, both parent spans and child spans).

💚 How did you test it?

Unit regression test + I had my clanker verify the fix works and is correct via our Android sample apps.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

@0xadam-brown
0xadam-brown force-pushed the fix/sentry-traced-origin-filtering-bug branch 2 times, most recently from a8aeb7e to 7b13e55 Compare September 5, 2026 13:36
@0xadam-brown
0xadam-brown marked this pull request as ready for review September 5, 2026 13:39
@sentry

sentry Bot commented Sep 5, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.55.0 (1) release

⚙️ sentry-android Build Distribution Settings

@0xadam-brown 0xadam-brown changed the title fix(compose): Honor ignored origins in SentryTraced spans fix(compose): Honor ignored origins for SentryTraced spans Sep 5, 2026
@0xadam-brown 0xadam-brown added the sanity-check PR needs a lightweight review for obvious issues label Sep 7, 2026

@runningcode runningcode left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is quite a subtle bug! :O Is there a way of changing the API to make it impossible to do it the wrong way? Or throwing an exception when doing this the wrong way?

Base automatically changed from fix/sentry-traced-stale-parent to main September 8, 2026 07:42
Fix a bug where we set span origins for SentryTraced after their creation via the span context, resulting in our ignore-span-origins logic not being able to see them and spans being produced when they should have been ignored / suppressed.

What was happening?

SentryTracer checks `ignoredSpanOrigins` during span creation, before the returned span can be mutated:

```java
if (SpanUtils.isIgnored(scopes.getOptions().getIgnoredSpanOrigins(), spanOptions.getOrigin())) {
  return NoOpSpan.getInstance();
}
```

That check reads SpanOptions.origin, not the SpanContext.origin we were setting after creation.

So if a host app did this...

```kotlin
options.setIgnoredSpanOrigins(listOf("auto.ui.jetpack_compose"))
```

...it would no-op and the Compose spans were created nonetheless.

The issue affected both levels of the SentryTraced span hierarchy (ie, both parent spans and child spans).
@0xadam-brown
0xadam-brown force-pushed the fix/sentry-traced-origin-filtering-bug branch from 7b13e55 to fcdad89 Compare September 8, 2026 07:52
@0xadam-brown

Copy link
Copy Markdown
Member Author

Rebased on an updated target + fixed minor merge conflicts; otherwise unchanged.

@0xadam-brown

Copy link
Copy Markdown
Member Author

This is quite a subtle bug! :O Is there a way of changing the API to make it impossible to do it the wrong way? Or throwing an exception when doing this the wrong way?

That's indeed the question. I also ran into a similar issue w/r/t setting the start timestamp for spans in another SentryTraced PRs. I think a deep dive into our ISpan API and the constraints driving its behavior could be worthwhile at some point...

@0xadam-brown
0xadam-brown enabled auto-merge (squash) September 8, 2026 07:56
@0xadam-brown 0xadam-brown changed the title fix(compose): Honor ignored origins for SentryTraced spans fix(compose): Ensure SentryTraced spans respect ignore-by-origin requests Sep 8, 2026
@0xadam-brown
0xadam-brown enabled auto-merge (squash) September 8, 2026 07:58
@0xadam-brown
0xadam-brown enabled auto-merge (squash) September 8, 2026 10:11
@0xadam-brown
0xadam-brown merged commit 8400a7f into main Sep 8, 2026
70 checks passed
@0xadam-brown
0xadam-brown deleted the fix/sentry-traced-origin-filtering-bug branch September 8, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sanity-check PR needs a lightweight review for obvious issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants