Skip to content

Commit

Permalink
Merge 24cbe32 into 4d00bb3
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn committed May 2, 2023
2 parents 4d00bb3 + 24cbe32 commit 2380724
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- Use `configureScope` instead of `withScope` in `Hub.close()`. This ensures that the main scope releases the in-memory data when closing a hub instance. ([#2688](https://github.com/getsentry/sentry-java/pull/2688))

### Dependencies

- Bump Gradle from v8.1.0 to v8.1.1 ([#2666](https://github.com/getsentry/sentry-java/pull/2666))
Expand Down
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public void close() {
}
}

withScope(scope -> scope.clear());
configureScope(scope -> scope.clear());
options.getTransactionProfiler().close();
options.getTransactionPerformanceCollector().close();
options.getExecutorService().close(options.getShutdownTimeoutMillis());
Expand Down
20 changes: 20 additions & 0 deletions sentry/src/test/java/io/sentry/HubTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,26 @@ class HubTest {
verify(performanceCollector).close()
}

@Test
fun `Hub close should clear the scope`() {
val options = SentryOptions().apply {
dsn = "https://key@sentry.io/proj"
}

val sut = Hub(options)
sut.addBreadcrumb("Test")
sut.startTransaction("test", "test.op", true)
sut.close()

// we have to clone the scope, so its isEnabled returns true, but it's still built up from
// the old scope preserving its data
val clone = sut.clone()
var oldScope: Scope? = null
clone.configureScope { scope -> oldScope = scope }
assertNull(oldScope!!.transaction)
assertTrue(oldScope!!.breadcrumbs.isEmpty())
}

@Test
fun `when tracesSampleRate and tracesSampler are not set on SentryOptions, startTransaction returns NoOp`() {
val hub = generateHub {
Expand Down

0 comments on commit 2380724

Please sign in to comment.