Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(nextjs): remove tracing from pages router API routes#18394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
logaretm wants to merge12 commits intodevelop
base:develop
Choose a base branch
Loading
fromawad/js-1209-remove-tracing-from-pages-router-api-2

Conversation

@logaretm
Copy link
Collaborator

@logaretmlogaretm commentedDec 3, 2025
edited by github-actionsbot
Loading

This is a big PR because of the tests added, the logic changes themselves are pretty minimal, so make sure to filter out the files when reviewing.

Actual Changes

Removed traces fromwrapApiHandlerWithSentry for both the server runtime and the edge runtime

Tests Added

Since we are dropping explicit trace wrapping logic from the pages router templates, we needed to have tests on Next 16 to make sure the page router there still works in both Turbopack and Webpack with minimal differences in the quality of the traces.

We have around 36 test case to check, but only 20 can pass at this time due to the wrapping logic still present, ideally as we move towards removing templates entirely, we can then unskip those tests and tighten many of the assertions we have to accommodate for it.

I added TODOs and aTEST_STATUS.md document to detail what we should update once the SDK drops more of the wrapping logic it currently has.

Closes#18450 (added automatically)

sentry[bot] reacted with hooray emoji
@linear
Copy link

linearbot commentedDec 3, 2025

@logaretmlogaretmforce-pushed theawad/js-1209-remove-tracing-from-pages-router-api-2 branch 2 times, most recently from2af20e5 to2516846CompareDecember 3, 2025 10:49
@github-actions
Copy link
Contributor

github-actionsbot commentedDec 3, 2025
edited
Loading

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

ScenarioRequests/s% of BaselinePrev. Requests/sChange %
GET Baseline11,022-8,535+29%
GET With Sentry1,95418%1,608+22%
GET With Sentry (error only)7,85671%5,850+34%
POST Baseline1,145-1,166-2%
POST With Sentry57850%546+6%
POST With Sentry (error only)1,02289%1,023-0%
MYSQL Baseline4,044-3,188+27%
MYSQL With Sentry53013%427+24%
MYSQL With Sentry (error only)3,31382%2,607+27%

View base workflow run

@logaretmlogaretmforce-pushed theawad/js-1209-remove-tracing-from-pages-router-api-2 branch 3 times, most recently fromc055f2d to8102dd9CompareDecember 9, 2025 14:43
@logaretmlogaretm marked this pull request as ready for reviewDecember 10, 2025 08:45
CopilotAI review requested due to automatic review settingsDecember 10, 2025 08:45
Copy link
Contributor

CopilotAI 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 removes explicit tracing instrumentation from Pages Router API route wrappers (wrapApiHandlerWithSentry) for both Node.js server and Edge runtimes, relying instead on Next.js's built-in OpenTelemetry instrumentation to create transaction spans. The wrappers now only handle error capture, transaction name setting on isolation scope, and route backfilling.

Key Changes:

  • Removed manual span creation (startSpanManual,startSpan) from API route wrappers
  • Wrappers now set transaction names on isolation scope and use route backfill attributes for parameterized route names
  • Updated test expectations to reflect origin change from'auto.http.nextjs' to'auto' (from Next.js OTEL)
  • Added comprehensive Next.js 16 Pages Router test application with 36+ test cases

Reviewed changes

Copilot reviewed 74 out of 76 changed files in this pull request and generated 8 comments.

Show a summary per file
FileDescription
packages/nextjs/src/common/pages-router-instrumentation/wrapApiHandlerWithSentry.tsRemoved tracing logic; now only captures errors and sets transaction metadata via isolation scope and route backfill
packages/nextjs/src/edge/wrapApiHandlerWithSentry.tsRemoved tracing logic from edge runtime wrapper; simplified to error monitoring only
packages/nextjs/src/server/index.tsAddedSEMANTIC_ATTRIBUTE_SENTRY_SOURCE to route backfill logic to ensure proper transaction source attribution
packages/nextjs/test/config/withSentry.test.tsDeleted unit test that verified explicit span creation (no longer applicable)
dev-packages/e2e-tests/test-applications/nextjs-13/tests/**/*.test.tsUpdated assertions to expect'auto' origin instead of'auto.http.nextjs'
dev-packages/e2e-tests/test-applications/create-next-app/tests/**/*.test.tsUpdated assertions for new tracing behavior with flexible parent span matching
dev-packages/e2e-tests/test-applications/nextjs-pages-dir/tests/edge-route.test.tsRemoved runtime context assertions and skipped scope isolation test
dev-packages/e2e-tests/test-applications/nextjs-16-pages-dir/**/*New comprehensive test application with 36 test cases for Next.js 16 Pages Router covering both webpack and turbopack
dev-packages/e2e-tests/test-applications/nextjs-16-pages-dir/TEST_STATUS.mdDetailed documentation of test status, known issues, and future work items

💡Add Copilot custom instructions for smarter, more guided reviews.Learn how to get started.

Comment on lines 93 to 103
// as the runtime freezes as soon as the error is thrown below
awaitflushSafelyWithTimeout();

// We rethrow here so that nextjs can do with the error whatever it would normally do. (Sometimes "whatever it
// would normally do" is to allow the error to bubble up to the global handlers - another reason we need to mark
// the error as already having been captured.)
throwobjectifiedErr;
}
},
});
}

This comment was marked as outdated.

Copy link
CollaboratorAuthor

@logaretmlogaretmDec 10, 2025
edited
Loading

Choose a reason for hiding this comment

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

I switched to a blocking await here before throwing which should work better than callingwaitUntil then throwing as the runtime can shutdown as soon as an unhandled error like these are thrown.

This matches the logic we have in the other API handler wrapper.

@logaretmlogaretmforce-pushed theawad/js-1209-remove-tracing-from-pages-router-api-2 branch from949da51 tobdb4be3CompareDecember 16, 2025 10:08
@logaretmlogaretmforce-pushed theawad/js-1209-remove-tracing-from-pages-router-api-2 branch from6de8d44 to9c04b47CompareDecember 16, 2025 12:24
// Set transaction name on isolation scope to ensure parameterized routes are used
// The HTTP server integration sets it on isolation scope, so we need to match that
constmethod=event.request?.method||'GET';
path=path??event.request?.url??'/';
Copy link

Choose a reason for hiding this comment

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

Bug: Nullish coalescing won't handle empty path string

Thepath variable is assigned fromString(...).replace(...).trim() on line 161, which always returns a string (possibly empty""). On line 165,path = path ?? event.request?.url ?? '/' uses nullish coalescing (??), which only falls back fornull/undefined, not for empty strings. If the span name is exactly'executing api route (pages)' with no route suffix,path becomes"" and the fallback toevent.request?.url or/ never triggers. This results in malformed transaction names like"GET " instead of"GET /". Using the logical OR operator (||) would correctly handle empty strings.

Fix in Cursor Fix in Web

@logaretmlogaretm marked this pull request as draftDecember 16, 2025 14:34
@logaretmlogaretmforce-pushed theawad/js-1209-remove-tracing-from-pages-router-api-2 branch from4538dfe toecfe19bCompareDecember 16, 2025 20:18
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

@cursorcursor[bot]cursor[bot] left review comments

@chargomechargomeAwaiting requested review from chargome

+1 more reviewer

@sentrysentry[bot]sentry[bot] left review comments

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Remove tracing from Edge API handler Remove tracing from Pages Router API handler template feat(nextjs): remove tracing from pages router API routes

1 participant

@logaretm

[8]ページ先頭

©2009-2025 Movatter.jp