Skip to content

Commit

Permalink
[QA] Load lazy fields on init in the background (#3803)
Browse files Browse the repository at this point in the history
* Lazy fields in SentryOptions are now loaded on init in the background
* use option's executor instead of a new thread to load fields
  • Loading branch information
stefanosiano authored Oct 18, 2024
1 parent 0132cdd commit 0cc9262
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
Expand Down
16 changes: 16 additions & 0 deletions sentry/src/main/java/io/sentry/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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;

Expand Down
11 changes: 11 additions & 0 deletions sentry/src/main/java/io/sentry/SentryOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

0 comments on commit 0cc9262

Please sign in to comment.