Skip to content

Preserve OTLP nanosecond timestamp precision#3751

Closed
RitwijParmar wants to merge 1 commit into
triggerdotdev:mainfrom
RitwijParmar:codex/otlp-nanosecond-precision
Closed

Preserve OTLP nanosecond timestamp precision#3751
RitwijParmar wants to merge 1 commit into
triggerdotdev:mainfrom
RitwijParmar:codex/otlp-nanosecond-precision

Conversation

@RitwijParmar
Copy link
Copy Markdown

Summary

  • reuse convertDateToNanoseconds() anywhere the webapp converts epoch milliseconds into OTLP nanosecond timestamps
  • move the remaining event repository and retry-event paths off float-first multiplication
  • add a regression test with an epoch millisecond value that loses precision when multiplied before BigInt conversion

Why

Fixes #3292. Multiplying epoch milliseconds by 1_000_000 before converting to BigInt crosses Number.MAX_SAFE_INTEGER and can introduce small nanosecond-level errors. Converting to BigInt first preserves exact span timestamps and duration calculations.

Verification

  • pnpm install --frozen-lockfile
  • pnpm exec prettier --check apps/webapp/app/v3/eventRepository/common.server.ts apps/webapp/app/v3/eventRepository/index.server.ts apps/webapp/app/v3/runEngineHandlers.server.ts apps/webapp/test/eventRepositoryNanoseconds.test.ts
  • git diff --check
  • node repro check confirms BigInt(ms * 1_000_000) differs from BigInt(ms) * 1_000_000n for 1_700_000_000_001

Local test note

I tried pnpm --filter webapp exec vitest run test/eventRepositoryNanoseconds.test.ts, but local collection is blocked before tests run because @trigger.dev/core/v3/isomorphic is not available until workspace packages are generated/built. Attempting pnpm --filter @trigger.dev/core build is currently blocked by existing generated database artifacts (../generated/prisma) plus an unrelated sharedRuntimeManager.ts exhaustiveness error.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 26, 2026

⚠️ No Changeset found

Latest commit: fe29b55

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

Hi @RitwijParmar, thanks for your interest in contributing!

This project requires that pull request authors are vouched, and you are not in the list of vouched users.

This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details.

@github-actions github-actions Bot closed this May 26, 2026
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ca8e0754-6f0d-4d78-9025-9863ad12c7c7

📥 Commits

Reviewing files that changed from the base of the PR and between 37eeaa3 and fe29b55.

📒 Files selected for processing (4)
  • apps/webapp/app/v3/eventRepository/common.server.ts
  • apps/webapp/app/v3/eventRepository/index.server.ts
  • apps/webapp/app/v3/runEngineHandlers.server.ts
  • apps/webapp/test/eventRepositoryNanoseconds.test.ts

Walkthrough

This pull request consolidates nanosecond timestamp conversion logic across the event repository module. Two helper functions in common.server.ts are refactored to delegate to convertDateToNanoseconds instead of performing inline BigInt calculations. The event repository and retry event handler are updated to import and use this shared helper when setting startTime for recorded events. A new test file validates the conversion functions with deterministic fake timers to ensure correct millisecond-to-nanosecond translation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

OTLP nanosecond timestamp overflow in webapp event repository

1 participant