-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@sentry/nextjs not reporting errors in next.js api routes #6450
Comments
Hi, are the logs you shared from running |
Also, can you share the logs with |
@lforst
In other words, if I run Next.js after building, error reporting works normally. However, when I run the development mode with the My scripts "scripts": {
"dev": "next dev",
"build": "tsc --noEmit && next build",
"start": "next start",
} the logs with debug: true in sentry.server.config.ts ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info - Loaded env from /Users/asdf/Projects/test-web/.env
Sentry Logger [log]: Initializing SDK...
Sentry Logger [log]: Integration installed: InboundFilters
Sentry Logger [log]: Integration installed: FunctionToString
Sentry Logger [log]: Integration installed: Console
Sentry Logger [log]: Integration installed: Http
Sentry Logger [log]: Integration installed: OnUncaughtException
Sentry Logger [log]: Integration installed: OnUnhandledRejection
Sentry Logger [log]: Integration installed: ContextLines
Sentry Logger [log]: Integration installed: Context
Sentry Logger [log]: Integration installed: Modules
Sentry Logger [log]: Integration installed: RequestData
Sentry Logger [log]: Integration installed: LinkedErrors
Sentry Logger [log]: Integration installed: RewriteFrames
Sentry Logger [log]: SDK successfully initialized
Sentry Logger [log]: [Tracing] Continuing trace dda07f49f5394bff9eaa9319f883b055.
Sentry Logger [log]: [Tracing] starting http.server transaction - GET /api/auth/[...nextauth]
Sentry Logger [log]: [Tracing] Finishing http.server transaction: GET /api/auth/[...nextauth].
Sentry Logger [log]: Flushing events...
Sentry Logger [log]: Done flushing events
Sentry Logger [log]: [Tracing] starting http.server transaction - GET /api/test
info - @sentry/nextjs is running with the autoInstrumentServerFunctions flag set, which means API routes no longer need to be manually wrapped with withSentry. Detected manual wrapping in /api/test.
Sentry Logger [log]: [Tracing] starting http.server transaction - GET /api/test
Sentry Logger [log]: [Tracing] Finishing http.server transaction: GET /api/test.
Sentry Logger [log]: Flushing events...
Sentry Logger [log]: Done flushing events
Error: API TEST
at handle (/Users/asdf/Projects/test-web/.next/server/pages/api/test.js:76:11)
at sentryWrappedHandler (/Users/asdf/Projects/test-web/node_modules/@sentry/nextjs/cjs/config/wrappers/withSentryAPI.js:62:14)
at /Users/asdf/Projects/test-web/node_modules/@sentry/nextjs/cjs/config/wrappers/withSentryAPI.js:132:37
at bound (node:domain:433:15)
at runBound (node:domain:444:12)
at sentryWrappedHandler (/Users/asdf/Projects/test-web/node_modules/@sentry/nextjs/cjs/config/wrappers/withSentryAPI.js:196:12)
at Object.apiResolver (/Users/jasdf/Projects/test-web/node_modules/next/dist/server/api-utils/node.js:363:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async NextNodeServer.runApi (/Users/asdf/Projects/test-web/node_modules/next/dist/server/next-server.js:474:9)
at async Object.fn (/Users/asdfProjects/test-web/node_modules/next/dist/server/next-server.js:736:37)
Sentry Logger [log]: Flushing events...
Sentry Logger [log]: Done flushing events
Sentry Logger [log]: [Tracing] starting http.server transaction - GET /api/auth/session
Sentry Logger [log]: [Tracing] starting http.server transaction - GET /api/auth/[...nextauth]
Sentry Logger [log]: [Tracing] Finishing http.server transaction: GET /api/auth/[...nextauth].
Sentry Logger [log]: Flushing events...
Sentry Logger [log]: Done flushing events |
Ok, I think I can somewhat reproduce this. I will put this on our backlog but just as a quick disclaimer fixing this is not gonna have a high priority. Dev mode is super sketchy in Next.js/Webpack and our priority is clearly in getting production builds to work smoothly. Thank you for surfacing this though! If you want to debug your Sentry SDK configuration I recommend just doing a production build locally. |
Bump. Seems like Nextjs api route handlers are still not supported automatically with Sentry. This would be a very nice nice-to-have 😄. |
I Have same issue, API routes dont handle and sentry.edge.config.ts dont call init |
What's the update on this @AbhiPrasad and @lforst? Actively blocking so will have to go with a solution like Highlight if this isn't going to be tackled by the team |
@Stefandasbach I assume you are talking about Next 13 app dir API routes right? #7228 The solution here is nontrivial, and we need to make sure that it is stable between versions considering there is no exposed error handler by the next.js framework we can hook into. Some of the complexity comes from:
For now you can manually wrap your API routes in a try-catch and using Sentry that way! I don't think anyone else offers an alternate solution to this right? I can't find another error monitoring solution that supports auto-wrapping nextjs 13 app dir API routes - but please correct me if I'm wrong. I'm going to try to get this bumped up in priority for the team! Thanks for your patience. |
I don’t think these emails were intended for PineSpire, fyi
Get Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: Abhijeet Prasad ***@***.***>
Sent: Monday, August 14, 2023 5:49:59 PM
To: getsentry/sentry-javascript ***@***.***>
Cc: Notices ***@***.***>; Manual ***@***.***>
Subject: Re: [getsentry/sentry-javascript] @sentry/nextjs not reporting errors in next.js api routes (Issue #6450)
One thing we should do is add a note to docs about this, and maybe add a snippet of how to do the try-catch. I will take care of that!
—
Reply to this email directly, view it on GitHub<#6450 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AYLVFC47AMNHJNUERUUP2MLXVK2SPANCNFSM6AAAAAASWTHCNY>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Hey @AbhiPrasad, appreciate the thoughtful response and insight.
|
@Stefandasbach While it is cool that the Next.js team added this hook, it does not meet our standards/requirements for instrumentation. Since we need more powerful instrumentation mechanisms to support features like distributed tracing and error and performance monitoring for individual routes/server components, as well as request context isolation we had to build our own webpack processing pipeline in order to properly instrument everything. This is where a lot of the complexity and development efforts come from. In the meanwhile, we started working on the route handlers for the app router. You can track the progress here: #8832 |
i have the same use case } catch (e) {
console.log('error occured in getSectionStreamViaEdge ', e);
Sentry.captureMessage('Something went wrong');
} |
@samipshah100 Yes, that should work for basic error monitoring functionality. (Note that it is not as simple as that so some things may get funky - like bleeding transaction information, bleeding breadcrumbs, weird tags and stuff like that) |
@Stefandasbach #8832 merging in should solve the majority of concerns here and means you don't have to set up an |
@Jay-flow sorry this issue got a bit messy because people misunderstood it. Are you still facing this problem in the newest version of the SDK? |
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you remove the label "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
Edit: My own fault. Resolution here: #6450 (comment) Responding here, but let me know if you'd rather I create a new issue. I'm not seeing my API endpoints getting auto instrumented. I was using a prior version of sentry and updated to take advantage of this improved autoinstrumentation. I've set Two things that could be causing issues:
Any help is appreciated!
|
@tomelliot Yes, would you mind creating a new issue for this? Thank you! |
@lforst In trying to create a reproduction I found this was my own fault: I was mistakenly using |
@tomelliot Awesome. Thanks for raising something upstream! I am wondering, are the API routes working at all if it is |
@lforst Yeah the misnamed endpoints seemed to be working fine - I had no reason to realise there was a problem. Maybe something to shake out with the Next.js team - are .tsx files meant to work or not. If they're not then it sounds like something they might want to update. |
Their docs say only .js and .ts. I'll chime in in the discussion you opened! https://nextjs.org/docs/app/building-your-application/routing/route-handlers#convention |
Version
@sentry/nextjs: 7.23.0
next: 13.0.6
Issue
@sentry/nextjs not reporting errors in next.js api routes
Only errors from the font-end are reported to Sentry.
Do not report API errors to Sentry.
pages/api/test.ts
I completed the setting according to the guide.
Below are the files I set up.
sentry.client.config.ts
sentry.server.config.ts
next.config.js
pages/_error.tsx
.sentryclirc
sentry.prooperties
Below is the log displayed on the console.
Expected Result
@sentry/nextjs should be reported to Sentry about API errors.
Actual Result
@sentry/nextjs not reporting errors in next.js api routes
Related Issues
#3917
The text was updated successfully, but these errors were encountered: