Skip to content

fix: #2147 preserve sub-millisecond precision in trace waterfall timestamps#2158

Open
nquandt wants to merge 5 commits intohyperdxio:mainfrom
nquandt:fix/trace-waterfall-nanosecond-timestamps
Open

fix: #2147 preserve sub-millisecond precision in trace waterfall timestamps#2158
nquandt wants to merge 5 commits intohyperdxio:mainfrom
nquandt:fix/trace-waterfall-nanosecond-timestamps

Conversation

@nquandt
Copy link
Copy Markdown

@nquandt nquandt commented Apr 23, 2026

fix: #2147

Summary

Move parseTimestampToMs to src/utils.ts and import it in DBTraceWaterfallChart. Uses TimestampNano to avoid truncation from new Date().getTime(), preventing alignment errors when two events fall within the same millisecond.

Screenshots or video

Before:
image

After:
image

How to test locally or on Vercel

  1. Run the docker build for hyperdx-local
  2. Send some spans and traces with less than ms precision
  3. See alignment in waterfall before and after applying change.

References

#2147

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 23, 2026

@nquandt-mt is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 23, 2026

⚠️ No Changeset found

Latest commit: 3e95580

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

github-actions Bot commented Apr 23, 2026

PR Review

✅ No critical issues found.

The implementation correctly extracts sub-millisecond precision from nanosecond timestamps. The key formula in parseTimestampToMs:

ts.toDate().getTime() + (ts.getNano() % 1_000_000) / 1_000_000

toDate().getTime() supplies millisecond-precision epoch ms (validated by the "whole-millisecond component" test)
getNano() % 1_000_000 strips the ms portion, leaving sub-ms nanoseconds
— Dividing by 1_000_000 converts to fractional ms

⚠️ Minor floating-point note: At 2024-era timestamps (~1.7×10¹² ms), JS doubles retain ~4 decimal places of fractional ms, giving ~100 ns resolution. This is far better than the original ms precision and adequate for ordering, but not full nanosecond fidelity — acceptable given the use case.

  • The TimestampNano import is cleanly moved to utils.ts, and the sorting logic is simplified correctly.
  • Test coverage covers the critical cases (zero sub-ms, fractional sub-ms, combined ms+sub-ms, max sub-ms, ordering).
  • No dependency changes — timestamp-nano was already in the package.

@nquandt nquandt force-pushed the fix/trace-waterfall-nanosecond-timestamps branch from 8b9aa54 to 126f572 Compare April 23, 2026 14:35
@nquandt nquandt force-pushed the fix/trace-waterfall-nanosecond-timestamps branch from 126f572 to 32b4fd1 Compare April 23, 2026 16:51
@nquandt
Copy link
Copy Markdown
Author

nquandt commented Apr 24, 2026

After fighting with the Claude Code Review bot, I think this is in a good spot. I have no further changes at this time.

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.

HyperDX DBTraceWaterfallChart Truncates nanosecond/microsecond spans.

1 participant