question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@sentry/nextjs not reporting errors in next.js api routes on vercel

See original GitHub issue

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other: @sentry/nextjs

Version:

6.17.3

Description

Errors from my frontend using the Throw Error button and errors from my api routes (/subscribe, /twitch) are not working. When pressing the Throw Error button referenced in your documentation, I do not see any network requests going to Sentry. In the api routes, I am seeing my fake error shown in the logs, but again nothing is sent to Sentry.

I have the following environment variables defined in Vercel.

SENTRY_DSN
SENTRY_PROJECT
SENTRY_ORG
SENTRY_URL
SENTRY_AUTH_TOKEN

You can view the source code in the repository, and check out the live demo on the website.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
lforstcommented, Nov 28, 2022

@rfdearborn Hi, admittedly that is a use case we haven’t fully explored yet.

The @sentry/nextjs SDK does a few things under the hood that you would need to do manually here.

First, you probably need to call Sentry.init() in the scope of your API route (not in the handler) so the SDK gets initialized. In the /pages folder this happens automatically.

Next, you will probably need to wrap your route handler in withSentryAPI. This is so that errors are properly recorded.

I haven’t actually done this yet but this is what I would try first. If you want and have the time you could open a separate issue so we can properly track this feature request and gauge interest.

1reaction
Jay-flowcommented, Dec 7, 2022

@Jay-flow we need more information. Can you open another issue with steps to reproduce your problem?

I wrote a new issue! https://github.com/getsentry/sentry-javascript/issues/6450

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js - Sentry Documentation
On this page, we get you up and running with Sentry's SDK, so that it will automatically report errors and exceptions in your...
Read more >
Next.js With Sentry Example - StackBlitz
This is an example showing how to use [Sentry]. (https://sentry.io) to catch and report. errors and monitor the performance of both.
Read more >
Advanced Features: Error Handling - Next.js
Handle errors in your Next.js app. ... It is only visible when the development server runs using next dev , npm run dev...
Read more >
Manual Setup for Next.js - DocBase AI Documentation
If you want to instrument Next.js API Routes , which run on serverless, ... done by @sentry/nextjs doesn't run, and therefore certain errors...
Read more >
Deploy and Monitor your Next.js Applications with ... - YouTube
Richard Propst (Solutions Engineer @Sentry) and Lee Robinson (Developer Relations @ Vercel ) walk through how to build, deploy, and monitor ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found