Skip to content

Conversation

@kishore03109
Copy link
Contributor

@kishore03109 kishore03109 commented Jun 27, 2025

Context

Good pre-read

Tracking of spans might be inaccurate as a time-of-day clock is subject to moving forward or backward due to NTP stepping and is subject to leap second adjustments. Using a monotonic clock allows us to have a more accurate measurement of elapsed time on a single node.

Did a similar fix for ASG

@vercel
Copy link

vercel bot commented Jun 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
starter-kit ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 27, 2025 9:36am

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@datadog-opengovsg
Copy link

Datadog Report

Branch report: fix_use_monotonic_clock_for_measuring_spans
Commit report: 3083fe3
Test service: starter-kit

✅ 0 Failed, 12 Passed, 0 Skipped, 11.9s Total Time

@kishore03109 kishore03109 marked this pull request as ready for review June 27, 2025 09:40
Copilot AI review requested due to automatic review settings June 27, 2025 09:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the accuracy of span measurements by switching from a time-of-day clock (Date.now()) to a monotonic clock (performance.now()).

  • Replaces Date.now() with performance.now() for better accuracy
  • Rounds the elapsed time for logging consistency
Comments suppressed due to low confidence (2)

src/server/trpc.ts:48

  • Ensure that the global 'performance' object is available in your server environment or is properly polyfilled, as some Node.js versions may not support it.
  const start = performance.now()

src/server/trpc.ts:55

  • [nitpick] Verify whether rounding the elapsed time to an integer is required for your use-case or if preserving fractional milliseconds would provide more precision.
  const durationInMs = Math.round(performance.now() - start)

@kishore03109 kishore03109 requested a review from karrui July 15, 2025 09:28
Copy link
Collaborator

@karrui karrui left a comment

Choose a reason for hiding this comment

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

Lgtm. Can add into knowledge base?

@karrui karrui merged commit ab1039e into main Jul 25, 2025
15 checks passed
@karrui karrui deleted the fix_use_monotonic_clock_for_measuring_spans branch July 25, 2025 01:40
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.

2 participants