Repository navigation
ref(core): Add SentryRuntime for the SDK's own collaborators - #6830
runningcode wants to merge 1 commit into
Conversation
SentryRuntime holds the collaborators the SDK owns rather than the customer (serializer, executor, envelope disk cache). Sentry.init builds it once, through LegacyOptionsBridge, from what is on SentryOptions and copies it back, so existing readers see the same instances. Nothing reads from it yet; follow-up PRs move the readers to constructor injection before the SentryOptions accessors get deprecated. Part of JAVA-817 Co-Authored-By: Claude Opus 5.5 <[email protected]>
🚨 Detected changes in high risk code 🚨High-risk code has higher potential to break the SDK and may be hard to test. To prevent severe bugs, apply the rollout process for releasing such changes and be extra careful when changing and reviewing these files:
|
PR risk: mediumFor commit Main concerns: reach, public contract, host performance. Rules that block low also fired:
This label is a hint for reviewers, not an approval. |
📲 Install BuildsAndroid
|
| public static void init( | ||
| final @NotNull Context context, | ||
| final @NotNull ILogger logger, | ||
| final @NotNull OptionsAndRuntimeConfiguration configuration) { | ||
| SentryAndroid.init(context, logger, configuration); | ||
| } |
There was a problem hiding this comment.
Hybrid init with profiling leaks the executor created before the runtime override
When a hybrid config supplies runtime.executorService(...) and enables profiling, activate() creates an executor on options and initConfigurations() submits profiling cleanup to it before the runtime replaces it; Sentry.close() closes only the replacement, leaving the original worker alive.
Evidence
InternalSentrySdk.initpasses the builder to the configuration callback, so a hybrid can setruntime.executorService(...)without setting the options executor.Sentry.initcallsoptions.activate()beforeinitConfigurations()and builds the runtime afterward. With the options executor unset,activate()creates aSentryExecutorService; when profiling is enabled,initConfigurations()submits cleanup to it. Android initialization supplies a cache path, so the profiling-traces path is available.LegacyOptionsBridge.buildRuntimethen replaces the options executor with the builder’s executor without closing the previous one. The defaultSentryExecutorServicedoes not time out its core worker, andSentry.close()closes only the executor currently on options.
Also found at 1 additional location
sentry/src/main/java/io/sentry/internal/LegacyOptionsBridge.java:32-43
Identified by Warden · code-review · CXK-F6A
| final @NotNull IEnvelopeCache envelopeDiskCache = options.getEnvelopeDiskCache(); | ||
| if (!(envelopeDiskCache instanceof NoOpEnvelopeCache)) { | ||
| builder.envelopeDiskCache(envelopeDiskCache); | ||
| } |
There was a problem hiding this comment.
Builder envelopeDiskCache is discarded when cacheDirPath is set
A cache set on SentryRuntime.Builder is overwritten whenever initConfigurations has already replaced options' NoOp with EnvelopeCache for a non-null cacheDirPath, so hybrid/platform caches never reach options or the runtime.
Evidence
Sentry.initrunsinitConfigurations(options)beforeLegacyOptionsBridge.buildRuntime().initConfigurationsdoesoptions.setEnvelopeDiskCache(EnvelopeCache.create(options))whencacheDirPath != nulland the options cache is stillNoOpEnvelopeCache.buildRuntimethen treats any non-NoOp options cache as authoritative and callsbuilder.envelopeDiskCache(envelopeDiskCache), replacing a cache already set on the builder.- The result is copied back with
options.setEnvelopeDiskCache(runtime.getEnvelopeDiskCache()), so options readers also keep the initConfigurations instance; the test that expects a platform builder cache to win only covers options that still hold NoOp.
Identified by Warden · code-review · FQU-9LK
📜 Description
Adds
io.sentry.internal.SentryRuntime, an immutable holder for the collaborators the SDK owns rather than the customer: the serializer, the executor and the envelope disk cache. It is built once perSentry.init. Nothing reads from it yet; follow-up PRs move each collaborator's readers to constructor injection.LegacyOptionsBridgebuilds the runtime from what is onSentryOptionsand copies it back, so code that still reads the options sees the same instances.InternalIntegrationletsSentry.inithand the runtime to SDK integrations.Sentry.initandSentryAndroid.inittake aSentryRuntime.Builderthrough new internal overloads. Hybrid SDKs getInternalSentrySdk.init(context, logger, (options, runtime) -> …)andInternalSentrySdk.getRuntime().No behavior change: the runtime is built where
initused to replace a closed executor, and it reuses the disk cacheinitConfigurationsalready created.💡 Motivation and Context
Part of JAVA-817. Customers should only configure
SentryOptions. Moving the SDK's internals off it lets 9.0 remove them from the public API.💚 How did you test it?
SentryRuntimeTest, plus the existingsentryandsentry-android-coreunit tests.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Separate PRs move executor shutdown, the integrations, the disk cache and the init-time executor users onto the runtime. A last PR deprecates the
SentryOptionsaccessors.🤖 Generated with Claude Code
#skip-changelog