Skip to content

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
fix/queue-instrumentation-kafka-enqueued-time-format
Open

fix(kafka): [Queue Instrumentation 31] Write enqueued-time header as plain decimal#5328
adinauer wants to merge 2 commits intotest/queue-instrumentation-kafka-record-interceptor-lifecyclefrom
fix/queue-instrumentation-kafka-enqueued-time-format

Conversation

@adinauer
Copy link
Copy Markdown
Member

@adinauer adinauer commented Apr 23, 2026

PR Stack (Queue Instrumentation)


📜 Description

Fix the sentry-task-enqueued-time Kafka header being serialized in scientific notation (e.g. 1.776933649613E9). The producer interceptor was writing the value via String.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 in SentryTransaction, 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 double toString — uses scientific notation for all realistic timestamps, which:

  • Python's sentry_sdk (and Ruby, PHP, .NET) Celery consumers parse the header with plain-decimal expectations, so they would fail to parse Java-produced headers.
  • The Java consumer (SentryKafkaConsumerTracing.receiveLatency) uses Double.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.doubleToBigDecimal helper.

💚 How did you test it?

  • Added regression assertions in SentryKafkaProducerInterceptorTest."creates queue publish span and injects headers" that:
    • reject scientific notation ('E'/'e' characters),
    • pin the plain-decimal format via ^\d+\.\d{6}$,
    • round-trip via 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

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

Port the same fix to the Spring Boot 4 and Spring Boot 2 Kafka interceptors once those stack PRs land.

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

…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
@sentry
Copy link
Copy Markdown

sentry Bot commented Apr 23, 2026

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.37.1 (1) release

⚙️ sentry-android Build Distribution Settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant