Skip to content

Commit 4395ef6

Browse files
adinauerclaude
andcommitted
fix(opentelemetry): Align null timestamp handling
Apply the explicit timestamp argument to copied span options even when it is null. This matches native tracing while preserving caller-owned options. Refs #6416 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5c33623 commit 4395ef6

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

‎sentry-opentelemetry/sentry-opentelemetry-core/src/main/java/io/sentry/opentelemetry/OtelSpanWrapper.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ public OtelSpanWrapper(
153153
@Nullable SentryDate timestamp,
154154
@NotNull SpanOptions spanOptions) {
155155
final @NotNull SpanOptions spanOptionsSnapshot = new SpanOptions(spanOptions);
156-
if (timestamp != null) {
157-
spanOptionsSnapshot.setStartTimestamp(timestamp);
158-
}
156+
spanOptionsSnapshot.setStartTimestamp(timestamp);
159157
return startChild(operation, description, spanOptionsSnapshot);
160158
}
161159

‎sentry-opentelemetry/sentry-opentelemetry-core/src/test/kotlin/OtelSpanWrapperTest.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import org.mockito.kotlin.whenever
2222

2323
class OtelSpanWrapperTest {
2424
@Test
25-
fun `startChild with timestamp and options only overrides non-null timestamp`() {
25+
fun `startChild with timestamp and options applies timestamp to copy`() {
2626
val otelSpan = mock<ReadWriteSpan>()
2727
whenever(otelSpan.spanContext)
2828
.thenReturn(
@@ -60,7 +60,7 @@ class OtelSpanWrapperTest {
6060
assertThat(spanOptions.allValues[0]).isNotSameInstanceAs(suppliedSpanOptions)
6161
assertThat(spanOptions.allValues[0].startTimestamp).isSameInstanceAs(timestamp)
6262
assertThat(spanOptions.allValues[1]).isNotSameInstanceAs(suppliedSpanOptions)
63-
assertThat(spanOptions.allValues[1].startTimestamp).isSameInstanceAs(originalTimestamp)
63+
assertThat(spanOptions.allValues[1].startTimestamp).isNull()
6464
assertThat(suppliedSpanOptions.startTimestamp).isSameInstanceAs(originalTimestamp)
6565
assertThat(spanContext.allValues[0].operation).isEqualTo("child-op")
6666
assertThat(spanContext.allValues[0].description).isEqualTo("description")

0 commit comments

Comments
 (0)