-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(nuxt)!: Bundle server config into Nitro build #24094
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
Open
s1gr1d
wants to merge
9
commits into
develop
Choose a base branch
from
sig/nuxt-server-config-auto-add
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+725
−287
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8ca6962
cloudflare util
s1gr1d bece846
fix package detection
s1gr1d a84ae4f
add deprecations
s1gr1d 03efd42
crash tests
s1gr1d 24c0354
double init guard
s1gr1d 89729c3
check for prerender runtime
s1gr1d c133bb8
feat(nuxt)!: Bundle server config into Nitro build
s1gr1d 5d60a39
Merge branch 'develop' into sig/nuxt-server-config-auto-add
s1gr1d 830a18a
add migration guide
s1gr1d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
9 changes: 9 additions & 0 deletions
9
dev-packages/e2e-tests/test-applications/nuxt-4/instrument-preload.mjs
This file contains hidden or 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 @@ | ||
| // Simulates a v10-style `node --import` preload that fully initializes the SDK | ||
| // before the config bundled into the server build runs its own `Sentry.init`. | ||
| import * as Sentry from '@sentry/nuxt'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| tracesSampleRate: 1.0, | ||
| tunnel: 'http://localhost:3031/', | ||
| }); |
55 changes: 0 additions & 55 deletions
55
dev-packages/e2e-tests/test-applications/nuxt-4/nuxt-start-dev-server.bash
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
9 changes: 9 additions & 0 deletions
9
dev-packages/e2e-tests/test-applications/nuxt-4/server/plugins/aa-eval-crash.ts
This file contains hidden or 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 { defineNitroPlugin } from 'nitropack/runtime'; | ||
|
|
||
| // Throws during module evaluation, before any plugin function runs. | ||
| // The `aa-` prefix makes this the first scanned plugin. | ||
| if (process.env.SENTRY_TEST_EVAL_CRASH) { | ||
| throw new Error('eval-crash-test'); | ||
| } | ||
|
|
||
| export default defineNitroPlugin(() => {}); |
9 changes: 9 additions & 0 deletions
9
dev-packages/e2e-tests/test-applications/nuxt-4/server/plugins/zz-startup-crash.ts
This file contains hidden or 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 { defineNitroPlugin } from 'nitropack/runtime'; | ||
|
|
||
| // Throws while nitro runs its plugins, before `listen`. | ||
| // The `zz-` prefix makes this the last scanned plugin (`aa-eval-crash.ts` covers the earliest point). | ||
| export default defineNitroPlugin(() => { | ||
| if (process.env.SENTRY_TEST_STARTUP_CRASH) { | ||
| throw new Error('startup-crash-test'); | ||
| } | ||
| }); |
This file contains hidden or 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
75 changes: 75 additions & 0 deletions
75
dev-packages/e2e-tests/test-applications/nuxt-4/tests/import-compat.test.ts
This file contains hidden or 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,75 @@ | ||
| import type { ChildProcess } from 'node:child_process'; | ||
| import { spawn } from 'node:child_process'; | ||
| import { expect, test } from '@playwright/test'; | ||
| import { getSpanOp, waitForStreamedSpan } from '@sentry-internal/test-utils'; | ||
|
|
||
| // `node --import` start commands must keep working now that the config is bundled: the emitted | ||
| // config file is a shim that only prints a removal hint, and a preload that really initializes | ||
| // the SDK must not cause a second init. Each test spawns its own server on a dedicated port. | ||
|
|
||
| interface PreloadedServer { | ||
| child: ChildProcess; | ||
| output: () => string; | ||
| } | ||
|
|
||
| async function startServerWithPreload(preloadPath: string, port: string): Promise<PreloadedServer> { | ||
| const child = spawn('node', ['--import', preloadPath, '.output/server/index.mjs'], { | ||
| env: { ...process.env, PORT: port }, | ||
| }); | ||
|
|
||
| let output = ''; | ||
| child.stdout?.on('data', chunk => (output += chunk)); | ||
| child.stderr?.on('data', chunk => (output += chunk)); | ||
|
|
||
| for (let attempt = 0; attempt < 100; attempt++) { | ||
| try { | ||
| await fetch(`http://localhost:${port}/`); | ||
| break; | ||
| } catch { | ||
| await new Promise(resolve => setTimeout(resolve, 200)); | ||
| } | ||
| } | ||
|
|
||
| return { child, output: () => output }; | ||
| } | ||
|
|
||
| test('serves traced requests with the shim preloaded and prints the removal hint', async () => { | ||
| const server = await startServerWithPreload('./.output/server/sentry.server.config.mjs', '3081'); | ||
|
|
||
| try { | ||
| const spanPromise = waitForStreamedSpan( | ||
| 'nuxt-4', | ||
| span => span.is_segment === true && span.attributes?.['url.path']?.value === '/test-param/8281', | ||
| ); | ||
|
|
||
| const response = await fetch('http://localhost:3081/test-param/8281'); | ||
| expect(response.status).toBe(200); | ||
|
|
||
| const span = await spanPromise; | ||
| expect(getSpanOp(span)).toBe('http.server'); | ||
| expect(server.output()).toContain('no longer needed'); | ||
| } finally { | ||
| server.child.kill(); | ||
| } | ||
| }); | ||
|
|
||
| test('skips the second init when a preload already initialized the SDK', async () => { | ||
| const server = await startServerWithPreload('./instrument-preload.mjs', '3082'); | ||
|
|
||
| try { | ||
| const spanPromise = waitForStreamedSpan( | ||
| 'nuxt-4', | ||
| span => span.is_segment === true && span.attributes?.['url.path']?.value === '/test-param/8282', | ||
| ); | ||
|
|
||
| const response = await fetch('http://localhost:3082/test-param/8282'); | ||
| expect(response.status).toBe(200); | ||
|
|
||
| // The preload-created client stays active and still delivers events. | ||
| const span = await spanPromise; | ||
| expect(getSpanOp(span)).toBe('http.server'); | ||
| expect(server.output()).toContain('already initialized'); | ||
| } finally { | ||
| server.child.kill(); | ||
| } | ||
| }); |
46 changes: 46 additions & 0 deletions
46
dev-packages/e2e-tests/test-applications/nuxt-4/tests/startup-error.test.ts
This file contains hidden or 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 @@ | ||
| import { spawn } from 'node:child_process'; | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForError, waitForSession } from '@sentry-internal/test-utils'; | ||
|
|
||
| // Errors thrown between server start and `listen` (module evaluation, nitro plugin runs) must be | ||
| // captured and flushed before the process exits. Each test spawns its own server process because | ||
| // the crash kills it; events still reach the shared event proxy via the tunnel. | ||
|
|
||
| /** Starts the built server and resolves with its exit code. */ | ||
| function spawnCrashingServer(env: Record<string, string>): Promise<number | null> { | ||
| return new Promise((resolve, reject) => { | ||
| const child = spawn('node', ['.output/server/index.mjs'], { | ||
| // Session tracking needs a release | ||
| env: { ...process.env, SENTRY_RELEASE: 'startup-error-test', ...env }, | ||
| }); | ||
| child.on('error', reject); | ||
| child.on('exit', code => resolve(code)); | ||
| }); | ||
| } | ||
|
|
||
| test('captures error and crashed session when a nitro plugin throws during startup', async () => { | ||
| const errorPromise = waitForError('nuxt-4', event => event.exception?.values?.[0]?.value === 'startup-crash-test'); | ||
| const sessionPromise = waitForSession('nuxt-4', session => session.status === 'crashed'); | ||
|
|
||
| const exitCode = await spawnCrashingServer({ SENTRY_TEST_STARTUP_CRASH: '1', PORT: '3077' }); | ||
|
|
||
| const [errorEvent, session] = await Promise.all([errorPromise, sessionPromise]); | ||
|
|
||
| expect(exitCode).toBe(1); | ||
| expect(errorEvent.exception?.values?.[0]?.value).toBe('startup-crash-test'); | ||
| expect(errorEvent.exception?.values?.[0]?.mechanism?.handled).toBe(false); | ||
| expect(session.status).toBe('crashed'); | ||
| expect(session.errors).toBe(1); | ||
| }); | ||
|
|
||
| test('captures error when a server module throws during bundle evaluation', async () => { | ||
| const errorPromise = waitForError('nuxt-4', event => event.exception?.values?.[0]?.value === 'eval-crash-test'); | ||
|
|
||
| const exitCode = await spawnCrashingServer({ SENTRY_TEST_EVAL_CRASH: '1', PORT: '3078' }); | ||
|
|
||
| const errorEvent = await errorPromise; | ||
|
|
||
| expect(exitCode).toBe(1); | ||
| expect(errorEvent.exception?.values?.[0]?.value).toBe('eval-crash-test'); | ||
| expect(errorEvent.exception?.values?.[0]?.mechanism?.handled).toBe(false); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prerender test does not prove skip
Low Severity
The prerender test treats missing
sentry-traceandbaggagetags as proof that bundledSentry.initis skipped at build time. Those tags are already omitted for responses with thex-nitro-prerenderheader, so the assertion can pass even when init still runs and send events during CI builds.Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 830a18a. Configure here.