@@ -47,8 +47,7 @@ public final class Sentry {
4747 private Sentry () {}
4848
4949 // TODO logger?
50- private static volatile @ NotNull IScopesStorage scopesStorage =
51- ScopesStorageFactory .create (new LoadClass (), NoOpLogger .getInstance ());
50+ private static volatile @ NotNull IScopesStorage scopesStorage = NoOpScopesStorage .getInstance ();
5251
5352 /** The root Scopes or NoOp if Sentry is disabled. */
5453 private static volatile @ NotNull IScopes rootScopes = NoOpScopes .getInstance ();
@@ -322,6 +321,7 @@ private static void init(final @NotNull SentryOptions options, final boolean glo
322321 final IScope rootIsolationScope = new Scope (options );
323322 rootScopes = new Scopes (rootScope , rootIsolationScope , globalScope , "Sentry.init" );
324323
324+ initScopesStorage (options );
325325 getScopesStorage ().set (rootScopes );
326326
327327 initConfigurations (options );
@@ -357,6 +357,15 @@ private static void init(final @NotNull SentryOptions options, final boolean glo
357357 }
358358 }
359359
360+ private static void initScopesStorage (SentryOptions options ) {
361+ getScopesStorage ().close ();
362+ if (SentryOpenTelemetryMode .OFF == options .getOpenTelemetryMode ()) {
363+ scopesStorage = new DefaultScopesStorage ();
364+ } else {
365+ scopesStorage = ScopesStorageFactory .create (new LoadClass (), options .getLogger ());
366+ }
367+ }
368+
360369 @ SuppressWarnings ("FutureReturnValueIgnored" )
361370 private static void handleAppStartProfilingConfig (
362371 final @ NotNull SentryOptions options ,
@@ -492,6 +501,11 @@ private static void initConfigurations(final @NotNull SentryOptions options) {
492501 logger .log (SentryLevel .INFO , "Initializing SDK with DSN: '%s'" , options .getDsn ());
493502
494503 OpenTelemetryUtil .applyIgnoredSpanOrigins (options , new LoadClass ());
504+ if (SentryOpenTelemetryMode .OFF == options .getOpenTelemetryMode ()) {
505+ options .setSpanFactory (new DefaultSpanFactory ());
506+ } else {
507+ options .setSpanFactory (SpanFactoryFactory .create (new LoadClass (), NoOpLogger .getInstance ()));
508+ }
495509
496510 // TODO: read values from conf file, Build conf or system envs
497511 // eg release, distinctId, sentryClientName
0 commit comments