Skip to content

Conversation

lforst
Copy link
Contributor

@lforst lforst commented Jul 11, 2024

This PR adds an experimental implementation of an error handler that can be used to capture errors for the onRequestError hook recently added to Next.js canary: vercel/next.js#67539

The handler can be added to the instrumentation.ts file as follows:

// instrumentation.ts
import * as Sentry from '@sentry/nextjs';

export async function register() {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    await import('./sentry.server.config');
  }

  if (process.env.NEXT_RUNTIME === 'edge') {
    await import('./sentry.edge.config');
  }
}

export const onRequestError = Sentry.experimental_captureRequestError;

Currently, Next.js requires a __NEXT_EXPERIMENTAL_INSTRUMENTATION=1 environment variable for this feature to work.

@lforst lforst changed the title feat(nextjs): Add experimental_captureRequestError feat(nextjs): Add experimental_captureRequestError for onRequestError hook Jul 12, 2024
@lforst lforst requested review from chargome and andreiborza July 12, 2024 08:33
Copy link
Member

@chargome chargome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@lforst lforst merged commit d67df35 into develop Jul 12, 2024
@lforst lforst deleted the lforst-nextjs-onrequesterrorwrapper branch July 12, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants