diff --git a/CHANGELOG.md b/CHANGELOG.md index c30eb073e9..dcdc3870ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Fix log count in client reports ([#4869](https://github.com/getsentry/sentry-java/pull/4869)) - Fix profilerId propagation ([#4833](https://github.com/getsentry/sentry-java/pull/4833)) - Fix profiling init for Spring and Spring Boot w Agent auto-init ([#4815](https://github.com/getsentry/sentry-java/pull/4815)) +- Copy active span on scope clone ([#4878](https://github.com/getsentry/sentry-java/pull/4878)) ### Improvements diff --git a/sentry/src/main/java/io/sentry/Scope.java b/sentry/src/main/java/io/sentry/Scope.java index eb17420dd2..5fc82a648d 100644 --- a/sentry/src/main/java/io/sentry/Scope.java +++ b/sentry/src/main/java/io/sentry/Scope.java @@ -124,6 +124,7 @@ public Scope(final @NotNull SentryOptions options) { private Scope(final @NotNull Scope scope) { this.transaction = scope.transaction; this.transactionName = scope.transactionName; + this.activeSpan = scope.activeSpan; this.session = scope.session; this.options = scope.options; this.level = scope.level; diff --git a/sentry/src/test/java/io/sentry/ScopeTest.kt b/sentry/src/test/java/io/sentry/ScopeTest.kt index 42c18049e0..bccc7d602a 100644 --- a/sentry/src/test/java/io/sentry/ScopeTest.kt +++ b/sentry/src/test/java/io/sentry/ScopeTest.kt @@ -12,6 +12,7 @@ import kotlin.test.assertFalse import kotlin.test.assertNotNull import kotlin.test.assertNotSame import kotlin.test.assertNull +import kotlin.test.assertSame import kotlin.test.assertTrue import org.junit.Assert.assertArrayEquals import org.mockito.kotlin.any @@ -155,6 +156,21 @@ class ScopeTest { assertEquals(attachment.contentType, actual.contentType) } + @Test + fun `copying scope copies active span`() { + val scope = Scope(SentryOptions()) + + val transaction = + SentryTracer(TransactionContext("transaction-name", "op"), NoOpScopes.getInstance()) + val span = transaction.startChild("child1") + + scope.setActiveSpan(span) + + val clone = scope.clone() + + assertSame(span, clone.span) + } + @Test fun `copying scope and changing the original values wont change the clone values`() { val scope = Scope(SentryOptions())