File tree Expand file tree Collapse file tree 4 files changed +52
-14
lines changed
packages/nextjs/src/common Expand file tree Collapse file tree 4 files changed +52
-14
lines changed Original file line number Diff line number Diff line change @@ -56,10 +56,20 @@ export function wrapAppGetInitialPropsWithSentry(origAppGetInitialProps: AppGetI
56
56
}
57
57
58
58
if ( requestSpan ) {
59
- appGetInitialProps . pageProps . _sentryTraceData = spanToTraceHeader ( requestSpan ) ;
59
+ const sentryTrace = spanToTraceHeader ( requestSpan ) ;
60
+
61
+ // The Next.js serializer throws on undefined values so we need to guard for it (#12102)
62
+ if ( sentryTrace ) {
63
+ appGetInitialProps . pageProps . _sentryTraceData = sentryTrace ;
64
+ }
65
+
60
66
const dynamicSamplingContext = getDynamicSamplingContextFromSpan ( requestSpan ) ;
61
- appGetInitialProps . pageProps . _sentryBaggage =
62
- dynamicSamplingContextToSentryBaggageHeader ( dynamicSamplingContext ) ;
67
+ const baggage = dynamicSamplingContextToSentryBaggageHeader ( dynamicSamplingContext ) ;
68
+
69
+ // The Next.js serializer throws on undefined values so we need to guard for it (#12102)
70
+ if ( baggage ) {
71
+ appGetInitialProps . pageProps . _sentryBaggage = baggage ;
72
+ }
63
73
}
64
74
65
75
return appGetInitialProps ;
Original file line number Diff line number Diff line change @@ -49,10 +49,20 @@ export function wrapErrorGetInitialPropsWithSentry(
49
49
const requestSpan = getSpanFromRequest ( req ) ?? ( activeSpan ? getRootSpan ( activeSpan ) : undefined ) ;
50
50
51
51
if ( requestSpan ) {
52
- errorGetInitialProps . _sentryTraceData = spanToTraceHeader ( requestSpan ) ;
52
+ const sentryTrace = spanToTraceHeader ( requestSpan ) ;
53
+
54
+ // The Next.js serializer throws on undefined values so we need to guard for it (#12102)
55
+ if ( sentryTrace ) {
56
+ errorGetInitialProps . _sentryTraceData = sentryTrace ;
57
+ }
53
58
54
59
const dynamicSamplingContext = getDynamicSamplingContextFromSpan ( requestSpan ) ;
55
- errorGetInitialProps . _sentryBaggage = dynamicSamplingContextToSentryBaggageHeader ( dynamicSamplingContext ) ;
60
+ const baggage = dynamicSamplingContextToSentryBaggageHeader ( dynamicSamplingContext ) ;
61
+
62
+ // The Next.js serializer throws on undefined values so we need to guard for it (#12102)
63
+ if ( baggage ) {
64
+ errorGetInitialProps . _sentryBaggage = baggage ;
65
+ }
56
66
}
57
67
58
68
return errorGetInitialProps ;
Original file line number Diff line number Diff line change @@ -45,10 +45,20 @@ export function wrapGetInitialPropsWithSentry(origGetInitialProps: GetInitialPro
45
45
const requestSpan = getSpanFromRequest ( req ) ?? ( activeSpan ? getRootSpan ( activeSpan ) : undefined ) ;
46
46
47
47
if ( requestSpan ) {
48
- initialProps . _sentryTraceData = spanToTraceHeader ( requestSpan ) ;
48
+ const sentryTrace = spanToTraceHeader ( requestSpan ) ;
49
+
50
+ // The Next.js serializer throws on undefined values so we need to guard for it (#12102)
51
+ if ( sentryTrace ) {
52
+ initialProps . _sentryTraceData = sentryTrace ;
53
+ }
49
54
50
55
const dynamicSamplingContext = getDynamicSamplingContextFromSpan ( requestSpan ) ;
51
- initialProps . _sentryBaggage = dynamicSamplingContextToSentryBaggageHeader ( dynamicSamplingContext ) ;
56
+ const baggage = dynamicSamplingContextToSentryBaggageHeader ( dynamicSamplingContext ) ;
57
+
58
+ // The Next.js serializer throws on undefined values so we need to guard for it (#12102)
59
+ if ( baggage ) {
60
+ initialProps . _sentryBaggage = baggage ;
61
+ }
52
62
}
53
63
54
64
return initialProps ;
Original file line number Diff line number Diff line change @@ -38,13 +38,21 @@ export function wrapGetServerSidePropsWithSentry(
38
38
39
39
if ( serverSideProps && 'props' in serverSideProps ) {
40
40
const activeSpan = getActiveSpan ( ) ;
41
- const requestTransaction = getSpanFromRequest ( req ) ?? ( activeSpan ? getRootSpan ( activeSpan ) : undefined ) ;
42
- if ( requestTransaction ) {
43
- ( serverSideProps . props as Record < string , unknown > ) . _sentryTraceData = spanToTraceHeader ( requestTransaction ) ;
44
-
45
- const dynamicSamplingContext = getDynamicSamplingContextFromSpan ( requestTransaction ) ;
46
- ( serverSideProps . props as Record < string , unknown > ) . _sentryBaggage =
47
- dynamicSamplingContextToSentryBaggageHeader ( dynamicSamplingContext ) ;
41
+ const requestSpan = getSpanFromRequest ( req ) ?? ( activeSpan ? getRootSpan ( activeSpan ) : undefined ) ;
42
+ if ( requestSpan ) {
43
+ const sentryTrace = spanToTraceHeader ( requestSpan ) ;
44
+
45
+ // The Next.js serializer throws on undefined values so we need to guard for it (#12102)
46
+ if ( sentryTrace ) {
47
+ ( serverSideProps . props as Record < string , unknown > ) . _sentryTraceData = sentryTrace ;
48
+ }
49
+
50
+ const dynamicSamplingContext = getDynamicSamplingContextFromSpan ( requestSpan ) ;
51
+ const baggage = dynamicSamplingContextToSentryBaggageHeader ( dynamicSamplingContext ) ;
52
+ // The Next.js serializer throws on undefined values so we need to guard for it (#12102)
53
+ if ( baggage ) {
54
+ ( serverSideProps . props as Record < string , unknown > ) . _sentryBaggage = baggage ;
55
+ }
48
56
}
49
57
}
50
58
You can’t perform that action at this time.
0 commit comments