Skip to content

feat(core): Add configurable IScopesStorageFactory to SentryOptions#5199

Merged
adinauer merged 6 commits intomainfrom
feat/configurable-scopes-storage-factory
Mar 25, 2026
Merged

feat(core): Add configurable IScopesStorageFactory to SentryOptions#5199
adinauer merged 6 commits intomainfrom
feat/configurable-scopes-storage-factory

Conversation

@adinauer
Copy link
Member

📜 Description

Adds a new IScopesStorageFactory interface and a corresponding scopesStorageFactory option on SentryOptions. When set, the custom factory takes precedence over the default auto-detection logic in Sentry.initScopesStorage().

This allows users to provide a custom IScopesStorage implementation without reflection hacks, which is needed for frameworks where the default ThreadLocal-backed DefaultScopesStorage is incompatible (e.g. reactive/non-pinning thread models).

Changes:

  • New IScopesStorageFactory functional interface with a single create() method
  • SentryOptions.getScopesStorageFactory() / setScopesStorageFactory() (marked @Experimental)
  • Sentry.initScopesStorage() checks the custom factory first, then falls back to existing auto-detection

Fixes #5193

💡 Motivation and Context

Sentry.initScopesStorage() decides the storage implementation internally with no user-facing override. Users who need a custom IScopesStorage (e.g. backed by Vert.x context instead of ThreadLocal) had to use reflection to override the private static field.

💚 How did you test it?

  • Unit tests in SentryOptionsTest — default is null, getter/setter works, can reset to null
  • Unit tests in SentryTest — custom factory is invoked and init() called on the result, null factory falls back to default, custom storage is functional end-to-end

📝 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.

🔮 Next steps

  • Document how to use this for Quarkus/Vert.x reactive applications

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]>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (core) Add configurable IScopesStorageFactory to SentryOptions by adinauer in #5199
  • (replay) Add beforeErrorSampling callback to Session Replay by romtsn in #5214

Internal Changes 🔧

  • (deps) Update Native SDK to v0.13.3 by github-actions in #5215
  • (opentelemetry) Bump OpenTelemetry dependencies by adinauer in #5225

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 709a81c

@sentry
Copy link

sentry bot commented Mar 16, 2026

Sentry Build Distribution

App Name App ID Version Configuration Install Page
SDK Size io.sentry.tests.size 8.36.0 (1) release Install Build

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 340.42 ms 412.17 ms 71.76 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

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

Previous results on branch: feat/configurable-scopes-storage-factory

Startup times

Revision Plain With Sentry Diff
9572a97 314.00 ms 344.60 ms 30.60 ms

App size

Revision Plain With Sentry Diff
9572a97 0 B 0 B 0 B

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]>
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]>
Copy link
Collaborator

@lbloder lbloder left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@adinauer
Copy link
Member Author

@sentry review

@adinauer
Copy link
Member Author

cursor review

@adinauer adinauer marked this pull request as ready for review March 25, 2026 05:29
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@adinauer adinauer enabled auto-merge (squash) March 25, 2026 05:43
@adinauer adinauer merged commit ae6907d into main Mar 25, 2026
68 checks passed
@adinauer adinauer deleted the feat/configurable-scopes-storage-factory branch March 25, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a way to set IScopesStorage using SentryOptions

2 participants