Repository navigation
Conversation
Validate thread-local scopes using their SDK initialization root instead of walking the parent chain. This keeps stale-scope detection independent from ancestry and makes the check constant time. Refs #6248 Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced Nov 17, 2026
📲 Install BuildsAndroid
|
Keep SDK initialization identity independent from any Scopes instance. Descendants now retain only a small shared token rather than the initialization root. Refs #6248 Co-Authored-By: Claude <noreply@anthropic.com>
Use reference equality for the opaque token shared by scopes created from the same SDK initialization.
This branch has not been deployed
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.
PR Stack (Scope Parent Retention)
📜 Description
Assign an opaque token to each SDK initialization and expose an explicit initialization identity check. Root scopes create the token, forks inherit it, and
Sentry.getCurrentScopes()validates thread-local scopes by token identity instead of walking their parent chain.This PR intentionally keeps parent references strong and preserves the existing scope ancestry behavior. Weak parent retention is introduced separately in the next stack PR.
Benchmark
A focused JMH benchmark compared the previous ancestry-based check with initialization-token identity across different parent-chain depths:
Both checks effectively allocate 0 B/op. The previous check is O(depth), while initialization-token identity remains O(1). The benchmark mirrors the relevant method logic on desktop JDK 21 and does not measure scope-fork construction or Android runtime behavior.
💡 Motivation and Context
SDK initialization identity must remain valid independently of the parent chain without retaining a root
Scopesinstance. Separating the check from ancestry prepares scopes for collectible parents while also avoiding recursive traversal for stale-scope validation.Refs #6248
💚 How did you test it?
make format api./gradlew :sentry:test --tests='io.sentry.ScopesTest' --tests='io.sentry.SentryTest'📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
The next PR changes immediate parent references to weak references and adds retention regressions across core, Spring, and OpenTelemetry.
#skip-changelog