-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nextjs): Trace pageloads in App Router
- Loading branch information
Showing
22 changed files
with
405 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
dev-packages/e2e-tests/test-applications/nextjs-15/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
.pnpm-debug.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
!*.d.ts | ||
|
||
# Sentry | ||
.sentryclirc | ||
|
||
.vscode | ||
|
||
test-results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@sentry:registry=http://127.0.0.1:4873 | ||
@sentry-internal:registry=http://127.0.0.1:4873 |
7 changes: 7 additions & 0 deletions
7
dev-packages/e2e-tests/test-applications/nextjs-15/app/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Layout({ children }: { children: React.ReactNode }) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
); | ||
} |
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/nextjs-15/app/pageload-tracing/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { PropsWithChildren } from 'react'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export default async function Layout({ children }: PropsWithChildren<unknown>) { | ||
await new Promise(resolve => setTimeout(resolve, 500)); | ||
return <>{children}</>; | ||
} |
14 changes: 14 additions & 0 deletions
14
dev-packages/e2e-tests/test-applications/nextjs-15/app/pageload-tracing/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const dynamic = 'force-dynamic'; | ||
|
||
export default async function Page() { | ||
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
return <p>I am page 2</p>; | ||
} | ||
|
||
export async function generateMetadata() { | ||
(await fetch('http://example.com/')).text(); | ||
|
||
return { | ||
title: 'my title', | ||
}; | ||
} |
4 changes: 4 additions & 0 deletions
4
dev-packages/e2e-tests/test-applications/nextjs-15/globals.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
interface Window { | ||
recordedTransactions?: string[]; | ||
capturedExceptionId?: string; | ||
} |
9 changes: 9 additions & 0 deletions
9
dev-packages/e2e-tests/test-applications/nextjs-15/instrumentation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export async function register() { | ||
if (process.env.NEXT_RUNTIME === 'nodejs') { | ||
await import('./sentry.server.config'); | ||
} | ||
|
||
if (process.env.NEXT_RUNTIME === 'edge') { | ||
await import('./sentry.edge.config'); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
dev-packages/e2e-tests/test-applications/nextjs-15/next-env.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/image-types/global" /> | ||
|
||
// NOTE: This file should not be edited | ||
// see https://nextjs.org/docs/basic-features/typescript for more information. |
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/nextjs-15/next.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const { withSentryConfig } = require('@sentry/nextjs'); | ||
|
||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {}; | ||
|
||
module.exports = withSentryConfig(nextConfig, { | ||
silent: true, | ||
}); |
46 changes: 46 additions & 0 deletions
46
dev-packages/e2e-tests/test-applications/nextjs-15/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "create-next-app", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"build": "next build > .tmp_build_stdout 2> .tmp_build_stderr || (cat .tmp_build_stdout && cat .tmp_build_stderr && exit 1)", | ||
"clean": "npx rimraf node_modules pnpm-lock.yaml", | ||
"test:prod": "TEST_ENV=production playwright test", | ||
"test:dev": "TEST_ENV=development playwright test", | ||
"test:build": "pnpm install && npx playwright install && pnpm build", | ||
"test:build-canary": "pnpm install && pnpm add next@canary && npx playwright install && pnpm build", | ||
"test:build-latest": "pnpm install && pnpm add next@latest && npx playwright install && pnpm build", | ||
"test:assert": "pnpm test:prod && pnpm test:dev" | ||
}, | ||
"dependencies": { | ||
"@playwright/test": "^1.27.1", | ||
"@sentry/nextjs": "latest || *", | ||
"@types/node": "18.11.17", | ||
"@types/react": "18.0.26", | ||
"@types/react-dom": "18.0.9", | ||
"next": "14.3.0-canary.73", | ||
"react": "beta", | ||
"react-dom": "beta", | ||
"typescript": "4.9.5", | ||
"wait-port": "1.0.4" | ||
}, | ||
"devDependencies": { | ||
"@sentry-internal/event-proxy-server": "link:../../../event-proxy-server", | ||
"@sentry-internal/feedback": "latest || *", | ||
"@sentry-internal/replay-canvas": "latest || *", | ||
"@sentry-internal/browser-utils": "latest || *", | ||
"@sentry/browser": "latest || *", | ||
"@sentry/core": "latest || *", | ||
"@sentry/nextjs": "latest || *", | ||
"@sentry/node": "latest || *", | ||
"@sentry/opentelemetry": "latest || *", | ||
"@sentry/react": "latest || *", | ||
"@sentry-internal/replay": "latest || *", | ||
"@sentry/types": "latest || *", | ||
"@sentry/utils": "latest || *", | ||
"@sentry/vercel-edge": "latest || *" | ||
}, | ||
"volta": { | ||
"extends": "../../package.json" | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
dev-packages/e2e-tests/test-applications/nextjs-15/playwright.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import os from 'os'; | ||
import type { PlaywrightTestConfig } from '@playwright/test'; | ||
import { devices } from '@playwright/test'; | ||
|
||
// Fix urls not resolving to localhost on Node v17+ | ||
// See: https://github.com/axios/axios/issues/3821#issuecomment-1413727575 | ||
import { setDefaultResultOrder } from 'dns'; | ||
setDefaultResultOrder('ipv4first'); | ||
|
||
const testEnv = process.env.TEST_ENV; | ||
|
||
if (!testEnv) { | ||
throw new Error('No test env defined'); | ||
} | ||
|
||
const nextPort = 3030; | ||
const eventProxyPort = 3031; | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
const config: PlaywrightTestConfig = { | ||
testDir: './tests', | ||
/* Maximum time one test can run for. */ | ||
timeout: 30_000, | ||
expect: { | ||
/** | ||
* Maximum time expect() should wait for the condition to be met. | ||
* For example in `await expect(locator).toHaveText();` | ||
*/ | ||
timeout: 10000, | ||
}, | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Defaults to half the number of CPUs. The tests are not really CPU-bound but rather I/O-bound with all the polling we do so we increase the concurrency to the CPU count. */ | ||
workers: os.cpus().length, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* `next dev` is incredibly buggy with the app dir */ | ||
retries: testEnv === 'development' ? 3 : 0, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: 'list', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ | ||
actionTimeout: 0, | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
baseURL: `http://localhost:${nextPort}`, | ||
trace: 'retain-on-failure', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { | ||
...devices['Desktop Chrome'], | ||
}, | ||
}, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: [ | ||
{ | ||
command: 'node start-event-proxy.mjs', | ||
port: eventProxyPort, | ||
}, | ||
{ | ||
command: | ||
testEnv === 'development' | ||
? `pnpm wait-port ${eventProxyPort} && pnpm next dev -p ${nextPort}` | ||
: `pnpm wait-port ${eventProxyPort} && pnpm next start -p ${nextPort}`, | ||
port: nextPort, | ||
stdout: 'pipe', | ||
stderr: 'pipe', | ||
}, | ||
], | ||
}; | ||
|
||
export default config; |
9 changes: 9 additions & 0 deletions
9
dev-packages/e2e-tests/test-applications/nextjs-15/sentry.client.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
Sentry.init({ | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN, | ||
tunnel: `http://localhost:3031/`, // proxy server | ||
tracesSampleRate: 1.0, | ||
sendDefaultPii: true, | ||
}); |
13 changes: 13 additions & 0 deletions
13
dev-packages/e2e-tests/test-applications/nextjs-15/sentry.edge.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
Sentry.init({ | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN, | ||
tunnel: `http://localhost:3031/`, // proxy server | ||
tracesSampleRate: 1.0, | ||
sendDefaultPii: true, | ||
transportOptions: { | ||
// We are doing a lot of events at once in this test | ||
bufferSize: 1000, | ||
}, | ||
}); |
13 changes: 13 additions & 0 deletions
13
dev-packages/e2e-tests/test-applications/nextjs-15/sentry.server.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as Sentry from '@sentry/nextjs'; | ||
|
||
Sentry.init({ | ||
environment: 'qa', // dynamic sampling bias to keep transactions | ||
dsn: process.env.NEXT_PUBLIC_E2E_TEST_DSN, | ||
tunnel: `http://localhost:3031/`, // proxy server | ||
tracesSampleRate: 1.0, | ||
sendDefaultPii: true, | ||
transportOptions: { | ||
// We are doing a lot of events at once in this test | ||
bufferSize: 1000, | ||
}, | ||
}); |
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/nextjs-15/start-event-proxy.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { startEventProxyServer } from '@sentry-internal/event-proxy-server'; | ||
|
||
startEventProxyServer({ | ||
port: 3031, | ||
proxyServerName: 'nextjs-15', | ||
}); |
37 changes: 37 additions & 0 deletions
37
dev-packages/e2e-tests/test-applications/nextjs-15/tests/pageload-tracing.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { waitForTransaction } from '@sentry-internal/event-proxy-server'; | ||
|
||
test('all server component transactions should be attached to the pageload request span', async ({ page }) => { | ||
const pageServerComponentTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => { | ||
return transactionEvent?.transaction === 'Page Server Component (/pageload-tracing)'; | ||
}); | ||
|
||
const layoutServerComponentTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => { | ||
return transactionEvent?.transaction === 'Layout Server Component (/pageload-tracing)'; | ||
}); | ||
|
||
const metadataTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => { | ||
return transactionEvent?.transaction === 'Page.generateMetadata (/pageload-tracing)'; | ||
}); | ||
|
||
const pageloadTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => { | ||
return transactionEvent?.transaction === '/pageload-tracing'; | ||
}); | ||
|
||
await page.goto(`/pageload-tracing`); | ||
|
||
const [pageServerComponentTransaction, layoutServerComponentTransaction, metadataTransaction, pageloadTransaction] = | ||
await Promise.all([ | ||
pageServerComponentTransactionPromise, | ||
layoutServerComponentTransactionPromise, | ||
metadataTransactionPromise, | ||
pageloadTransactionPromise, | ||
]); | ||
|
||
const pageloadTraceId = pageloadTransaction.contexts?.trace?.trace_id; | ||
|
||
expect(pageloadTraceId).toBeTruthy(); | ||
expect(pageServerComponentTransaction.contexts?.trace?.trace_id).toBe(pageloadTraceId); | ||
expect(layoutServerComponentTransaction.contexts?.trace?.trace_id).toBe(pageloadTraceId); | ||
expect(metadataTransaction.contexts?.trace?.trace_id).toBe(pageloadTraceId); | ||
}); |
25 changes: 25 additions & 0 deletions
25
dev-packages/e2e-tests/test-applications/nextjs-15/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2018", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"plugins": [ | ||
{ | ||
"name": "next" | ||
} | ||
], | ||
"incremental": true | ||
}, | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "next.config.js", ".next/types/**/*.ts"], | ||
"exclude": ["node_modules", "playwright.config.ts"] | ||
} |
Oops, something went wrong.