diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f6c22e1d5..b235002fab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ ### Fixes +- 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)) 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 6632efce93..4ab9310d6b 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 99d4c05be0..4e593bb051 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")