From 987fda7f364680bbec5a6c927be7b3c95bd88e0c Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 7 Nov 2025 10:31:26 +0100 Subject: [PATCH 1/2] Copy active span when cloning scope --- sentry/src/main/java/io/sentry/Scope.java | 1 + sentry/src/test/java/io/sentry/ScopeTest.kt | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/sentry/src/main/java/io/sentry/Scope.java b/sentry/src/main/java/io/sentry/Scope.java index eb17420dd24..5fc82a648d3 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 42c18049e04..bccc7d602ab 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()) From 9047c00086f575793182c37cffb2057f6e686d93 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 7 Nov 2025 11:08:53 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38b0feabc76..ebd64a81ec1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Removed SentryExecutorService limit for delayed scheduled tasks ([#4846](https://github.com/getsentry/sentry-java/pull/4846)) - Fix visual artifacts for the Canvas strategy on some devices ([#4861](https://github.com/getsentry/sentry-java/pull/4861)) +- Copy active span on scope clone ([#4878](https://github.com/getsentry/sentry-java/pull/4878)) ### Improvements