From 4fed13d25753035873a8795604abcdef5ad06769 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Mon, 16 Nov 2026 13:44:57 +0100 Subject: [PATCH 1/3] fix(ktor-client): Send replay network timestamps in milliseconds Session Replay reads the HTTP start and end timestamps on a breadcrumb as epoch milliseconds, which is what sentry-okhttp sends. sentry-ktor-client divided the epoch nanoseconds by 1000, so it sent microseconds and its replay network spans landed 1000x too far in the future. Co-Authored-By: Claude Opus 5.5 --- .../ktorClient/SentryKtorClientUtils.kt | 6 +++-- .../ktorClient/SentryKtorClientPluginTest.kt | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt b/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt index 6632efce93f..4ab9310d6b1 100644 --- a/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt +++ b/sentry-ktor-client/src/main/java/io/sentry/ktorClient/SentryKtorClientUtils.kt @@ -19,6 +19,7 @@ import io.sentry.protocol.Mechanism import io.sentry.util.CookieUtils import io.sentry.util.HttpUtils import io.sentry.util.UrlUtils +import java.util.concurrent.TimeUnit internal object SentryKtorClientUtils { internal suspend fun captureClientError( @@ -126,16 +127,17 @@ internal object SentryKtorClientUtils { SpanDataConvention.HTTP_RESPONSE_CONTENT_LENGTH_KEY, response.contentLength(), ) + // Session Replay reads these as epoch milliseconds for its rrweb network spans. if (startTimestamp != null) { breadcrumb.setData( SpanDataConvention.HTTP_START_TIMESTAMP, - startTimestamp.nanoTimestamp() / 1000L, + TimeUnit.NANOSECONDS.toMillis(startTimestamp.nanoTimestamp()), ) } if (endTimestamp != null) { breadcrumb.setData( SpanDataConvention.HTTP_END_TIMESTAMP, - endTimestamp.nanoTimestamp() / 1000L, + TimeUnit.NANOSECONDS.toMillis(endTimestamp.nanoTimestamp()), ) } diff --git a/sentry-ktor-client/src/test/java/io/sentry/ktorClient/SentryKtorClientPluginTest.kt b/sentry-ktor-client/src/test/java/io/sentry/ktorClient/SentryKtorClientPluginTest.kt index 99d4c05be08..4e593bb0511 100644 --- a/sentry-ktor-client/src/test/java/io/sentry/ktorClient/SentryKtorClientPluginTest.kt +++ b/sentry-ktor-client/src/test/java/io/sentry/ktorClient/SentryKtorClientPluginTest.kt @@ -23,8 +23,10 @@ import io.sentry.Scope import io.sentry.ScopeCallback import io.sentry.ScopeType import io.sentry.Sentry +import io.sentry.SentryDateProvider import io.sentry.SentryEvent import io.sentry.SentryLevel +import io.sentry.SentryNanotimeDate import io.sentry.SentryOptions import io.sentry.SentryTraceHeader import io.sentry.SentryTracer @@ -155,6 +157,27 @@ class SentryKtorClientPluginTest { ) } + @Test + fun `breadcrumb timestamps are epoch milliseconds`(): Unit = runBlocking { + val epochMillis = 1_700_000_000_123L + val sut = + fixture.getSut( + optionsConfiguration = { options -> + options.dateProvider = SentryDateProvider { SentryNanotimeDate(epochMillis, 0) } + }, + ) + sut.get(fixture.server.url("/hello").toString()) + + verify(fixture.scopes) + .addBreadcrumb( + check { + assertThat(it.getData(SpanDataConvention.HTTP_START_TIMESTAMP)).isEqualTo(epochMillis) + assertThat(it.getData(SpanDataConvention.HTTP_END_TIMESTAMP)).isEqualTo(epochMillis) + }, + anyOrNull(), + ) + } + @Test fun `adds breadcrumb when http call fails`(): Unit = runBlocking { val sut = fixture.getSut(httpStatusCode = 500, responseBody = "error") From f3f473655a884496435376c7e909e20dfaa0f36c Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Mon, 16 Nov 2026 13:45:30 +0100 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f6c22e1d5f..57a80fac17f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ ### Fixes +- Session Replay: Fix Ktor client network requests showing up 1000x too late in the replay timeline ([#6619](https://github.com/getsentry/sentry-java/pull/6619)) - Nav3: Stop attributing errors and spans from an Activity or ViewPager2 page without a `SentryNavEffect` to the most recently visited Nav3 root ([#6483](https://github.com/getsentry/sentry-java/pull/6483)) - Android: Count deep sleep in breadcrumb, screenshot and view hierarchy debounce windows, so the first low-memory or battery breadcrumb after a long Doze is no longer dropped ([#6590](https://github.com/getsentry/sentry-java/pull/6590)) From 7959851b9084789046c6160be92e188890bce5e8 Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Mon, 16 Nov 2026 13:45:41 +0100 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57a80fac17f..b235002fab1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ ### Fixes -- Session Replay: Fix Ktor client network requests showing up 1000x too late in the replay timeline ([#6619](https://github.com/getsentry/sentry-java/pull/6619)) +- Session Replay: Send Ktor client network request start and end times in milliseconds, so the requests line up with the replay ([#6619](https://github.com/getsentry/sentry-java/pull/6619)) - Nav3: Stop attributing errors and spans from an Activity or ViewPager2 page without a `SentryNavEffect` to the most recently visited Nav3 root ([#6483](https://github.com/getsentry/sentry-java/pull/6483)) - Android: Count deep sleep in breadcrumb, screenshot and view hierarchy debounce windows, so the first low-memory or battery breadcrumb after a long Doze is no longer dropped ([#6590](https://github.com/getsentry/sentry-java/pull/6590))