Skip to content

Commit 78f5361

Browse files
adinauerclaude
andcommitted
feat(core): Pass SentryOptions to IScopesStorageFactory.create()
SPI-discovered factory implementations are instantiated via ServiceLoader with no-arg constructors, so they need access to options like logger and DSN at creation time. Change the interface method signature to accept SentryOptions as a parameter. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6368b19 commit 78f5361

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

sentry/api/sentry.api

Lines changed: 1 addition & 1 deletion
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/SentryOptions;)Lio/sentry/IScopesStorage;
10651065
}
10661066

10671067
public abstract interface class io/sentry/ISentryClient {

sentry/src/main/java/io/sentry/IScopesStorageFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
@ApiStatus.Experimental
88
public interface IScopesStorageFactory {
99
@NotNull
10-
IScopesStorage create();
10+
IScopesStorage create(@NotNull SentryOptions options);
1111
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ private static void initFatalLogger(final @NotNull SentryOptions options) {
440440
private static void initScopesStorage(SentryOptions options) {
441441
getScopesStorage().close();
442442
if (options.getScopesStorageFactory() != null) {
443-
scopesStorage = options.getScopesStorageFactory().create();
443+
scopesStorage = options.getScopesStorageFactory().create(options);
444444
scopesStorage.init();
445445
} else if (SentryOpenTelemetryMode.OFF == options.getOpenTelemetryMode()) {
446446
scopesStorage = new DefaultScopesStorage();

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)