sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

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

Open TuanManhCao opened this issue 2 months ago • 5 comments

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

TuanManhCao avatar May 15 '24 12:05 TuanManhCao