test(nextjs): Add test case to assert no duplicate root spans for pages router - #22784
test(nextjs): Add test case to assert no duplicate root spans for pages router#22784logaretm wants to merge 2 commits into
Conversation
9b79719 to
6f31175
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6f31175. Configure here.
| const response = await request.get('/api/endpoint'); | ||
| expect(await response.json()).toStrictEqual({ name: 'John Doe' }); | ||
|
|
||
| await Promise.race([collectorPromise, new Promise(resolve => setTimeout(resolve, 6000))]); |
There was a problem hiding this comment.
Flaky timeout-based transaction wait
Medium Severity
Flagged because the review rules call out timeouts/sleeps in telemetry waits as flake-prone. The collector always returns false, so the race always falls through to a fixed 6s setTimeout instead of a concrete signal (for example waiting for the first matching transaction, then a short follow-up window for duplicates). Under CI load that can false-fail when the first envelope is slow, or false-pass if a second root transaction arrives after the grace period.
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 6f31175. Configure here.
There was a problem hiding this comment.
we can probably remove the race here indeed as this can never resolve, so just doing await new Promise(...setTimeout) is probably a bit clearer 🤔
mydea
left a comment
There was a problem hiding this comment.
small comment for the test but overall good coverage!
6f31175 to
e5c22da
Compare
Guards against duplicate root transactions for pages-router API routes: Next.js's own BaseServer.handleRequest transaction and the one created by wrapApiHandlerWithSentry must never both be sent for a single request.
e5c22da to
b4932be
Compare


Adds a test to verify the changes in subsequent PRs #18394 and #22685
It asserts we do not produce duplicate root transactions, I have run this against each PR and it verified the outcome:
startSpancall that forces the second transaction