-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Description
Problem Statement
The captureUnderscoreErrorException function in @sentry/nextjs returns Promise<void>, but the underlying captureException it calls internally returns the event ID. This makes it impossible to display a "Reference ID" to users on custom error pages when using the recommended Next.js error handling pattern.
Use Case
In our Next.js _error.tsx page, we want to display a Sentry event ID to users so they can reference it when contacting support:
CustomError.getInitialProps = async (pageContext: NextPageContext) => {
// This doesn't return the event ID 😞
await Sentry.captureUnderscoreErrorException(pageContext);
// Sentry.lastEventId() also doesn't work in SDK v10.37.0 but works on SDK v8.3.0
const eventId = Sentry.lastEventId(); // Always undefined. WHY???
return { statusCode, eventId };
};Solution Brainstorm
We have to manually replicate what captureUnderscoreErrorException does internally:
const error = pageContext.err;
if (error) {
// This returns the event ID ✅
const eventId = Sentry.captureException(error, {
mechanism: {
type: 'instrument',
handled: false,
data: { function: '_error.getInitialProps' },
},
});
}Additional Context
Sentry.lastEventId()no longer works in newer SDK due to the new scope isolation model- This worked in older SDK versions where
lastEventId()was updated globally - The same issue likely applies to other
capture*wrapper functions that don't return the event ID
Proposed Solution
Update captureUnderscoreErrorException to return the event ID:
// Current
export async function captureUnderscoreErrorException(contextOrProps: unknown): Promise<void>
// Proposed
export async function captureUnderscoreErrorException(contextOrProps: unknown): Promise<string | undefined>Priority
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Projects
Status
Waiting for: Product Owner