Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nextjs): Don't put undefined values in props #12131

Merged
merged 1 commit into from
May 21, 2024
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
16 changes: 13 additions & 3 deletions packages/nextjs/src/common/wrapAppGetInitialPropsWithSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,20 @@ export function wrapAppGetInitialPropsWithSentry(origAppGetInitialProps: AppGetI
}

if (requestSpan) {
appGetInitialProps.pageProps._sentryTraceData = spanToTraceHeader(requestSpan);
const sentryTrace = spanToTraceHeader(requestSpan);

// The Next.js serializer throws on undefined values so we need to guard for it (#12102)
if (sentryTrace) {
appGetInitialProps.pageProps._sentryTraceData = sentryTrace;
}

const dynamicSamplingContext = getDynamicSamplingContextFromSpan(requestSpan);
appGetInitialProps.pageProps._sentryBaggage =
dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);
const baggage = dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);

// The Next.js serializer throws on undefined values so we need to guard for it (#12102)
if (baggage) {
appGetInitialProps.pageProps._sentryBaggage = baggage;
}
}

return appGetInitialProps;
Expand Down
14 changes: 12 additions & 2 deletions packages/nextjs/src/common/wrapErrorGetInitialPropsWithSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,20 @@ export function wrapErrorGetInitialPropsWithSentry(
const requestSpan = getSpanFromRequest(req) ?? (activeSpan ? getRootSpan(activeSpan) : undefined);

if (requestSpan) {
errorGetInitialProps._sentryTraceData = spanToTraceHeader(requestSpan);
const sentryTrace = spanToTraceHeader(requestSpan);

// The Next.js serializer throws on undefined values so we need to guard for it (#12102)
if (sentryTrace) {
errorGetInitialProps._sentryTraceData = sentryTrace;
}

const dynamicSamplingContext = getDynamicSamplingContextFromSpan(requestSpan);
errorGetInitialProps._sentryBaggage = dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);
const baggage = dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);

// The Next.js serializer throws on undefined values so we need to guard for it (#12102)
if (baggage) {
errorGetInitialProps._sentryBaggage = baggage;
}
}

return errorGetInitialProps;
Expand Down
14 changes: 12 additions & 2 deletions packages/nextjs/src/common/wrapGetInitialPropsWithSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,20 @@ export function wrapGetInitialPropsWithSentry(origGetInitialProps: GetInitialPro
const requestSpan = getSpanFromRequest(req) ?? (activeSpan ? getRootSpan(activeSpan) : undefined);

if (requestSpan) {
initialProps._sentryTraceData = spanToTraceHeader(requestSpan);
const sentryTrace = spanToTraceHeader(requestSpan);

// The Next.js serializer throws on undefined values so we need to guard for it (#12102)
if (sentryTrace) {
initialProps._sentryTraceData = sentryTrace;
}

const dynamicSamplingContext = getDynamicSamplingContextFromSpan(requestSpan);
initialProps._sentryBaggage = dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);
const baggage = dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);

// The Next.js serializer throws on undefined values so we need to guard for it (#12102)
if (baggage) {
initialProps._sentryBaggage = baggage;
}
}

return initialProps;
Expand Down
22 changes: 15 additions & 7 deletions packages/nextjs/src/common/wrapGetServerSidePropsWithSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,21 @@ export function wrapGetServerSidePropsWithSentry(

if (serverSideProps && 'props' in serverSideProps) {
const activeSpan = getActiveSpan();
const requestTransaction = getSpanFromRequest(req) ?? (activeSpan ? getRootSpan(activeSpan) : undefined);
if (requestTransaction) {
(serverSideProps.props as Record<string, unknown>)._sentryTraceData = spanToTraceHeader(requestTransaction);

const dynamicSamplingContext = getDynamicSamplingContextFromSpan(requestTransaction);
(serverSideProps.props as Record<string, unknown>)._sentryBaggage =
dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);
const requestSpan = getSpanFromRequest(req) ?? (activeSpan ? getRootSpan(activeSpan) : undefined);
if (requestSpan) {
const sentryTrace = spanToTraceHeader(requestSpan);

// The Next.js serializer throws on undefined values so we need to guard for it (#12102)
if (sentryTrace) {
(serverSideProps.props as Record<string, unknown>)._sentryTraceData = sentryTrace;
}

const dynamicSamplingContext = getDynamicSamplingContextFromSpan(requestSpan);
const baggage = dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext);
// The Next.js serializer throws on undefined values so we need to guard for it (#12102)
if (baggage) {
(serverSideProps.props as Record<string, unknown>)._sentryBaggage = baggage;
}
}
}

Expand Down
Loading