1717import io .sentry .transport .NoOpEnvelopeCache ;
1818import io .sentry .util .DebugMetaPropertiesApplier ;
1919import io .sentry .util .FileUtils ;
20+ import io .sentry .util .InitUtil ;
2021import io .sentry .util .LoadClass ;
2122import io .sentry .util .Platform ;
2223import io .sentry .util .thread .IMainThreadChecker ;
@@ -279,43 +280,55 @@ private static synchronized void init(
279280 "Sentry has been already initialized. Previous configuration will be overwritten." );
280281 }
281282
282- if (!initConfigurations (options )) {
283+ if (!preInitConfigurations (options )) {
283284 return ;
284285 }
285286
286287 options .getLogger ().log (SentryLevel .INFO , "GlobalHubMode: '%s'" , String .valueOf (globalHubMode ));
287288 Sentry .globalHubMode = globalHubMode ;
288- globalScope .replaceOptions (options );
289+ final boolean shouldInit = InitUtil .shouldInit (globalScope .getOptions (), options , isEnabled ());
290+ if (shouldInit ) {
291+ globalScope .replaceOptions (options );
289292
290- final IScopes scopes = getCurrentScopes ();
291- final IScope rootScope = new Scope (options );
292- final IScope rootIsolationScope = new Scope (options );
293- rootScopes = new Scopes (rootScope , rootIsolationScope , globalScope , "Sentry.init" );
293+ final IScopes scopes = getCurrentScopes ();
294+ final IScope rootScope = new Scope (options );
295+ final IScope rootIsolationScope = new Scope (options );
296+ rootScopes = new Scopes (rootScope , rootIsolationScope , globalScope , "Sentry.init" );
294297
295- getScopesStorage ().set (rootScopes );
298+ getScopesStorage ().set (rootScopes );
296299
297- scopes .close (true );
298- globalScope .bindClient (new SentryClient (rootScopes .getOptions ()));
300+ scopes .close (true );
299301
300- // If the executorService passed in the init is the same that was previously closed, we have to
301- // set a new one
302- if (options .getExecutorService ().isClosed ()) {
303- options .setExecutorService (new SentryExecutorService ());
304- }
302+ initConfigurations (options );
305303
306- // when integrations are registered on Scopes ctor and async integrations are fired,
307- // it might and actually happened that integrations called captureSomething
308- // and Scopes was still NoOp.
309- // Registering integrations here make sure that Scopes is already created.
310- for (final Integration integration : options .getIntegrations ()) {
311- integration .register (ScopesAdapter .getInstance (), options );
312- }
304+ globalScope .bindClient (new SentryClient (options ));
305+
306+ // If the executorService passed in the init is the same that was previously closed, we have
307+ // to
308+ // set a new one
309+ if (options .getExecutorService ().isClosed ()) {
310+ options .setExecutorService (new SentryExecutorService ());
311+ }
312+ // when integrations are registered on Scopes ctor and async integrations are fired,
313+ // it might and actually happened that integrations called captureSomething
314+ // and Scopes was still NoOp.
315+ // Registering integrations here make sure that Scopes is already created.
316+ for (final Integration integration : options .getIntegrations ()) {
317+ integration .register (ScopesAdapter .getInstance (), options );
318+ }
313319
314- notifyOptionsObservers (options );
320+ notifyOptionsObservers (options );
315321
316- finalizePreviousSession (options , ScopesAdapter .getInstance ());
322+ finalizePreviousSession (options , ScopesAdapter .getInstance ());
317323
318- handleAppStartProfilingConfig (options , options .getExecutorService ());
324+ handleAppStartProfilingConfig (options , options .getExecutorService ());
325+ } else {
326+ options
327+ .getLogger ()
328+ .log (
329+ SentryLevel .WARNING ,
330+ "This init call has been ignored due to priority being too low." );
331+ }
319332 }
320333
321334 @ SuppressWarnings ("FutureReturnValueIgnored" )
@@ -419,8 +432,7 @@ private static void notifyOptionsObservers(final @NotNull SentryOptions options)
419432 }
420433 }
421434
422- @ SuppressWarnings ("FutureReturnValueIgnored" )
423- private static boolean initConfigurations (final @ NotNull SentryOptions options ) {
435+ private static boolean preInitConfigurations (final @ NotNull SentryOptions options ) {
424436 if (options .isEnableExternalConfiguration ()) {
425437 options .merge (ExternalOptions .from (PropertiesProviderFactory .create (), options .getLogger ()));
426438 }
@@ -438,6 +450,11 @@ private static boolean initConfigurations(final @NotNull SentryOptions options)
438450 @ SuppressWarnings ("unused" )
439451 final Dsn parsedDsn = new Dsn (dsn );
440452
453+ return true ;
454+ }
455+
456+ @ SuppressWarnings ("FutureReturnValueIgnored" )
457+ private static void initConfigurations (final @ NotNull SentryOptions options ) {
441458 ILogger logger = options .getLogger ();
442459
443460 if (options .isDebug () && logger instanceof NoOpLogger ) {
@@ -534,8 +551,6 @@ private static boolean initConfigurations(final @NotNull SentryOptions options)
534551 options .setBackpressureMonitor (new BackpressureMonitor (options , ScopesAdapter .getInstance ()));
535552 options .getBackpressureMonitor ().start ();
536553 }
537-
538- return true ;
539554 }
540555
541556 /** Close the SDK */
0 commit comments