sentry-javascript
sentry-javascript copied to clipboard
@sentry/nextjs v8 does not create issue/error on vercel for API Route Handler
Is there an existing issue for this?
- [X] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- [X] I have reviewed the documentation https://docs.sentry.io/
- [X] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
8.0.0
Framework Version
nextjs ^14.2.3
Link to Sentry event
No response
SDK Setup
// My setup is in src/instrumentation.ts
import * as Sentry from '@sentry/nextjs'
export async function register() {
const SENTRY_DSN = process.env.SENTRY_DSN ?? process.env.NEXT_PUBLIC_SENTRY_DSN
console.log('🚀 ~ register ~ register:', SENTRY_DSN)
Sentry.init({
dsn: "https://[email protected]/somenumber",
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: false
// uncomment the line below to enable Spotlight (https://spotlightjs.com)
// spotlight: process.env.NODE_ENV === 'development',
})
}
my nextjs config
const { withSentryConfig } = require("@sentry/nextjs");
/** @type {import('next').NextConfig} */
const nextConfig = {
images : {
// my nextjs config...
}
}
module.exports = withSentryConfig(
nextConfig,
{
org: "my-org",
project: "my-project",
authToken: process.env.SENTRY_AUTH_TOKEN,
}
);
// src/app/api/sentry-example-api/route.ts
import { NextResponse, NextRequest } from "next/server";
export const dynamic = "force-dynamic";
// A faulty API route to test Sentry's error monitoring
export async function GET(request: NextRequest, response: NextResponse) {
throw new Error("Sentry Example API Route Error");
return NextResponse.json({ data: "Testing Sentry Error..." });
}
Steps to Reproduce
When i visit /api/sentry-example-api on localhost I see the error is tracked correctly in my sentry's dashboard's issues
However when I deployed the code to vercel cloud, I checked that the source map is uploaded correctly, the env variable for dsn, auth_token, all setup correctly (via console.log())
Step to reproduce:
- When I visited the
/api/sentry-example-apiI saw the page show 500 error, checked vercel log, it does thow the error - But I cannot see the error show up in sentry's issue dashboard
All work well in local env.
And strange thing is the client code for tracking error is working, meaning this page (see screenshot)
Any idea?
Expected Result
The error for API route should show up in sentry dashboard
Actual Result
Right now the error does not show up in sentry dashboard
Hello, thanks for reaching out! Do you start your app with next dev or next start? Does the error show up in Sentry if you run the local production build with next build and next start?
Thanks @s1gr1d .
I just tried to do a next build then do a next start on my local machine and do see error getting tracked in sentry
As you can see in this screenshot, the env is production, and the host is localhost:3000
Hi, I just looked into this and my suspicion is that Vercel is freezing lambdas before we are able to flush out events. I looked into using waitUntil but that seems buggy right now so I reached out to Vercel directly. I hope they will clear things up but this is definitely top of my mind.
Thanks @lforst ! Wondering if this is particular to vercel or just new version of @sentry/nextjs? Or combination of both?
@TuanManhCao I am honestly not sure. It might be that vercel changed something or that the SDK now requires a tad longer to flush, causing us to run into the limit. I am optimistic however that using waitUntil will solve our problems. To me this seems to be a bug in Vercel that needs to be figured out.
@lforst it's awesome to see that this issue is resolved so quickly. Thanks Luca!
Can you elaborate a little bit more? As in, do I need to do anything on my side to make this work?
Or should I just wait for next version coming out? If yes, which version I should be looking out for?
Thanks!