Skip to content

Drew/trace duration unit test fix - #3280

Closed
pulpdrew wants to merge 22 commits into
mainfrom
drew/trace-duration-unit-test-fix
Closed

pulpdrew wants to merge 22 commits into
mainfrom
drew/trace-duration-unit-test-fix

Conversation

@pulpdrew

@pulpdrew pulpdrew commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Screenshots or video

Before After

How to test on Vercel preview

Preview routes:

Steps:

References

  • Linear Issue:
  • Related PRs:

milansanjeev and others added 22 commits September 1, 2026 17:23
DBSearchPage's Results Table view shows scanned rows/elapsed time next to
the results, but when viewing a single trace (directTraceId set) there is
no glanceable total wall-clock duration or span count for that trace --
users have to open the trace waterfall to see it (#3038).

Adds useTraceTotalDuration, which issues a small aggregate query
(MIN/MAX/COUNT over the trace's spans) using the resolved source's
timestamp/duration/traceId expressions, mirroring the existing
DBTraceWaterfallChart getConfig pattern for embedding the traceId
(SqlString.escape) into a raw SQL where clause. Renders as a
TraceTotalDurationStat next to SearchNumRows.
Addresses the changeset-bot note on #3051 so this user-visible Search
stats-row addition is included in the next @hyperdx/app version bump.
…aterfall view

Move the #3038 stat out of DBSearchPage's Results Table (where the
displayed rows/spans can diverge from the actual trace scope once the
user edits the search -- a bad place for a "total trace duration" figure
to live) and into DBTraceWaterfallChartContainer instead, where the
trace's full span set is already fetched for the waterfall itself.

Computes MIN(start)/MAX(start+duration)/span count directly from the
already-fetched `rows` (client-side, no extra query), consistent with
how the waterfall bars already compute each span's own offset/duration
(parseTimestampToMs + Duration*1000). Only counts spans, not correlated
logs. Renders next to the existing "N spans, N errors" text in the
waterfall controls bar.

Reverts the earlier DBSearchPage.tsx placement and removes the
now-unused useTraceTotalDuration hook/query.
- Drop the span count from the new stat -- it duplicated the existing
  "N spans, N errors" text with a different scope (all fetched spans vs.
  the visible/toggled subset), producing contradictory lines like
  "0 spans, 1 error · Total Duration: 2.28s · 12 spans" once the user
  toggles a chip or applies a filter. Fold the stat into the same <Text>
  as the existing count instead of a separate floating element.
- Rename "Total Duration" to "Total duration" (sentence case, per
  AGENTS.md UI text convention); update matching test assertions.
- Surface the trace query's 50k-row-per-window cap: propagate an
  `isTruncated` flag from useEventsAroundFocus through
  useFilteredEventsAroundFocus into the container, and append a "+" to
  the displayed duration when either window hit the cap, instead of
  silently presenting a partial total as exact.
- Add tests: log exclusion no longer relies on a same-timestamp log row
  (uses a log timestamped an hour later, which would blow up the
  reported duration if wrongly included); overlapping-spans case where
  the true MAX(end) span is not the last one processed (catches a
  "last write wins" bug the non-overlapping fixture couldn't); chip
  toggling doesn't change the stat (proves it reflects all fetched
  spans, not the visible subset); isTruncated flagging via a cheap
  length-only mock in useEventsAroundFocus rather than a real
  50k-row render (which timed out in jsdom).
Fetch one extra waterfall row so a complete window of exactly 50,000
spans is not marked truncated. Compute duration from span rows only,
drop the unused spanCount field, document wall-clock vs MCP, and
explain the lower-bound marker with a tooltip.
…k on trace total duration

- Fix TS2339: traceRowsData's static row type doesn't expose Duration
  (useEventsAroundFocus builds it via an object-literal spread of an
  any-typed ClickHouse row plus explicit re-declared keys, so TS infers
  the element type from only the explicit keys). Cast to any[] for the
  loop, matching the existing any-typed access pattern used elsewhere in
  this file (rows.reduce, visibleNodes.map) for the same dynamic shape.

- Extend the lower-bound/truncation marker to also fire when the +/-1h
  dateRange fetch window itself clips the trace (a span starting at/before
  the window's lower edge, or ending at/after its upper edge), not just
  the TRACE_WATERFALL_ROW_LIMIT row cap. Previously a trace clipped by the
  focus window reported a confident-looking exact duration with no
  indication data was missing. Generalize the tooltip copy to cover both
  triggers.

- Add tests for the new window-edge behavior (lower edge, upper edge, and
  the not-clipped case), run through the full render chain.

- Widen the test file's shared mockDateRange/mockFocusDate, which never
  actually overlapped the mock span/log timestamps used by the existing
  duration tests (harmless before this change, since nothing previously
  compared row timestamps against dateRange) so the new window-edge check
  doesn't spuriously trip on unrelated tests.
The row type dropped Duration after spreading a Record, and comparing the
earliest start to the window start never sees an earlier span. Treat a
missing parent on the earliest span, or a span that runs to the window end,
as a lower bound, and keep trimmed query windows stable across renders.
…rent

A parent that was never exported is a gap in the trace when the child starts inside the fetch window, and an empty parent id is a real root. The lower-bound marker now follows a start pressed against the window, or a span that runs to the window end.

Co-authored-by: Cursor <cursoragent@cursor.com>
The 1ms window-edge tolerance missed a root that started before the window and flagged a span that only started on the edge. A parent id on the earliest loaded span that was not fetched is the start clip.
@changeset-bot

changeset-bot Bot commented Oct 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4cb4f62

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

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

@vercel

vercel Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Oct 3, 2026 6:21pm UTC
hyperdx-storybook Ready Ready Preview Oct 3, 2026 6:21pm UTC

Request Review

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 127 in total (1.79%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Adds trace duration display to waterfall chart UI.

The PR is not ready to merge because an incomplete trace can display an apparently exact duration; the explicit typing requirement also needs to be met.

Fix All in Claude CodeFindings

  1. P1 Missing ancestor goes unmarked ▶
  2. P2 Complete trace marked incomplete ▶
  3. P2 New fallback uses any ▶

Summary

The PR adds a fetched-span wall-clock duration to the trace waterfall controls and marks durations considered incomplete.

  • Adds per-window row trimming and tests for duration calculation and clipping.
  • The start-clipping check can miss an unfetched ancestor; the end-clipping check can mark a complete trace as incomplete.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Q[Before and after trace queries] --> R[Fetched span rows]
  R --> C[Trim rows per window]
  C --> E[Find earliest start and latest end]
  E --> D[Format total duration]
  C --> T[Row-cap marker]
  E --> W[Window-clipping marker]
  T --> D
  W --> D
Loading

Reviews (1) · Last reviewed commit: "test: Fix slow test"

Comment on lines +827 to +834
if (startMs < minStartMs) {
minStartMs = startMs;

// The start is clipped if the earliest span has a parent that was not fetched
const parentId =
typeof row.ParentSpanId === 'string' ? row.ParentSpanId : '';
isStartClipped = parentId.length > 0 && !validSpanIDs.has(parentId);
}

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.

P1 Missing ancestor goes unmarked

If the earliest fetched span is a root but a later span's parent started before the selected time range, this code never checks the later span's missing parent. The displayed duration omits that earlier work but has no + marker, so an incomplete trace appears to have an exact duration.

Knowledge Base Used: Trace investigation

Fix in Claude Code Fix in Conductor Fix in Cursor Fix in Codex

}

if (endMs > maxEndMs) maxEndMs = endMs;
if (endMs >= windowEndMs) isEndClipped = true;

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.

P2 Complete trace marked incomplete

A span ending at or after the selected range's upper edge sets the + marker even when every span was fetched. Ending at that edge does not establish that the trace is incomplete, so users can be told a complete duration is only a lower bound.

Knowledge Base Used: Trace investigation

Fix in Claude Code Fix in Conductor Fix in Cursor Fix in Codex


// Stable empty fallback. `data ?? []` would allocate a new array every render
// and invalidate every memo downstream of the waterfall rows.
const EMPTY_ROWS: Record<string, any>[] = [];

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.

P2 New fallback uses any

The new EMPTY_ROWS declaration uses Record<string, any>[], which discards type checks for rows passed downstream. The repository's code-style directive says to avoid any and use proper typing; this requirement needs to be satisfied before merging.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Conductor Fix in Cursor Fix in Codex

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 393 passed • 1 skipped • 1127s

Status Count
✅ Passed 393
❌ Failed 0
⚠️ Flaky 1
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@pulpdrew pulpdrew closed this Oct 3, 2026

This branch was successfully deployed

2 active deployments
Preview – hyperdx-oss — 4cb4f625 Deployed Oct 3, 2026 by vercel[bot]
Preview – hyperdx-storybook — 4cb4f625 Deployed Oct 3, 2026 by vercel[bot]
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.

3 participants