Skip to content

Commit a0d77eb

Browse files
adinauerclaude
andcommitted
ref(core): Have ScopesStorageFactory implement IScopesStorageFactory
Add LoadClass and ILogger parameters to IScopesStorageFactory.create() so custom factories have access to class loading utilities. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a211bd5 commit a0d77eb

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

sentry/api/sentry.api

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ public abstract interface class io/sentry/IScopesStorage {
10611061
}
10621062

10631063
public abstract interface class io/sentry/IScopesStorageFactory {
1064-
public abstract fun create ()Lio/sentry/IScopesStorage;
1064+
public abstract fun create (Lio/sentry/util/LoadClass;Lio/sentry/ILogger;)Lio/sentry/IScopesStorage;
10651065
}
10661066

10671067
public abstract interface class io/sentry/ISentryClient {
@@ -2632,9 +2632,9 @@ public final class io/sentry/ScopesAdapter : io/sentry/IScopes {
26322632
public fun withScope (Lio/sentry/ScopeCallback;)V
26332633
}
26342634

2635-
public final class io/sentry/ScopesStorageFactory {
2635+
public final class io/sentry/ScopesStorageFactory : io/sentry/IScopesStorageFactory {
26362636
public fun <init> ()V
2637-
public static fun create (Lio/sentry/util/LoadClass;Lio/sentry/ILogger;)Lio/sentry/IScopesStorage;
2637+
public fun create (Lio/sentry/util/LoadClass;Lio/sentry/ILogger;)Lio/sentry/IScopesStorage;
26382638
}
26392639

26402640
public final class io/sentry/ScreenshotStrategyType : java/lang/Enum {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package io.sentry;
22

3+
import io.sentry.util.LoadClass;
34
import org.jetbrains.annotations.ApiStatus;
45
import org.jetbrains.annotations.NotNull;
56

67
/** Factory for creating custom {@link IScopesStorage} implementations. */
78
@ApiStatus.Experimental
89
public interface IScopesStorageFactory {
910
@NotNull
10-
IScopesStorage create();
11+
IScopesStorage create(final @NotNull LoadClass loadClass, final @NotNull ILogger logger);
1112
}

sentry/src/main/java/io/sentry/ScopesStorageFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
import org.jetbrains.annotations.Nullable;
99

1010
@ApiStatus.Internal
11-
public final class ScopesStorageFactory {
11+
public final class ScopesStorageFactory implements IScopesStorageFactory {
1212

1313
private static final String OTEL_SCOPES_STORAGE =
1414
"io.sentry.opentelemetry.OtelContextScopesStorage";
1515

16-
public static @NotNull IScopesStorage create(
16+
@Override
17+
public @NotNull IScopesStorage create(
1718
final @NotNull LoadClass loadClass, final @NotNull ILogger logger) {
1819
final @NotNull IScopesStorage storage = createInternal(loadClass, logger);
1920
storage.init();

sentry/src/main/java/io/sentry/Sentry.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,15 @@ private static void initFatalLogger(final @NotNull SentryOptions options) {
439439

440440
private static void initScopesStorage(SentryOptions options) {
441441
getScopesStorage().close();
442+
final @NotNull LoadClass loadClass = new LoadClass();
443+
final @NotNull ILogger logger = NoOpLogger.getInstance();
442444
if (options.getScopesStorageFactory() != null) {
443-
scopesStorage = options.getScopesStorageFactory().create();
445+
scopesStorage = options.getScopesStorageFactory().create(loadClass, logger);
444446
scopesStorage.init();
445447
} else if (SentryOpenTelemetryMode.OFF == options.getOpenTelemetryMode()) {
446448
scopesStorage = new DefaultScopesStorage();
447449
} else {
448-
scopesStorage = ScopesStorageFactory.create(new LoadClass(), NoOpLogger.getInstance());
450+
scopesStorage = new ScopesStorageFactory().create(loadClass, logger);
449451
}
450452
}
451453

sentry/src/test/java/io/sentry/SentryOptionsTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,15 +974,15 @@ class SentryOptionsTest {
974974
@Test
975975
fun `scopesStorageFactory can be set and retrieved`() {
976976
val options = SentryOptions()
977-
val factory = IScopesStorageFactory { DefaultScopesStorage() }
977+
val factory = IScopesStorageFactory { _, _ -> DefaultScopesStorage() }
978978
options.scopesStorageFactory = factory
979979
assertSame(factory, options.scopesStorageFactory)
980980
}
981981

982982
@Test
983983
fun `scopesStorageFactory can be set to null`() {
984984
val options = SentryOptions()
985-
val factory = IScopesStorageFactory { DefaultScopesStorage() }
985+
val factory = IScopesStorageFactory { _, _ -> DefaultScopesStorage() }
986986
options.scopesStorageFactory = factory
987987
options.scopesStorageFactory = null
988988
assertNull(options.scopesStorageFactory)

sentry/src/test/java/io/sentry/SentryTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ class SentryTest {
17321732

17331733
initForTest {
17341734
it.dsn = dsn
1735-
it.scopesStorageFactory = IScopesStorageFactory { customStorage }
1735+
it.scopesStorageFactory = IScopesStorageFactory { _, _ -> customStorage }
17361736
}
17371737

17381738
verify(customStorage).init()
@@ -1758,7 +1758,7 @@ class SentryTest {
17581758

17591759
initForTest {
17601760
it.dsn = dsn
1761-
it.scopesStorageFactory = IScopesStorageFactory {
1761+
it.scopesStorageFactory = IScopesStorageFactory { _, _ ->
17621762
factoryCalled.set(true)
17631763
backingStorage
17641764
}

0 commit comments

Comments
 (0)