fix(core): App start data lost when first transaction is unsampled#5756
Merged
fix(core): App start data lost when first transaction is unsampled#5756
Conversation
… app start When `tracesSampleRate < 1.0`, the first root span could be unsampled, permanently locking `firstStartedActiveRootSpanId` to a span that would never reach `processEvent`. This caused app start data to be lost for the entire session. Now we check `spanIsSampled()` before locking the ID, so app start attaches to the first sampled root span instead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog.
Plus 11 more 🤖 This preview updates automatically when you update the PR. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
|
q: what about users with sample rate near 0, aren't they going to lose the app start data anyway? |
Contributor
Author
Good point @lucas-zimerman 👍 |
Contributor
iOS (legacy) Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| ea3e26e+dirty | 1229.13 ms | 1228.46 ms | -0.67 ms |
| 80e4616+dirty | 1221.32 ms | 1225.64 ms | 4.32 ms |
| 818a608+dirty | 1205.76 ms | 1208.00 ms | 2.24 ms |
| 77061ed+dirty | 1233.16 ms | 1234.88 ms | 1.71 ms |
| bef3709+dirty | 1222.07 ms | 1220.24 ms | -1.83 ms |
| a206511+dirty | 1185.00 ms | 1186.35 ms | 1.35 ms |
| 74979ac+dirty | 1210.49 ms | 1213.31 ms | 2.82 ms |
| a2bb688+dirty | 1223.53 ms | 1232.90 ms | 9.37 ms |
| 8a868fe+dirty | 1221.50 ms | 1230.78 ms | 9.28 ms |
| d590428+dirty | 1211.77 ms | 1220.51 ms | 8.75 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| ea3e26e+dirty | 3.41 MiB | 4.58 MiB | 1.17 MiB |
| 80e4616+dirty | 3.38 MiB | 4.60 MiB | 1.22 MiB |
| 818a608+dirty | 2.63 MiB | 3.91 MiB | 1.28 MiB |
| 77061ed+dirty | 2.63 MiB | 3.98 MiB | 1.34 MiB |
| bef3709+dirty | 3.38 MiB | 4.78 MiB | 1.40 MiB |
| a206511+dirty | 3.41 MiB | 4.67 MiB | 1.25 MiB |
| 74979ac+dirty | 3.38 MiB | 4.60 MiB | 1.22 MiB |
| a2bb688+dirty | 2.63 MiB | 3.99 MiB | 1.36 MiB |
| 8a868fe+dirty | 3.38 MiB | 4.60 MiB | 1.22 MiB |
| d590428+dirty | 3.38 MiB | 4.78 MiB | 1.39 MiB |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📢 Type of change
📜 Description
When
tracesSampleRate < 1.0, theappStartIntegrationlocksfirstStartedActiveRootSpanIdto the first root span regardless of whether it is sampled. SinceprocessEventonly runs for sampled events, if the first root span is unsampled, app start data is permanently lost for that session — subsequent sampled transactions fail the span ID match check.This PR adds a
spanIsSampled()guard inrecordFirstStartedActiveRootSpanIdso the ID only locks to the first sampled root span. The existing age/duration guards still protect against stale app starts.💡 Motivation and Context
Users with
tracesSampleRate < 1.0were losing Cold/Warm Start data whenever the first transaction happened to be unsampled (which is statistically likely at low sample rates). This is a data loss bug — the app start is measured by the native layer but never attached to any event.Fixes #5757
💚 How did you test it?
SentryNonRecordingSpan(unsampled) followed by a real sampled span, verifies app start attaches to the sampled transactionyarn test,yarn build,yarn lint)📝 Checklist
sendDefaultPIIis enabled🔮 Next steps
🤖 Generated with Claude Code