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

Api route handler unhandled error not reported in sentry with sentry/nextjs since 8.36.0. Auto instrumentation doesn't work for app router api route handlers #14780

Open
3 tasks done
Yuripetusko opened this issue Dec 18, 2024 · 3 comments
Assignees
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Waiting for: Community

Comments

@Yuripetusko
Copy link

Yuripetusko commented Dec 18, 2024

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

8.42.0

Framework Version

react 18.3.1, next 14.2.4

Link to Sentry event

No response

Reproduction Example/SDK Setup

// apps/api/sentry-example-api/route.ts

import { NextResponse } from 'next/server'

export const dynamic = 'force-dynamic'

// A faulty API route to test Sentry's error monitoring
export const GET() {
  throw new Error('Sentry Example API Route Error')
  return NextResponse.json({ data: 'Testing Sentry Error...' })
}

Steps to Reproduce

@sentry/nextjs introduced a bug in version 8.36.0 that broke the auto instrumentation of nextjs api route handlers in next 14.2.4 (maybe other version too) App router.

The error in api route handler is not logged in sentry completly, and as soon as I downgrade to 8.33.0 it works fine. All version from 8.36.0 and up to the latest (8.42.0) have this bug.

Haven't investigated this deeper, but from a quick glance, perhaps this commit was when the issue was introduced?
#14084
Or this f9df1b4

Expected Result

For next: 14.2.4 api route handler unhandled error to be reported in sentry with latest @sentry/nextjs sdk

Actual Result

No error reported in Sentry

@s1gr1d
Copy link
Member

s1gr1d commented Dec 18, 2024

Hy, thanks for reporting this and also pinning down the version where this fails.
Based on the changelog it's probably one of those two PRs - we'll look into this.

@chargome
Copy link
Member

@Yuripetusko can't reproduce this, maybe there is a configuration issue. Can you provide a reproduction repository so we can better debug this?

@Yuripetusko
Copy link
Author

@Yuripetusko can't reproduce this, maybe there is a configuration issue. Can you provide a reproduction repository so we can better debug this?

Thanks for looking into it. I will re-test soon, as we discovered another issue that could have been the source of this problem all along. When using turbo as a build tool, you need to set env vars in turbo config to be exposed during build time, otherwise the values can be cached for previous builds so they are incorrect or undefined. and we were using process.env.VERCEL_ENV to conditionally enable sentry on production only. So will re-test with the latest sentry version of this is now fixed as we specified required env vars

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 Waiting for: Community
Projects
Status: Waiting for: Community
Development

No branches or pull requests

4 participants