fix(kafka): [Queue Instrumentation 31] Write enqueued-time header as plain decimal#5328
Open
adinauer wants to merge 2 commits intotest/queue-instrumentation-kafka-record-interceptor-lifecyclefrom
Conversation
…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 <noreply@anthropic.com>
This was referenced Apr 23, 2026
Open
Open
📲 Install BuildsAndroid
|
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Stack (Queue Instrumentation)
📜 Description
Fix the
sentry-task-enqueued-timeKafka header being serialized in scientific notation (e.g.1.776933649613E9). The producer interceptor was writing the value viaString.valueOf(double), which switches to scientific notation once|d| >= 10^7— and epoch seconds are always~1.77 × 10^9.Route the value through
DateUtils.doubleToBigDecimal(...).toString()— the same helper already used to serialize epoch-seconds timestamps inSentryTransaction,SentrySpan,SentryLogEvent,SentryMetricsEvent,ProfileChunk, etc. At the pinned scale of 6,BigDecimal.toString()produces plain decimal form (1776938295.692000) for every realistic epoch-seconds magnitude.Addresses review7.md finding R7-F017 — the only remaining open review comment across the Queue Instrumentation stack (1–30).
💡 Motivation and Context
PR #5283 ("Align enqueue time with Python") was meant to make the Java Kafka queue instrumentation interoperable with other Sentry SDKs by switching the header payload to epoch seconds. However, the format it actually shipped — Java's default
doubletoString— uses scientific notation for all realistic timestamps, which:sentry_sdk(and Ruby, PHP, .NET) Celery consumers parse the header with plain-decimal expectations, so they would fail to parse Java-produced headers.SentryKafkaConsumerTracing.receiveLatency) usesDouble.parseDouble, which accepts both plain and scientific forms — so internal round-trips pass and none of the existing tests caught the bug.This PR closes the gap without a core API change by reusing the canonical
DateUtils.doubleToBigDecimalhelper.💚 How did you test it?
SentryKafkaProducerInterceptorTest."creates queue publish span and injects headers"that:'E'/'e'characters),^\d+\.\d{6}$,toDouble()../gradlew :sentry-kafka:test— all 7 producer-interceptor tests pass../gradlew :sentry-spring-jakarta:test --tests="*Kafka*"— green../gradlew spotlessApply apiDump— clean, no API surface changes.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Port the same fix to the Spring Boot 4 and Spring Boot 2 Kafka interceptors once those stack PRs land.