Skip to content

Commit f54a1d9

Browse files
authored
fix(otel): Copy active span on scope clone (#4878)
* Copy active span when cloning scope * changelog
1 parent db8e32e commit f54a1d9

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- Fix log count in client reports ([#4869](https://github.com/getsentry/sentry-java/pull/4869))
2525
- Fix profilerId propagation ([#4833](https://github.com/getsentry/sentry-java/pull/4833))
2626
- Fix profiling init for Spring and Spring Boot w Agent auto-init ([#4815](https://github.com/getsentry/sentry-java/pull/4815))
27+
- Copy active span on scope clone ([#4878](https://github.com/getsentry/sentry-java/pull/4878))
2728

2829
### Improvements
2930

sentry/src/main/java/io/sentry/Scope.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public Scope(final @NotNull SentryOptions options) {
124124
private Scope(final @NotNull Scope scope) {
125125
this.transaction = scope.transaction;
126126
this.transactionName = scope.transactionName;
127+
this.activeSpan = scope.activeSpan;
127128
this.session = scope.session;
128129
this.options = scope.options;
129130
this.level = scope.level;

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import kotlin.test.assertFalse
1212
import kotlin.test.assertNotNull
1313
import kotlin.test.assertNotSame
1414
import kotlin.test.assertNull
15+
import kotlin.test.assertSame
1516
import kotlin.test.assertTrue
1617
import org.junit.Assert.assertArrayEquals
1718
import org.mockito.kotlin.any
@@ -155,6 +156,21 @@ class ScopeTest {
155156
assertEquals(attachment.contentType, actual.contentType)
156157
}
157158

159+
@Test
160+
fun `copying scope copies active span`() {
161+
val scope = Scope(SentryOptions())
162+
163+
val transaction =
164+
SentryTracer(TransactionContext("transaction-name", "op"), NoOpScopes.getInstance())
165+
val span = transaction.startChild("child1")
166+
167+
scope.setActiveSpan(span)
168+
169+
val clone = scope.clone()
170+
171+
assertSame(span, clone.span)
172+
}
173+
158174
@Test
159175
fun `copying scope and changing the original values wont change the clone values`() {
160176
val scope = Scope(SentryOptions())

0 commit comments

Comments
 (0)