Skip to content
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

[QA] Load lazy fields on init in the background #3803

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading