Skip to content

Commit fe639f4

Browse files
Luca Forstnerchargome
andauthored
feat(nextjs/vercel-edge/cloudflare): Switch to OTEL for performance monitoring (#13889)
Co-authored-by: Charly Gomez <[email protected]>
1 parent c56d84d commit fe639f4

File tree

71 files changed

+1565
-1094
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1565
-1094
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,7 @@ jobs:
10371037
retention-days: 7
10381038

10391039
- name: Pre-process E2E Test Dumps
1040+
if: always()
10401041
run: |
10411042
node ./scripts/normalize-e2e-test-dump-transaction-events.js
10421043
@@ -1193,6 +1194,7 @@ jobs:
11931194
run: pnpm ${{ matrix.assert-command || 'test:assert' }}
11941195

11951196
- name: Pre-process E2E Test Dumps
1197+
if: always()
11961198
run: |
11971199
node ./scripts/normalize-e2e-test-dump-transaction-events.js
11981200

.size-limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ module.exports = [
224224
import: createImport('init'),
225225
ignore: ['next/router', 'next/constants'],
226226
gzip: true,
227-
limit: '39 KB',
227+
limit: '39.1 KB',
228228
},
229229
// SvelteKit SDK (ESM)
230230
{

dev-packages/e2e-tests/publish-packages.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,19 @@ const packageTarballPaths = glob.sync('packages/*/sentry-*.tgz', {
1212

1313
// Publish built packages to the fake registry
1414
packageTarballPaths.forEach(tarballPath => {
15+
// eslint-disable-next-line no-console
16+
console.log(`Publishing tarball ${tarballPath} ...`);
1517
// `--userconfig` flag needs to be before `publish`
1618
childProcess.exec(
1719
`npm --userconfig ${__dirname}/test-registry.npmrc publish ${tarballPath}`,
1820
{
1921
cwd: repositoryRoot, // Can't use __dirname here because npm would try to publish `@sentry-internal/e2e-tests`
2022
encoding: 'utf8',
2123
},
22-
(err, stdout, stderr) => {
23-
// eslint-disable-next-line no-console
24-
console.log(stdout);
25-
// eslint-disable-next-line no-console
26-
console.log(stderr);
24+
err => {
2725
if (err) {
2826
// eslint-disable-next-line no-console
29-
console.error(err);
27+
console.error(`Error publishing tarball ${tarballPath}`, err);
3028
process.exit(1);
3129
}
3230
},

dev-packages/e2e-tests/test-applications/nextjs-13/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@types/node": "18.11.17",
1818
"@types/react": "18.0.26",
1919
"@types/react-dom": "18.0.9",
20-
"next": "13.2.0",
20+
"next": "13.5.7",
2121
"react": "18.2.0",
2222
"react-dom": "18.2.0",
2323
"typescript": "4.9.5"

dev-packages/e2e-tests/test-applications/nextjs-13/tests/client/pages-dir-pageload.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,38 @@ test('should create a pageload transaction when the `pages` directory is used',
4646
type: 'transaction',
4747
});
4848
});
49+
50+
test('should create a pageload transaction with correct name when an error occurs in getServerSideProps', async ({
51+
page,
52+
}) => {
53+
const transactionPromise = waitForTransaction('nextjs-13', async transactionEvent => {
54+
return (
55+
transactionEvent.transaction === '/[param]/error-getServerSideProps' &&
56+
transactionEvent.contexts?.trace?.op === 'pageload'
57+
);
58+
});
59+
60+
await page.goto(`/something/error-getServerSideProps`, { waitUntil: 'networkidle' });
61+
62+
const transaction = await transactionPromise;
63+
64+
expect(transaction).toMatchObject({
65+
contexts: {
66+
trace: {
67+
data: {
68+
'sentry.op': 'pageload',
69+
'sentry.origin': 'auto.pageload.nextjs.pages_router_instrumentation',
70+
'sentry.source': 'route',
71+
},
72+
op: 'pageload',
73+
origin: 'auto.pageload.nextjs.pages_router_instrumentation',
74+
},
75+
},
76+
transaction: '/[param]/error-getServerSideProps',
77+
transaction_info: { source: 'route' },
78+
type: 'transaction',
79+
});
80+
81+
// Ensure the transaction name is not '/_error'
82+
expect(transaction.transaction).not.toBe('/_error');
83+
});

dev-packages/e2e-tests/test-applications/nextjs-13/tests/isomorphic/getInitialProps.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test('should propagate serverside `getInitialProps` trace to client', async ({ p
1111

1212
const serverTransactionPromise = waitForTransaction('nextjs-13', async transactionEvent => {
1313
return (
14-
transactionEvent.transaction === '/[param]/withInitialProps' &&
14+
transactionEvent.transaction === 'GET /[param]/withInitialProps' &&
1515
transactionEvent.contexts?.trace?.op === 'http.server'
1616
);
1717
});
@@ -47,7 +47,7 @@ test('should propagate serverside `getInitialProps` trace to client', async ({ p
4747
status: 'ok',
4848
},
4949
},
50-
transaction: '/[param]/withInitialProps',
50+
transaction: 'GET /[param]/withInitialProps',
5151
transaction_info: {
5252
source: 'route',
5353
},

dev-packages/e2e-tests/test-applications/nextjs-13/tests/isomorphic/getServerSideProps.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test('Should record performance for getServerSideProps', async ({ page }) => {
1111

1212
const serverTransactionPromise = waitForTransaction('nextjs-13', async transactionEvent => {
1313
return (
14-
transactionEvent.transaction === '/[param]/withServerSideProps' &&
14+
transactionEvent.transaction === 'GET /[param]/withServerSideProps' &&
1515
transactionEvent.contexts?.trace?.op === 'http.server'
1616
);
1717
});
@@ -47,7 +47,7 @@ test('Should record performance for getServerSideProps', async ({ page }) => {
4747
status: 'ok',
4848
},
4949
},
50-
transaction: '/[param]/withServerSideProps',
50+
transaction: 'GET /[param]/withServerSideProps',
5151
transaction_info: {
5252
source: 'route',
5353
},
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect, test } from '@playwright/test';
22
import { waitForTransaction } from '@sentry-internal/test-utils';
33

4-
test('should not automatically create transactions for routes that were excluded from auto wrapping (string)', async ({
4+
test('should not apply build-time instrumentation for routes that were excluded from auto wrapping (string)', async ({
55
request,
66
}) => {
77
const transactionPromise = waitForTransaction('nextjs-13', async transactionEvent => {
@@ -13,17 +13,13 @@ test('should not automatically create transactions for routes that were excluded
1313

1414
expect(await (await request.get(`/api/endpoint-excluded-with-string`)).text()).toBe('{"success":true}');
1515

16-
let transactionPromiseReceived = false;
17-
transactionPromise.then(() => {
18-
transactionPromiseReceived = true;
19-
});
20-
21-
await new Promise(resolve => setTimeout(resolve, 5_000));
16+
const transaction = await transactionPromise;
2217

23-
expect(transactionPromiseReceived).toBe(false);
18+
expect(transaction.contexts?.trace?.data?.['sentry.origin']).toBeDefined();
19+
expect(transaction.contexts?.trace?.data?.['sentry.origin']).not.toBe('auto.http.nextjs'); // This is the origin set by the build time instrumentation
2420
});
2521

26-
test('should not automatically create transactions for routes that were excluded from auto wrapping (regex)', async ({
22+
test('should not apply build-time instrumentation for routes that were excluded from auto wrapping (regex)', async ({
2723
request,
2824
}) => {
2925
const transactionPromise = waitForTransaction('nextjs-13', async transactionEvent => {
@@ -35,12 +31,8 @@ test('should not automatically create transactions for routes that were excluded
3531

3632
expect(await (await request.get(`/api/endpoint-excluded-with-regex`)).text()).toBe('{"success":true}');
3733

38-
let transactionPromiseReceived = false;
39-
transactionPromise.then(() => {
40-
transactionPromiseReceived = true;
41-
});
42-
43-
await new Promise(resolve => setTimeout(resolve, 5_000));
34+
const transaction = await transactionPromise;
4435

45-
expect(transactionPromiseReceived).toBe(false);
36+
expect(transaction.contexts?.trace?.data?.['sentry.origin']).toBeDefined();
37+
expect(transaction.contexts?.trace?.data?.['sentry.origin']).not.toBe('auto.http.nextjs'); // This is the origin set by the build time instrumentation
4638
});

0 commit comments

Comments
 (0)