-
-
Notifications
You must be signed in to change notification settings - Fork 473
perf(core): Create outbox and cache dirs lazily instead of during init (JAVA-613) #5792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d868b87
46681de
1fdc454
a2a855b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -616,19 +616,14 @@ private static void initConfigurations(final @NotNull SentryOptions options) { | |
| // TODO: read values from conf file, Build conf or system envs | ||
| // eg release, distinctId, sentryClientName | ||
|
|
||
| // this should be after setting serializers | ||
| final String outboxPath = options.getOutboxPath(); | ||
| if (outboxPath != null) { | ||
| final File outboxDir = new File(outboxPath); | ||
| outboxDir.mkdirs(); | ||
| } else { | ||
| // The outbox and cache dirs are created lazily by their consumers (envelope cache, outbox file | ||
| // observer, native SDK) off the init thread, so we don't stat/mkdir them here. | ||
| if (options.getOutboxPath() == null) { | ||
| logger.log(SentryLevel.INFO, "No outbox dir path is defined in options."); | ||
| } | ||
|
|
||
| final String cacheDirPath = options.getCacheDirPath(); | ||
| if (cacheDirPath != null) { | ||
| final File cacheDir = new File(cacheDirPath); | ||
| cacheDir.mkdirs(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cache send errors on missing dirMedium Severity Removing init-time Additional Locations (1)Reviewed by Cursor Bugbot for commit a2a855b. Configure here. |
||
| final IEnvelopeCache envelopeCache = options.getEnvelopeDiskCache(); | ||
| // only overwrite the cache impl if it's not already set | ||
| if (envelopeCache instanceof NoOpEnvelopeCache) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package io.sentry.util; | ||
|
|
||
| import java.io.File; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| /** | ||
| * A filesystem directory that is created on demand rather than up front, so the (potentially | ||
| * blocking) {@code mkdirs()} runs on the thread that first writes into it instead of on the SDK | ||
| * init thread. | ||
| */ | ||
| @ApiStatus.Internal | ||
| public final class LazyDirectory { | ||
|
|
||
| private final @NotNull File file; | ||
|
|
||
| public LazyDirectory(final @NotNull String path) { | ||
| this.file = new File(path); | ||
| } | ||
|
|
||
| /** Returns the directory without touching the filesystem. */ | ||
| public @NotNull File getFile() { | ||
| return file; | ||
| } | ||
|
|
||
| /** Returns the directory, creating it and any missing parents if it does not exist yet. */ | ||
| public @NotNull File getOrCreate() { | ||
| if (!file.isDirectory()) { | ||
| file.mkdirs(); | ||
| } | ||
| return file; | ||
| } | ||
| } |


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outbox missing after init returns
Medium Severity
Outbox creation moved onto the executor inside
startOutboxSender, so afterSentry.initreturns the outbox may still be missing when NDK is disabled (native no longer materializes it during init). Hybrid SDKs that write envelopes to the outbox immediately after init can fail in that window, whereas init previously created the directory synchronously before returning.Additional Locations (1)
sentry/src/main/java/io/sentry/Sentry.java#L618-L623Reviewed by Cursor Bugbot for commit a2a855b. Configure here.