Skip to content

feat(trace): Correct clock drift between client and server spans - #132010

Open
Lms24 wants to merge 21 commits into
masterfrom
lms/feat-trace-clock-drift-correction
Open

Lms24 wants to merge 21 commits into
masterfrom
lms/feat-trace-clock-drift-correction

Conversation

@Lms24

@Lms24 Lms24 commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

This PR adds clock drift correction to the trace waterfall, gated behind the trace-waterfall-clock-drift-correction flag.

When the clocks of a client and a server are not in sync, a server span can show up before or after the client request that caused it. This happens often on client-side apps, when user devices are (temporarily) out of sync or correting to NTP time or they their clocks manually. With getsentry/sentry-javascript#23054 in the JS SDK, we now more often adjust our telemetry togimestamps to the users' wall clock (it's the only somewhat reliable clock in browsers), which likely increased the amount of out-of-sync client and server span trees.

The correction shifts the server subtree into the client span that made the request. It can be toggled in the trace preferences and is off by default. Shifted spans show a clock icon on the subtree root, and their duration label and the details panel explain the shift on hover. The criteria for applying the clock drift correction are:

  • the span pairs to check are http.client followed by a http.server child segment
  • the server span started or finished outside of the client span, with a 10ms margin
  • the server span's duration fits into the client span's duration
  • requests are grouped by the client segment that made them, and only the shift most of a segment's requests agree on is applied (mental model: one segment shares one clock)

Clock drift makes traces across services hard to read, and the correction fixes the most common case. We want to try it with a few internal orgs first.

Screenshots

Clock drift correction toggle (off)

image

Clock drift correction toggle (on)

image

Raw waterfall (note the 2 min. drift)

image

Corrected waterfall

image

Waterfall tooltip

image

Detail panel tooltip

image

Testing

Some traces if anyone wants to check out the preview:

Flag: #132009. Rollout: getsentry/sentry-options-automator#10726.

🤖 Generated with Claude Code

@Lms24
Lms24 added this pull request to stack #132012 November 20, 2026 14:18
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Nov 20, 2026
@Lms24 Lms24 changed the title lms/feat trace clock drift correction feat(trace): Correct clock drift between client and server spans Nov 20, 2026
@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

📊 Type Coverage Diff

✅ no issues found

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@Lms24
Lms24 force-pushed the lms/feat-trace-clock-drift-correction branch from 40e68bb to 7e0fa52 Compare November 27, 2026 13:30
@Lms24 Lms24 self-assigned this Nov 27, 2026
@Lms24
Lms24 removed this pull request from stack #132012 November 27, 2026 13:53
@Lms24
Lms24 force-pushed the lms/feat-trace-clock-drift-correction branch from f2e5703 to 194eb38 Compare November 27, 2026 13:53
@Lms24
Lms24 changed the base branch from master to lms/ref-trace-center-duration-labels November 27, 2026 13:53
Lms24 and others added 10 commits November 30, 2026 10:00
The renderer and the trace styles imported them from the indicator
components, pulling a React module into the renderer.

Co-Authored-By: Claude <noreply@anthropic.com>
Bolds the corrected span count with Text instead of a raw strong, and
uses t over tct where only strings are interpolated.

Co-Authored-By: Claude <noreply@anthropic.com>
The tree keeps the count of corrected spans now, so nothing outside the
tests collected the corrections anymore.

Co-Authored-By: Claude <noreply@anthropic.com>
…pans

Clock drift correction moves a span in the waterfall, but its profiles
and issues are stored at the time it was recorded. The continuous
profile links and the issues link built their time range from the
moved space, which could open a range without the span's data.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Autogroups in a corrected subtree are shifted along with the spans they
wrap, but the duration label of a group with several bars did not get
the tooltip explaining the shift.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Span bar issue icons were placed only when their row rendered. After a
zoom or pan, an icon kept the edge anchoring of the old view, while the
duration label was placed for the current one, so the two could overlap.
Redraw the icons with the bars, as autogrouped bars already do.

Co-Authored-By: Lukas Stracke <lukas.stracke@sentry.io>
The issues link queried the trace node's recorded space, but the trace
node is never shifted while its space is rewritten to the corrected
bounds. Issues on server spans moved by clock drift correction fell
outside the link's time range. Query the recorded range of the node and
all of its drifted descendants instead.

Co-Authored-By: Lukas Stracke <lukas.stracke@sentry.io>
The sentence wrapped in the default 225px tooltip, which left wide
empty space on both sides compared to other tooltips.

Co-Authored-By: Lukas Stracke <lukas.stracke@sentry.io>

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One gap left, in the same class as the issues-link fix:

tracePinnedAttribute.tsx (not touched here) builds its /events/ query range from tree.root.space. With correction on, refreshTraceSpace shrinks the root space to the corrected bounds, so server spans that were recorded outside them (e.g. the 2 min drift in the screenshots) fall out of the range. Their pinned attribute values then go missing for exactly the shifted spans. Using getRecordedSubtreeSpace(tree.root) for start/end should cover them, ideally with a test that pins an attribute on a shifted server span.

Everything else looks good. The consensus logic, the pageload swap ordering, autogroup and missing-instrumentation offsets, the preference storage when the flag is off, and the profile and issue link ranges all hold up, and the earlier threads are addressed.

Pinned attribute values were queried over the trace space, which clock
drift correction rewrites to the corrected bounds. Spans moved by the
correction were recorded outside of it, so their values were missing.
The tree now keeps the range its spans were recorded in, also for
appended trees, and the query uses it.

Co-Authored-By: Lukas Stracke <lukas.stracke@sentry.io>

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in fd8b4352e97. The tree now keeps recorded_space, the range its spans were recorded in. refreshTraceSpace sets it and appendTree merges it, and the pinned attribute query reads it. It's a plain field instead of a getRecordedSubtreeSpace(tree.root) call in the hook, because the React Compiler memoizes that call on tree.root and would serve a stale range after the tree changes in place. Looks good to me otherwise.

@github-actions

Copy link
Copy Markdown
Contributor

Story previews

Preview the stories changed in this PR on the Vercel deployment:

Preview deployment: https://sentry-fz4181qx4.sentry.dev

@Lms24
Lms24 marked this pull request as ready for review November 30, 2026 13:29
@Lms24
Lms24 requested review from a team as code owners November 30, 2026 13:29
@nsdeschenes
nsdeschenes requested review from nsdeschenes and removed request for a team November 30, 2026 13:52

This branch was successfully deployed

1 active deployment
Preview — fd8b4352 Deployed Nov 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant