Skip to content

Commit 8c90f98

Browse files
authored
Close Scopes before replacing options on global Scope (#3750)
* attach request body for application/x-www-form-urlencoded * extend tests * changelog * Add support for v22 of graphql-java, new modules sentry-graphql-22 and sentry-graphql-core * Add back callback interface and constants as deprecated * Replace GraphQlSourceBuilderCustomizer with directly providing a SentryInstrumentation bean if missing * Support graphql-java v22 in spring integrations * Close scopes before replacing options on global scope * changelog * fix api file
1 parent 2065d35 commit 8c90f98

File tree

5 files changed

+51
-7
lines changed

5 files changed

+51
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
- Transactions are dropped if trace context is missing
5858
- Remove internal annotation on `SpanOptions` ([#3722](https://github.com/getsentry/sentry-java/pull/3722))
5959
- `SentryLogbackInitializer` is now public ([#3723](https://github.com/getsentry/sentry-java/pull/3723))
60+
- Fix order of calling `close` on previous Sentry instance when re-initializing ([#3750](https://github.com/getsentry/sentry-java/pull/3750))
61+
- Previously some parts of Sentry were immediately closed after re-init that should have stayed open and some parts of the previous init were never closed
6062

6163
### Behavioural Changes
6264

sentry-android-integration-tests/sentry-uitest-android/src/androidTest/java/io/sentry/uitest/android/SdkInitTests.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import io.sentry.android.core.SentryAndroidOptions
1010
import io.sentry.assertEnvelopeTransaction
1111
import io.sentry.protocol.SentryTransaction
1212
import org.junit.runner.RunWith
13-
import kotlin.test.Ignore
1413
import kotlin.test.Test
1514
import kotlin.test.assertEquals
1615
import kotlin.test.assertTrue
@@ -36,7 +35,6 @@ class SdkInitTests : BaseUiTest() {
3635
transaction2.finish()
3736
}
3837

39-
@Ignore("not working since re-init changes related to POTel")
4038
@Test
4139
fun doubleInitWithSameOptionsDoesNotThrow() {
4240
val options = SentryAndroidOptions()
@@ -95,7 +93,6 @@ class SdkInitTests : BaseUiTest() {
9593
}
9694
}
9795

98-
@Ignore("not working since re-init changes related to POTel")
9996
@Test
10097
fun doubleInitDoesNotWait() {
10198
relayIdlingResource.increment()

sentry-graphql-22/api/sentry-graphql-22.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
public final class io/sentry/graphql22/BuildConfig {
2-
public static final field SENTRY_GRAPHQL_SDK_NAME Ljava/lang/String;
32
public static final field SENTRY_GRAPHQL22_SDK_NAME Ljava/lang/String;
43
public static final field VERSION_NAME Ljava/lang/String;
54
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,18 @@ private static void init(final @NotNull SentryOptions options, final boolean glo
294294
SentryLevel.WARNING,
295295
"Sentry has been already initialized. Previous configuration will be overwritten.");
296296
}
297-
globalScope.replaceOptions(options);
298297

299298
final IScopes scopes = getCurrentScopes();
299+
scopes.close(true);
300+
301+
globalScope.replaceOptions(options);
302+
300303
final IScope rootScope = new Scope(options);
301304
final IScope rootIsolationScope = new Scope(options);
302305
rootScopes = new Scopes(rootScope, rootIsolationScope, globalScope, "Sentry.init");
303306

304307
getScopesStorage().set(rootScopes);
305308

306-
scopes.close(true);
307-
308309
initConfigurations(options);
309310

310311
globalScope.bindClient(new SentryClient(options));

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.mockito.kotlin.mock
3333
import org.mockito.kotlin.never
3434
import org.mockito.kotlin.verify
3535
import org.mockito.kotlin.whenever
36+
import java.io.Closeable
3637
import java.io.File
3738
import java.io.FileReader
3839
import java.nio.file.Files
@@ -78,6 +79,50 @@ class SentryTest {
7879
verify(scopes).close(eq(true))
7980
}
8081

82+
@Test
83+
fun `init multiple times calls close on previous options not new`() {
84+
val profiler1 = mock<ITransactionProfiler>()
85+
val profiler2 = mock<ITransactionProfiler>()
86+
Sentry.init {
87+
it.dsn = dsn
88+
it.setTransactionProfiler(profiler1)
89+
}
90+
verify(profiler1, never()).close()
91+
92+
Sentry.init {
93+
it.dsn = dsn
94+
it.setTransactionProfiler(profiler2)
95+
}
96+
verify(profiler2, never()).close()
97+
verify(profiler1).close()
98+
99+
Sentry.close()
100+
verify(profiler2).close()
101+
}
102+
103+
@Test
104+
fun `init multiple times calls close on previous integrations not new`() {
105+
val integration1 = mock<CloseableIntegration>()
106+
val integration2 = mock<CloseableIntegration>()
107+
Sentry.init {
108+
it.dsn = dsn
109+
it.addIntegration(integration1)
110+
}
111+
verify(integration1, never()).close()
112+
113+
Sentry.init {
114+
it.dsn = dsn
115+
it.addIntegration(integration2)
116+
}
117+
verify(integration2, never()).close()
118+
verify(integration1).close()
119+
120+
Sentry.close()
121+
verify(integration2).close()
122+
}
123+
124+
interface CloseableIntegration : Integration, Closeable
125+
81126
@Test
82127
fun `global client is enabled after restart`() {
83128
val scopes = mock<IScopes>()

0 commit comments

Comments
 (0)