Skip to content

fix(tracing): Sync the JS trace to the native SDKs after they start - #7107

Merged
antonis merged 2 commits into
getsentry:mainfrom
RasmusKard:6961-sync-initial-trace-to-native
Nov 25, 2026
Merged

antonis merged 2 commits into
getsentry:mainfrom
RasmusKard:6961-sync-initial-trace-to-native

Conversation

@RasmusKard

@RasmusKard RasmusKard commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Native kept its own random trace until the first idle span synced, so native errors and crashes didn't share the JS trace:

  • Apps without tracing never start an idle span, so it never synced
  • Apps started in the background (or inactive on iOS), since startIdleSpan returns early
  • An idle span that synced before initNativeSdk finished was lost, because the native start replaces the scope

Now the client also syncs after native init: the active span, or the scope's propagation context when there is none.

💡 Motivation and Context

I tried sentry-cocoa's webViewTracing (getsentry/sentry-cocoa#9538) on iOS instead of sentryWebViewProps, and WebView pages got native's random trace instead of the app's. This was the root cause.

Follow-up to #6686 and #6720, which only sync from startIdleSpan.

💚 How did you test it?

  • Jest: the new tests fail if the sync runs before native init, ignores the active span, or sends sampled: undefined
  • Android emulator and iOS simulator, with and without useNativeInit: before the fix native had a different trace than JS, after it they matched
  • A trace synced right before initNativeSdk was lost before the fix and kept after (Android in both setups, iOS with useNativeInit)

📝 Checklist

  • I added tests to verify 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.
  • All tests passing.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.
  • No breaking changes.

🔮 Next steps

@antonis antonis added the ready-to-merge Triggers the full CI test suite label Nov 25, 2026

@antonis antonis 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.

Thank you for your contribution @RasmusKard 🙇

The code changes look good and the sample app worked as expected for me with the fix (internal Sentry link) 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Triggers the full CI test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants