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

@sentry/nextjs v8 does not create issue/error on vercel for API Route Handler #12045

Closed
3 tasks done
TuanManhCao opened this issue May 15, 2024 · 6 comments · Fixed by #12133
Closed
3 tasks done

@sentry/nextjs v8 does not create issue/error on vercel for API Route Handler #12045

TuanManhCao opened this issue May 15, 2024 · 6 comments · Fixed by #12133

Comments

@TuanManhCao
Copy link

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.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-api I 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

cleanshot-2024-05-15-000328@2x

All work well in local env.

And strange thing is the client code for tracking error is working, meaning this page (see screenshot)
cleanshot-2024-05-15-000329@2x

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

cleanshot-2024-05-15-000330@2x

@s1gr1d
Copy link
Member

s1gr1d commented May 16, 2024

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?

@TuanManhCao
Copy link
Author

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

cleanshot-2024-05-17-000338@2x

@lforst
Copy link
Member

lforst commented May 21, 2024

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.

@TuanManhCao
Copy link
Author

Thanks @lforst ! Wondering if this is particular to vercel or just new version of @sentry/nextjs? Or combination of both?

@lforst
Copy link
Member

lforst commented May 21, 2024

@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.

@TuanManhCao
Copy link
Author

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants