Skip to content

Error thrown inside useEffect is not sent to Sentry only in Next.js production modeΒ #14768

@mikan3rd

Description

@mikan3rd

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

"next": "15.0.4"

Link to Sentry event

https://bizforward.sentry.io/issues/6155743438/events/a1389f97618147fa890ed7ec864d39ca/

Reproduction Example/SDK Setup

import * as Sentry from '@sentry/nextjs';

const SENTRY_ENABLED = process.env.NEXT_PUBLIC_SENTRY_ENABLED === 'true';
const SENTRY_DEBUG = process.env.NEXT_PUBLIC_SENTRY_DEBUG === 'true';
console.log({ SENTRY_ENABLED, SENTRY_DEBUG });

Sentry.init({
  dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
  environment: process.env.NEXT_PUBLIC_APP_ENV,
  sampleRate: 1,
  tracesSampleRate: 1,
  replaysSessionSampleRate: 1,
  replaysOnErrorSampleRate: 1,
  normalizeDepth: 10,
  tracePropagationTargets: [/^\//, '/api/graphql'],

  // https://docs.sentry.io/platforms/javascript/configuration/integrations/#modifying-default-integrations
  defaultIntegrations: false,
  integrations: [
    // default
    Sentry.breadcrumbsIntegration(),
    Sentry.browserApiErrorsIntegration(),
    // Sentry.dedupeIntegration(),  // disabled
    Sentry.functionToStringIntegration(),
    Sentry.globalHandlersIntegration(),
    Sentry.httpContextIntegration(),
    Sentry.inboundFiltersIntegration(),
    Sentry.linkedErrorsIntegration(),

    // trace
    Sentry.browserTracingIntegration(),

    // replay
    Sentry.replayIntegration({
      maskAllText: false,
      blockAllMedia: true,
      networkDetailAllowUrls: ['/api/graphql'],
      networkCaptureBodies: true,
    }),
  ],
  debug: SENTRY_DEBUG,
  release: process.env.NEXT_PUBLIC_SENTRY_RELEASE,
  enabled: SENTRY_ENABLED,
  beforeSend(event, hint) {
    const errorType = event.exception?.values?.[0]?.type ?? '';
    const errorMessage = event.exception?.values?.[0]?.value ?? '';
    const normalizedMessage = errorMessage.replace(/\d/g, '*');

    //   https://docs.sentry.io/platforms/javascript/guides/node/enriching-events/fingerprinting/#group-errors-with-greater-granularity
    event.fingerprint = ['{{ default }}', errorType, normalizedMessage];

    return event;
  },
});

Steps to Reproduce

  1. Write code in your application to throw an Error inside useEffect as follows.
  useEffect(() => {
    throw new Error('useEffect!!!!!');
  }, []);
  1. Start the application in development mode by next dev, and confirm that an error occurs in the relevant code and that an Issue is created in Sentry.

  2. Create the production build by next build, and start the application in production mode by next start, and confirm that an error occurs in the relevant code but that an Issue is not created in Sentry.

Expected Result

In Next.js production mode, Error should be sent to Sentry.

Actual Result

In Next.js production mode, error is not sent to Sentry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPackage: nextjsIssues related to the Sentry Nextjs SDK

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions