Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- feat(nextjs): Add `onRequestError` to `instrumentation.ts` (#659)
- feat(nextjs): Warn about Turbopack incompatibility (#657)
- feat(sveltekit): Add feature selection (#648)

Expand Down
15 changes: 12 additions & 3 deletions src/nextjs/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ YourCustomErrorComponent.getInitialProps = async (contextData${
export function getInstrumentationHookContent(
instrumentationHookLocation: 'src' | 'root',
) {
return `export async function register() {
return `import * as Sentry from '@sentry/nextjs';

export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('${
instrumentationHookLocation === 'root' ? '.' : '..'
Expand All @@ -382,14 +384,18 @@ export function getInstrumentationHookContent(
}/sentry.edge.config');
}
}

export const onRequestError = Sentry.captureRequestError;
`;
}

export function getInstrumentationHookCopyPasteSnippet(
instrumentationHookLocation: 'src' | 'root',
) {
return makeCodeSnippet(true, (unchanged, plus) => {
return unchanged(`export ${plus('async')} function register() {
return unchanged(`${plus("import * as Sentry from '@sentry/nextjs';")}

export ${plus('async')} function register() {
${plus(`if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('${
instrumentationHookLocation === 'root' ? '.' : '..'
Expand All @@ -401,7 +407,10 @@ export function getInstrumentationHookCopyPasteSnippet(
instrumentationHookLocation === 'root' ? '.' : '..'
}/sentry.edge.config');
}`)}
}`);
}

${plus('export const onRequestError = Sentry.captureRequestError;')}
`);
});
}

Expand Down
Loading