diff --git a/CHANGELOG.md b/CHANGELOG.md index c7e5c4149b..9eb6d75604 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Unreleased + +### Fixes + +- Load lazy fields on init in the background ([#3803](https://github.com/getsentry/sentry-java/pull/3803)) +- Replace setOf with HashSet.add ([#3801](https://github.com/getsentry/sentry-java/pull/3801)) + ## 7.16.0-alpha.1 ### Features @@ -8,7 +15,6 @@ ### Fixes -- Replace setOf with HashSet.add ([#3801](https://github.com/getsentry/sentry-java/pull/3801)) - Cache parsed Dsn ([#3796](https://github.com/getsentry/sentry-java/pull/3796)) - fix invalid profiles when the transaction name is empty ([#3747](https://github.com/getsentry/sentry-java/pull/3747)) - Deprecate `enableTracing` option ([#3777](https://github.com/getsentry/sentry-java/pull/3777)) diff --git a/sentry/src/main/java/io/sentry/Sentry.java b/sentry/src/main/java/io/sentry/Sentry.java index 7c34720d19..6e4a2530a7 100644 --- a/sentry/src/main/java/io/sentry/Sentry.java +++ b/sentry/src/main/java/io/sentry/Sentry.java @@ -217,6 +217,10 @@ public static void init(final @NotNull SentryOptions options) { * @param options options the SentryOptions * @param globalHubMode the globalHubMode */ + @SuppressWarnings({ + "Convert2MethodRef", + "FutureReturnValueIgnored" + }) // older AGP versions do not support method references private static synchronized void init( final @NotNull SentryOptions options, final boolean globalHubMode) { if (isEnabled()) { @@ -231,6 +235,18 @@ private static synchronized void init( return; } + // load lazy fields of the options in a separate thread + try { + options.getExecutorService().submit(() -> options.loadLazyFields()); + } catch (RejectedExecutionException e) { + options + .getLogger() + .log( + SentryLevel.DEBUG, + "Failed to call the executor. Lazy fields will not be loaded. Did you call Sentry.close()?", + e); + } + options.getLogger().log(SentryLevel.INFO, "GlobalHubMode: '%s'", String.valueOf(globalHubMode)); Sentry.globalHubMode = globalHubMode; diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java index 91a1372fed..3c286f2bff 100644 --- a/sentry/src/main/java/io/sentry/SentryOptions.java +++ b/sentry/src/main/java/io/sentry/SentryOptions.java @@ -2451,6 +2451,17 @@ public void setEnableScreenTracking(final boolean enableScreenTracking) { this.enableScreenTracking = enableScreenTracking; } + /** + * Load the lazy fields. Useful to load in the background, so that results are already cached. DO + * NOT CALL THIS METHOD ON THE MAIN THREAD. + */ + void loadLazyFields() { + getSerializer(); + getParsedDsn(); + getEnvelopeReader(); + getDateProvider(); + } + /** The BeforeSend callback */ public interface BeforeSendCallback {