mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #334] [MERGED] fix: pages router instrumentation error reporting for api routes #486
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#486
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/334
Author: @james-elicx
Created: 3/7/2026
Status: ✅ Merged
Merged: 3/7/2026
Merged by: @james-elicx
Base:
main← Head:j-branch-4📝 Commits (4)
f24ee8etest: pages router instrumentation7b9d7d7fix error handlinga7ac963add pages route to app dir3235045fix api route type📊 Changes
7 files changed (+295 additions, -0 deletions)
View changed files
➕
examples/app-router-cloudflare/pages/index.tsx(+4 -0)📝
packages/vinext/src/server/api-handler.ts(+12 -0)➕
tests/e2e/pages-router/instrumentation.spec.ts(+136 -0)➕
tests/fixtures/pages-basic/instrumentation-state.ts(+63 -0)➕
tests/fixtures/pages-basic/instrumentation.ts(+44 -0)➕
tests/fixtures/pages-basic/pages/api/error-route.ts(+7 -0)➕
tests/fixtures/pages-basic/pages/api/instrumentation-test.ts(+29 -0)📄 Description
fix: instrumentation.ts Pages Router support + onRequestError for API routes
Extends instrumentation.ts support to Pages Router and fixes a gap where
onRequestErrorwas never called for API route errors.What changed
onRequestErrorin API route handlerapi-handler.tscaught errors from Pages Router API routes but never calledreportRequestError, soonRequestErrorwould silently not fire for anypages/api/*handler. Added the call in the catch block withrouterKind: "Pages Router"androuteType: "render".Pages Router fixture
tests/fixtures/pages-basicgetsinstrumentation.ts,instrumentation-state.ts,/api/instrumentation-test, and/api/error-routeto support the new e2e tests. The state module usesglobalThiskeys rather than plain module-level variables — necessary becauseregister()runs in an isolatedModuleRunnermodule graph (separate from the Vite SSR graph that handles API routes), so plain exports wouldn't be shared between them.Pages Router e2e spec
tests/e2e/pages-router/instrumentation.spec.tscovers:instrumentation.tsis present (regression guard for theoutsideEmittercrash)register()was called before the first requestonRequestError()fires when an API handler throws, with correctrouterKind/routeType/routePathonRequestErrorcloudflare-devadded to CI matrixThe
**cloudflare-dev` added to CI matrix**The
cloudflare-devPlaywright project was missing from the CI matrix despite existing inplaywright.config.ts. Added it so the Vite dev +@cloudflare/vite-pluginstartup tests run in CI.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.