From a001e2586d59ec3747c2156f1acd65543b636c2a Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Thu, 23 Apr 2026 13:33:00 +0200 Subject: [PATCH 1/2] fix(kafka): [Queue Instrumentation 31] Write enqueued-time header as plain decimal The sentry-task-enqueued-time Kafka header was serialized via String.valueOf(double), which emits scientific notation (e.g. 1.776933649613E9) for epoch-seconds values. Cross-SDK consumers (sentry-python, -ruby, -php, -dotnet) expect a plain decimal like 1776938295.692000 and could not parse the Java output, defeating the cross-SDK alignment goal of #5283. Route the value through DateUtils.doubleToBigDecimal(...).toString(), the same helper already used to serialize epoch-seconds timestamps in SentryTransaction, SentrySpan, SentryLogEvent, etc. At the pinned scale of 6, BigDecimal.toString() produces plain decimal form for all realistic epoch-seconds magnitudes. Add regression assertions that reject scientific notation and pin the plain-decimal format in SentryKafkaProducerInterceptorTest. Co-Authored-By: Claude --- .../kafka/SentryKafkaProducerInterceptor.java | 3 ++- .../kafka/SentryKafkaProducerInterceptorTest.kt | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sentry-kafka/src/main/java/io/sentry/kafka/SentryKafkaProducerInterceptor.java b/sentry-kafka/src/main/java/io/sentry/kafka/SentryKafkaProducerInterceptor.java index ea961c3786..6bcb424397 100644 --- a/sentry-kafka/src/main/java/io/sentry/kafka/SentryKafkaProducerInterceptor.java +++ b/sentry-kafka/src/main/java/io/sentry/kafka/SentryKafkaProducerInterceptor.java @@ -128,7 +128,8 @@ private void injectHeaders(final @NotNull Headers headers, final @NotNull ISpan headers.remove(SENTRY_ENQUEUED_TIME_HEADER); headers.add( SENTRY_ENQUEUED_TIME_HEADER, - String.valueOf(DateUtils.millisToSeconds(System.currentTimeMillis())) + DateUtils.doubleToBigDecimal(DateUtils.millisToSeconds(System.currentTimeMillis())) + .toString() .getBytes(StandardCharsets.UTF_8)); } diff --git a/sentry-kafka/src/test/kotlin/io/sentry/kafka/SentryKafkaProducerInterceptorTest.kt b/sentry-kafka/src/test/kotlin/io/sentry/kafka/SentryKafkaProducerInterceptorTest.kt index 2c59f2a24c..758deed094 100644 --- a/sentry-kafka/src/test/kotlin/io/sentry/kafka/SentryKafkaProducerInterceptorTest.kt +++ b/sentry-kafka/src/test/kotlin/io/sentry/kafka/SentryKafkaProducerInterceptorTest.kt @@ -17,6 +17,7 @@ import kotlin.test.AfterTest import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertFalse import kotlin.test.assertNotNull import kotlin.test.assertSame import kotlin.test.assertTrue @@ -84,7 +85,19 @@ class SentryKafkaProducerInterceptorTest { val enqueuedTimeHeader = record.headers().lastHeader(SentryKafkaProducerInterceptor.SENTRY_ENQUEUED_TIME_HEADER) assertNotNull(enqueuedTimeHeader) - val enqueuedTime = String(enqueuedTimeHeader.value(), StandardCharsets.UTF_8).toDouble() + val enqueuedTimeRaw = String(enqueuedTimeHeader.value(), StandardCharsets.UTF_8) + // Must be written as a plain decimal so cross-SDK consumers (e.g. sentry-python) can + // parse it. String.valueOf(double) would emit scientific notation (e.g. 1.77E9) for + // epoch seconds. + assertFalse( + enqueuedTimeRaw.contains('E') || enqueuedTimeRaw.contains('e'), + "enqueued-time header must not use scientific notation, got: $enqueuedTimeRaw", + ) + assertTrue( + enqueuedTimeRaw.matches(Regex("""^\d+\.\d{6}$""")), + "enqueued-time header must be plain epoch seconds with 6 decimals, got: $enqueuedTimeRaw", + ) + val enqueuedTime = enqueuedTimeRaw.toDouble() assertTrue(enqueuedTime > 0) } From 39f67f3b8de179ab944cb75c76562f3ca04a9a6e Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Thu, 23 Apr 2026 13:39:58 +0200 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ce9b04b72..68dd4433f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ - Android: Attachments on the scope will now be synced to native ([#5211](https://github.com/getsentry/sentry-java/pull/5211)) - Add THIRD_PARTY_NOTICES.md for vendored third-party code, bundled as SENTRY_THIRD_PARTY_NOTICES.md in the sentry JAR under META-INF ([#5186](https://github.com/getsentry/sentry-java/pull/5186)) +### Fixes + +- Write the `sentry-task-enqueued-time` Kafka header as a plain decimal so cross-SDK consumers (e.g. sentry-python) can parse it ([#5328](https://github.com/getsentry/sentry-java/pull/5328)) + ## 8.37.1 ### Fixes