17
17
import io .sentry .transport .NoOpEnvelopeCache ;
18
18
import io .sentry .util .DebugMetaPropertiesApplier ;
19
19
import io .sentry .util .FileUtils ;
20
+ import io .sentry .util .InitUtil ;
20
21
import io .sentry .util .LoadClass ;
21
22
import io .sentry .util .Platform ;
22
23
import io .sentry .util .thread .IMainThreadChecker ;
@@ -279,43 +280,55 @@ private static synchronized void init(
279
280
"Sentry has been already initialized. Previous configuration will be overwritten." );
280
281
}
281
282
282
- if (!initConfigurations (options )) {
283
+ if (!preInitConfigurations (options )) {
283
284
return ;
284
285
}
285
286
286
287
options .getLogger ().log (SentryLevel .INFO , "GlobalHubMode: '%s'" , String .valueOf (globalHubMode ));
287
288
Sentry .globalHubMode = globalHubMode ;
288
- globalScope .replaceOptions (options );
289
+ final boolean shouldInit = InitUtil .shouldInit (globalScope .getOptions (), options , isEnabled ());
290
+ if (shouldInit ) {
291
+ globalScope .replaceOptions (options );
289
292
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" );
294
297
295
- getScopesStorage ().set (rootScopes );
298
+ getScopesStorage ().set (rootScopes );
296
299
297
- scopes .close (true );
298
- globalScope .bindClient (new SentryClient (rootScopes .getOptions ()));
300
+ scopes .close (true );
299
301
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 );
305
303
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
+ }
313
319
314
- notifyOptionsObservers (options );
320
+ notifyOptionsObservers (options );
315
321
316
- finalizePreviousSession (options , ScopesAdapter .getInstance ());
322
+ finalizePreviousSession (options , ScopesAdapter .getInstance ());
317
323
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
+ }
319
332
}
320
333
321
334
@ SuppressWarnings ("FutureReturnValueIgnored" )
@@ -419,8 +432,7 @@ private static void notifyOptionsObservers(final @NotNull SentryOptions options)
419
432
}
420
433
}
421
434
422
- @ SuppressWarnings ("FutureReturnValueIgnored" )
423
- private static boolean initConfigurations (final @ NotNull SentryOptions options ) {
435
+ private static boolean preInitConfigurations (final @ NotNull SentryOptions options ) {
424
436
if (options .isEnableExternalConfiguration ()) {
425
437
options .merge (ExternalOptions .from (PropertiesProviderFactory .create (), options .getLogger ()));
426
438
}
@@ -438,6 +450,11 @@ private static boolean initConfigurations(final @NotNull SentryOptions options)
438
450
@ SuppressWarnings ("unused" )
439
451
final Dsn parsedDsn = new Dsn (dsn );
440
452
453
+ return true ;
454
+ }
455
+
456
+ @ SuppressWarnings ("FutureReturnValueIgnored" )
457
+ private static void initConfigurations (final @ NotNull SentryOptions options ) {
441
458
ILogger logger = options .getLogger ();
442
459
443
460
if (options .isDebug () && logger instanceof NoOpLogger ) {
@@ -534,8 +551,6 @@ private static boolean initConfigurations(final @NotNull SentryOptions options)
534
551
options .setBackpressureMonitor (new BackpressureMonitor (options , ScopesAdapter .getInstance ()));
535
552
options .getBackpressureMonitor ().start ();
536
553
}
537
-
538
- return true ;
539
554
}
540
555
541
556
/** Close the SDK */
0 commit comments