Repository navigation
[SDK-801] Document reporting errors from Next.js proxy/middleware (#125) - #186
Open
devtools-agent[bot] wants to merge 1 commit into
Open
devtools-agent[bot] wants to merge 1 commit into
devtools-agent[bot] wants to merge 1 commit into
Conversation
Issue #125: calling the server instance from Edge middleware fails with "post_client_item scope is required" because on the Edge runtime the bundler resolves `rollbar` to its browser build, which sends browser items that a post_server_item token cannot post. - Add src/proxy.ts to the nextjs-approuter example. Next.js 16 runs proxy.ts on the Node.js runtime, so it gets the server build and the server token works. Request data is passed per call instead of via rollbar.configure(), which would mutate the shared instance. - Document the proxy pattern and the Edge middleware options (proxy.ts, runtime: 'nodejs', or a client-token instance). - Fix the example README's env var names to match src/rollbar.ts. Closes #125 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
AI Agent Review (openai, openai-astra)Review: document reporting from Next.js
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linear: SDK-801 · Closes #125
What changed
examples/nextjs-approuter/src/proxy.ts(new): reports errors with the sharedserverInstance. Amatcherlimits it to a/proxy_errordemo route, which throws, reports to Rollbar and returns a 500. Request data goes in per call (rollbar.error(err, { pathname })) and not throughrollbar.configure(), becauseconfigure()would change the instance every concurrent request shares. That was the pattern in the original issue.examples/nextjs-approuter/README.md: new section Reporting errors fromproxy.ts(formerlymiddleware.ts) that explains the Edge-runtime 403 and gives three options: rename toproxy.tson Next 16, useruntime: 'nodejs'on Next 15.5 and later, or create a separatenew Rollbar(clientConfig)instance if the middleware has to stay on Edge. The env var names in the README snippet now matchsrc/rollbar.ts(NEXT_PUBLIC_ROLLBAR_CLIENT_TOKEN/ROLLBAR_SERVER_TOKEN); before, the snippet used different names than the code.README.md: one paragraph under Using with Next.js App Router that links to the new section.src/__tests__/proxy.test.tsx(new): checks that the proxy reports throughserverInstancewith per-call data, never callsconfigure(), returns a 500 on the demo route and passes other requests through.Why
#125 is a docs/example gap, not an SDK bug. On the Edge runtime the bundler resolves
rollbarthrough thebrowserexport condition, so middleware gets the browser build. That build sendsplatform: browseritems, and the API rejects them when they come with apost_server_itemtoken.Validation
Run against Next 16.3.8 and rollbar 3.1.0, with
endpointtemporarily pointed at a local listener so the payloads could be inspected:middleware.ts(Edge, default)rollbar-browser-jsplatform: browser→ 403 on the real API (reproduces #125)middleware.ts+runtime: 'nodejs'node_rollbarproxy.ts(this PR)node_rollbarnext buildandnext startwith the newproxy.ts:GET /proxy_errorreturned 500 and sent onenode_rollbaritem;GET /returned 200 and sent nothing.jest --ci: 4 suites and 5 tests pass.eslint . --max-warnings 0andtsc --noEmitpass, and prettier passes on the changed files.🤖 Generated with Claude Code