Skip to content
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

Next.js SSR unhandled errors are not logged #9152

Closed
3 tasks done
curiousercreative opened this issue Oct 2, 2023 · 6 comments · Fixed by #9388
Closed
3 tasks done

Next.js SSR unhandled errors are not logged #9152

curiousercreative opened this issue Oct 2, 2023 · 6 comments · Fixed by #9388
Assignees
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug

Comments

@curiousercreative
Copy link

curiousercreative commented Oct 2, 2023

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

7.73.0

Framework Version

Next.js 13.5.3

Link to Sentry event

No response

SDK Setup

No response

Steps to Reproduce

  1. Install NextJS example, enter project dir and init git repo (seems to be required for sentry wizard)
    npx create-next-app@latest nextjs-blog --use-npm --example "https://github.com/vercel/next-learn/tree/main/basics/learn-starter"
    cd nextjs-blog/
    git init
  2. Install sentry
    npx @sentry/wizard@latest -i nextjs
  3. Modify the home page to make it SSR rather than SSG and throw an error server-side during page component render.
    export function getServerSideProps () {
      return {
        props: {
          a: 'b',
        }
      }
    }
    
    export default function Home() {
      if (typeof window === 'undefined') throw new Error('server-side error')
      else throw new Error('client-side error')
    
      return <div></div>
    }
    
  4. Build, start, and load page at http://localhost:3000
    npm run build && npm start

Expected Result

I expected at least the server-side error to be logged in Sentry. I wouldn't be surprised if both a server-side and client-side error were logged per page load.

Actual Result

No errors are logged in sentry

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Oct 2, 2023
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label Oct 2, 2023
@curiousercreative
Copy link
Author

captureException does work, so that may be a viable workaround for some

@Lms24
Copy link
Member

Lms24 commented Oct 4, 2023

Hi @curiousercreative thanks for reporting! Backlogging to investigate this further (currently too busy with other tasks). If you want to help speed this up, we'd greatly appreciate a minimal reproduction as a GH repo. Only asking because your repro steps make it seem like you already set up a minimal repro project.

@curiousercreative
Copy link
Author

@Lms24 I've added a reproduction repo here: https://github.com/CommonEnergy/sentry-next-ssr

To repro:

  1. Clone repo
    git clone https://github.com/CommonEnergy/sentry-next-ssr.git
    cd sentry-next-ssr
    
  2. Add a .env or .env.local file to repo root with a NEXT_PUBLIC_SENTRY_DSN defined
  3. Build and start the app
    npm run build
    npm start
    
  4. Open in browser http://localhost:3000

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Oct 11, 2023
@lforst
Copy link
Member

lforst commented Oct 13, 2023

Hey thanks for opening this issue. This is mind-blowing to me. We are instrumenting getServerSideProps but never considered instrumenting the actual page if it is run on the server. This is something we need to fix.

@getsantry getsantry bot removed the status in GitHub Issues with 👀 Oct 13, 2023
@lforst lforst self-assigned this Oct 13, 2023
@curiousercreative
Copy link
Author

@lforst we should also investigate whether the app router (where server components are the default) is affected and make sure those pages are similarly instrumented.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 Oct 13, 2023
@lforst
Copy link
Member

lforst commented Oct 13, 2023

@curiousercreative In the app-router we have this for sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants