-
-
Notifications
You must be signed in to change notification settings - Fork 465
[QA] Lazily load SentryOptions members #3749
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
64a61fe
Make AtomicClientReportStorage constructor lazy
romtsn 4210b0b
Lazily initialize things we dont need
romtsn 79e8ce1
Empty experimental options
romtsn 0511933
Format code
getsentry-bot 209e60d
Merge branch 'main' into rz/anrs/lazy-client-reports
romtsn c8ea809
Make LazyEvaluator thread-safe
markushi 02fd16f
Fix tests
markushi 5ed2cfe
Fix .api
markushi b6f9dd0
Use LazyEvaluator for heavy SentryOptions
romtsn 306add9
Changelog
romtsn d437823
revert
romtsn 62f4168
tests
romtsn 30ec7a2
Merge branch 'main' into rz/anrs/lazy-client-reports
romtsn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,13 +19,13 @@ | |
| import io.sentry.transport.ITransportGate; | ||
| import io.sentry.transport.NoOpEnvelopeCache; | ||
| import io.sentry.transport.NoOpTransportGate; | ||
| import io.sentry.util.Objects; | ||
| import io.sentry.util.Platform; | ||
| import io.sentry.util.SampleRateUtils; | ||
| import io.sentry.util.StringUtils; | ||
| import io.sentry.util.thread.IMainThreadChecker; | ||
| import io.sentry.util.thread.NoOpMainThreadChecker; | ||
| import java.io.File; | ||
| import java.net.Proxy; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
|
|
@@ -119,10 +119,14 @@ public class SentryOptions { | |
| private @NotNull SentryLevel diagnosticLevel = DEFAULT_DIAGNOSTIC_LEVEL; | ||
|
|
||
| /** Envelope reader interface */ | ||
| private @NotNull IEnvelopeReader envelopeReader = new EnvelopeReader(new JsonSerializer(this)); | ||
| private volatile @Nullable IEnvelopeReader envelopeReader; | ||
|
|
||
| private final @NotNull Object envelopeReaderLock = new Object(); | ||
|
|
||
| /** Serializer interface to serialize/deserialize json events */ | ||
| private @NotNull ISerializer serializer = new JsonSerializer(this); | ||
| private volatile @Nullable ISerializer serializer; | ||
|
|
||
| private final @NotNull Object serializerLock = new Object(); | ||
|
|
||
| /** Max depth when serializing object graphs with reflection. * */ | ||
| private int maxDepth = 100; | ||
|
|
@@ -415,8 +419,9 @@ public class SentryOptions { | |
| private boolean traceOptionsRequests = true; | ||
|
|
||
| /** Date provider to retrieve the current date from. */ | ||
| @ApiStatus.Internal | ||
| private @NotNull SentryDateProvider dateProvider = new SentryAutoDateProvider(); | ||
| @ApiStatus.Internal private volatile @Nullable SentryDateProvider dateProvider; | ||
|
|
||
| private final @NotNull Object dateProviderLock = new Object(); | ||
|
|
||
| private final @NotNull List<IPerformanceCollector> performanceCollectors = new ArrayList<>(); | ||
|
|
||
|
|
@@ -479,7 +484,7 @@ public class SentryOptions { | |
|
|
||
| @ApiStatus.Experimental private @Nullable Cron cron = null; | ||
|
|
||
| private final @NotNull ExperimentalOptions experimental = new ExperimentalOptions(); | ||
| private final @NotNull ExperimentalOptions experimental; | ||
|
|
||
| private @NotNull ReplayController replayController = NoOpReplayController.getInstance(); | ||
|
|
||
|
|
@@ -605,7 +610,14 @@ public void setDiagnosticLevel(@Nullable final SentryLevel diagnosticLevel) { | |
| * @return the serializer | ||
| */ | ||
| public @NotNull ISerializer getSerializer() { | ||
| return serializer; | ||
| if (serializer == null) { | ||
| synchronized (serializerLock) { | ||
|
||
| if (serializer == null) { | ||
| serializer = new JsonSerializer(this); | ||
| } | ||
| } | ||
| } | ||
| return Objects.requireNonNull(serializer, "Serializer was null"); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -636,7 +648,14 @@ public void setMaxDepth(int maxDepth) { | |
| } | ||
|
|
||
| public @NotNull IEnvelopeReader getEnvelopeReader() { | ||
| return envelopeReader; | ||
| if (envelopeReader == null) { | ||
| synchronized (envelopeReaderLock) { | ||
| if (envelopeReader == null) { | ||
| envelopeReader = new EnvelopeReader(getSerializer()); | ||
| } | ||
| } | ||
| } | ||
| return Objects.requireNonNull(envelopeReader, "EnvelopeReader was null"); | ||
| } | ||
|
|
||
| public void setEnvelopeReader(final @Nullable IEnvelopeReader envelopeReader) { | ||
|
|
@@ -2212,7 +2231,14 @@ public void setIgnoredCheckIns(final @Nullable List<String> ignoredCheckIns) { | |
| /** Returns the current {@link SentryDateProvider} that is used to retrieve the current date. */ | ||
| @ApiStatus.Internal | ||
| public @NotNull SentryDateProvider getDateProvider() { | ||
| return dateProvider; | ||
| if (dateProvider == null) { | ||
| synchronized (dateProviderLock) { | ||
| if (dateProvider == null) { | ||
| dateProvider = new SentryAutoDateProvider(); | ||
| } | ||
| } | ||
| } | ||
| return Objects.requireNonNull(dateProvider, "DateProvider is not set"); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -2540,6 +2566,7 @@ public SentryOptions() { | |
| * @param empty if options should be empty. | ||
| */ | ||
| private SentryOptions(final boolean empty) { | ||
| experimental = new ExperimentalOptions(empty); | ||
| if (!empty) { | ||
| // SentryExecutorService should be initialized before any | ||
| // SendCachedEventFireAndForgetIntegration | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.