feat(core): Add configurable IScopesStorageFactory to SentryOptions#5199
Merged
feat(core): Add configurable IScopesStorageFactory to SentryOptions#5199
Conversation
Allow users to provide a custom IScopesStorage factory via SentryOptions.setScopesStorageFactory(). When set, the custom factory takes precedence over the default auto-detection logic. Fixes #5193 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Contributor
|
Sentry Build Distribution
|
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| abfcc92 | 304.04 ms | 370.33 ms | 66.29 ms |
| 3699cd5 | 423.60 ms | 495.52 ms | 71.92 ms |
| b3d8889 | 371.33 ms | 426.24 ms | 54.92 ms |
| 55aaf9b | 336.43 ms | 364.14 ms | 27.71 ms |
| 6727e14 | 337.22 ms | 373.94 ms | 36.71 ms |
| f634d01 | 359.58 ms | 433.88 ms | 74.30 ms |
| ee747ae | 374.71 ms | 455.18 ms | 80.47 ms |
| bbc35bb | 324.88 ms | 425.73 ms | 100.85 ms |
| f064536 | 327.04 ms | 405.35 ms | 78.31 ms |
| ee747ae | 400.46 ms | 423.61 ms | 23.15 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| abfcc92 | 1.58 MiB | 2.13 MiB | 557.31 KiB |
| 3699cd5 | 1.58 MiB | 2.10 MiB | 533.45 KiB |
| b3d8889 | 1.58 MiB | 2.10 MiB | 535.07 KiB |
| 55aaf9b | 0 B | 0 B | 0 B |
| 6727e14 | 1.58 MiB | 2.28 MiB | 718.64 KiB |
| f634d01 | 1.58 MiB | 2.10 MiB | 533.40 KiB |
| ee747ae | 1.58 MiB | 2.10 MiB | 530.95 KiB |
| bbc35bb | 1.58 MiB | 2.12 MiB | 553.01 KiB |
| f064536 | 1.58 MiB | 2.20 MiB | 633.90 KiB |
| ee747ae | 1.58 MiB | 2.10 MiB | 530.95 KiB |
Add LoadClass and ILogger parameters to IScopesStorageFactory.create() so custom factories have access to class loading utilities. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
adinauer
commented
Mar 16, 2026
…Factory" This reverts commit a0d77eb.
adinauer
commented
Mar 16, 2026
adinauer
commented
Mar 16, 2026
SPI-discovered factory implementations are instantiated via ServiceLoader with no-arg constructors, so they need access to options like logger and DSN at creation time. Change the interface method signature to accept SentryOptions as a parameter. Co-Authored-By: Claude <[email protected]>
Member
Author
|
@sentry review |
Member
Author
|
cursor review |
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.
📜 Description
Adds a new
IScopesStorageFactoryinterface and a correspondingscopesStorageFactoryoption onSentryOptions. When set, the custom factory takes precedence over the default auto-detection logic inSentry.initScopesStorage().This allows users to provide a custom
IScopesStorageimplementation without reflection hacks, which is needed for frameworks where the defaultThreadLocal-backedDefaultScopesStorageis incompatible (e.g. reactive/non-pinning thread models).Changes:
IScopesStorageFactoryfunctional interface with a singlecreate()methodSentryOptions.getScopesStorageFactory()/setScopesStorageFactory()(marked@Experimental)Sentry.initScopesStorage()checks the custom factory first, then falls back to existing auto-detectionFixes #5193
💡 Motivation and Context
Sentry.initScopesStorage()decides the storage implementation internally with no user-facing override. Users who need a customIScopesStorage(e.g. backed by Vert.x context instead ofThreadLocal) had to use reflection to override the private static field.💚 How did you test it?
SentryOptionsTest— default is null, getter/setter works, can reset to nullSentryTest— custom factory is invoked andinit()called on the result, null factory falls back to default, custom storage is functional end-to-end📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps