Skip to content

Commit 652d3eb

Browse files
author
Luca Forstner
committed
Add support for getStaticProps tracing
1 parent 1bde09a commit 652d3eb

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

packages/nextjs/src/performance/client.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ interface SentryEnhancedNextData extends NextData {
2929
pageProps?: {
3030
_sentryGetServerSidePropsTraceData?: string; // trace parent info, if injected by server-side `getServerSideProps`
3131
_sentryGetServerSidePropsBaggage?: string; // baggage, if injected by server-side `getServerSideProps`
32+
33+
// The following two values are only injected in a very special case with the following conditions:
34+
// 1. The page's `getStaticPaths` method must have returned `fallback: 'blocking'`.
35+
// 2. The requested page must be a "miss" in terms of "Incremental Static Regeneration", meaning the requested page has not been generated before.
36+
// In this case, a page is requested and only served when `getStaticProps` is done. There is not even a fallback page or similar.
37+
_sentryGetStaticPropsTraceData?: string; // trace parent info, if injected by server-side `getStaticProps`
38+
_sentryGetStaticPropsBaggage?: string; // baggage, if injected by server-side `getStaticProps`
3239
};
3340
};
3441
}
@@ -81,16 +88,18 @@ function extractNextDataTagInformation(): NextDataTagInfo {
8188

8289
const getInitialPropsBaggage = props._sentryGetInitialPropsBaggage;
8390
const getServerSidePropsBaggage = pageProps && pageProps._sentryGetServerSidePropsBaggage;
84-
// Ordering of the following shouldn't matter but `getInitialProps` generally runs before `getServerSideProps` so we give it priority.
85-
const baggage = getInitialPropsBaggage || getServerSidePropsBaggage;
91+
const getStaticPropsBaggage = pageProps && pageProps._sentryGetStaticPropsBaggage;
92+
// Ordering of the following shouldn't matter but `getInitialProps` generally runs before `getServerSideProps` or `getStaticProps` so we give it priority.
93+
const baggage = getInitialPropsBaggage || getServerSidePropsBaggage || getStaticPropsBaggage;
8694
if (baggage) {
8795
nextDataTagInfo.baggage = baggage;
8896
}
8997

9098
const getInitialPropsTraceData = props._sentryGetInitialPropsTraceData;
9199
const getServerSidePropsTraceData = pageProps && pageProps._sentryGetServerSidePropsTraceData;
92-
// Ordering of the following shouldn't matter but `getInitialProps` generally runs before `getServerSideProps` so we give it priority.
93-
const traceData = getInitialPropsTraceData || getServerSidePropsTraceData;
100+
const getStaticPropsTraceData = pageProps && pageProps._sentryGetStaticPropsTraceData;
101+
// Ordering of the following shouldn't matter but `getInitialProps` generally runs before `getServerSideProps` or `getStaticProps` so we give it priority.
102+
const traceData = getInitialPropsTraceData || getServerSidePropsTraceData || getStaticPropsTraceData;
94103
if (traceData) {
95104
nextDataTagInfo.traceParentData = extractTraceparentData(traceData);
96105
}

packages/nextjs/test/performance/client.test.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ describe('client', () => {
107107
},
108108
],
109109
[
110-
'https://example.com/static',
111-
'/static',
110+
'https://example.com/dynamic',
111+
'/dynamic',
112112
{},
113113
{
114114
pageProps: {
@@ -118,6 +118,33 @@ describe('client', () => {
118118
},
119119
},
120120
true,
121+
{
122+
name: '/dynamic',
123+
op: 'pageload',
124+
tags: {
125+
'routing.instrumentation': 'next-router',
126+
},
127+
metadata: {
128+
source: 'route',
129+
baggage: [{ environment: 'myEnv', release: '2.1.0' }, '', true],
130+
},
131+
traceId: 'c82b8554881b4d28ad977de04a4fb40a',
132+
parentSpanId: 'a755953cd3394d5f',
133+
parentSampled: true,
134+
},
135+
],
136+
[
137+
'https://example.com/static',
138+
'/static',
139+
{},
140+
{
141+
pageProps: {
142+
_sentryGetStaticPropsTraceData: 'c82b8554881b4d28ad977de04a4fb40a-a755953cd3394d5f-1',
143+
_sentryGetStaticPropsBaggage:
144+
'other=vendor,foo=bar,third=party,last=item,sentry-release=2.1.0,sentry-environment=myEnv',
145+
},
146+
},
147+
true,
121148
{
122149
name: '/static',
123150
op: 'pageload',

0 commit comments

Comments
 (0)