Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- 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
7.69.0
Framework Version
React 17.0, NextJS 12.1.0
Link to Sentry event
https://ardian.sentry.io/issues/4480381245/
SDK Setup
No response
Steps to Reproduce
If a page's getInitialProps
function does not return an object, but rather undefined or null, Sentry will throw an exception on that page. This is because of this piece of code in wrapGetInitialPropsWithSentry.ts
:
const initialProps: {
_sentryTraceData?: string;
_sentryBaggage?: string;
} = await tracedGetInitialProps.apply(thisArg, args);
const requestTransaction = getTransactionFromRequest(req) ?? hub.getScope().getTransaction();
if (requestTransaction) {
initialProps._sentryTraceData = requestTransaction.toTraceparent();
const dynamicSamplingContext = requestTransaction.getDynamicSamplingContext();
initialProps._sentryBaggage = dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);
}
return initialProps;
The specific error is TypeError: Cannot set properties of undefined (setting '_sentryTraceData')
For context, I had a page's getInitialProps
returning undefined because I only used getInitialProps
to handle server-side redirections.
I don't know if this can easliy modified whilde still keeping the instrumentation, but the exception could at least be caught to not bubble up and crash the whole page.
Expected Result
Sentry doesn't throw an exception if getInitialProps
returns undefined
Actual Result
Sentry throws an exception if getInitialProps
returns undefined, crashing the whole page.
Metadata
Metadata
Assignees
Type
Projects
Status