-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(nitro): Add a Cloudflare Workers plugin #23246
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
adipascu
wants to merge
1
commit into
getsentry:develop
Choose a base branch
from
adipascu:feat/nitro-cloudflare-plugin
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.
+569
−1
Open
Changes from all commits
Commits
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
dev-packages/e2e-tests/test-applications/nitro-3-cloudflare/package.json
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,31 @@ | ||
| { | ||
| "name": "nitro-3-cloudflare", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "build": "vite build", | ||
| "preview": "wrangler dev --port 3030 --log-level=$(test $CI && echo 'none' || echo 'log')", | ||
| "clean": "npx rimraf node_modules pnpm-lock.yaml .output", | ||
| "test": "playwright test", | ||
| "test:build": "pnpm install && pnpm build", | ||
| "test:assert": "pnpm test" | ||
| }, | ||
| "dependencies": { | ||
| "@sentry/cloudflare": "latest || *", | ||
| "@sentry/nitro": "latest || *" | ||
| }, | ||
| "devDependencies": { | ||
| "@playwright/test": "~1.56.0", | ||
| "@sentry-internal/test-utils": "link:../../../test-utils", | ||
| "@sentry/core": "latest || *", | ||
| "nitro": "^3.0.260522-beta", | ||
| "rolldown": "latest", | ||
| "vite": "latest", | ||
| "wrangler": "^4.72.0" | ||
| }, | ||
| "volta": { | ||
| "node": "22.20.0", | ||
| "extends": "../../package.json" | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/nitro-3-cloudflare/playwright.config.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,8 @@ | ||
| import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
|
|
||
| const config = getPlaywrightConfig({ | ||
| startCommand: 'pnpm preview', | ||
| port: 3030, | ||
| }); | ||
|
|
||
| export default config; |
3 changes: 3 additions & 0 deletions
3
dev-packages/e2e-tests/test-applications/nitro-3-cloudflare/server/api/index.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,3 @@ | ||
| import { defineHandler } from 'nitro/h3'; | ||
|
|
||
| export default defineHandler(() => ({ hello: 'world' })); |
5 changes: 5 additions & 0 deletions
5
dev-packages/e2e-tests/test-applications/nitro-3-cloudflare/server/api/test-error.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,5 @@ | ||
| import { defineHandler } from 'nitro/h3'; | ||
|
|
||
| export default defineHandler(() => { | ||
| throw new Error('This is a test error'); | ||
| }); |
12 changes: 12 additions & 0 deletions
12
dev-packages/e2e-tests/test-applications/nitro-3-cloudflare/server/plugins/sentry.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,12 @@ | ||
| import { sentryCloudflareNitroPlugin } from '@sentry/nitro/cloudflare'; | ||
| import { definePlugin } from 'nitro'; | ||
|
|
||
| export default definePlugin( | ||
| sentryCloudflareNitroPlugin(() => ({ | ||
| environment: 'qa', | ||
| traceLifecycle: 'static', | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| tunnel: 'http://localhost:3031/', | ||
| tracesSampleRate: 1.0, | ||
| })), | ||
| ); |
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/nitro-3-cloudflare/start-event-proxy.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,6 @@ | ||
| import { startEventProxyServer } from '@sentry-internal/test-utils'; | ||
|
|
||
| startEventProxyServer({ | ||
| port: 3031, | ||
| proxyServerName: 'nitro-3-cloudflare', | ||
| }); |
45 changes: 45 additions & 0 deletions
45
dev-packages/e2e-tests/test-applications/nitro-3-cloudflare/tests/errors.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,45 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForError } from '@sentry-internal/test-utils'; | ||
|
|
||
| test('sends an error event from the Cloudflare Workers runtime', async ({ request }) => { | ||
| const errorEventPromise = waitForError('nitro-3-cloudflare', event => { | ||
| return !event.type && !!event.exception?.values?.some(v => v.value === 'This is a test error'); | ||
| }); | ||
|
|
||
| const res = await request.get('/api/test-error'); | ||
| expect(res.status()).toBe(500); | ||
|
|
||
| const errorEvent = await errorEventPromise; | ||
| const values = errorEvent.exception?.values ?? []; | ||
|
|
||
| // h3 wraps the thrown error in an HTTPError, so both are reported and linked. | ||
| expect(values).toHaveLength(2); | ||
| expect(values.some(v => v.type === 'Error' && v.value === 'This is a test error')).toBe(true); | ||
| expect( | ||
| values.some(v => v.mechanism?.type === 'auto.function.nitro.captureErrorHook' && v.mechanism.handled === false), | ||
| ).toBe(true); | ||
| expect(errorEvent.sdk?.name).toBe('sentry.javascript.cloudflare'); | ||
| }); | ||
|
|
||
| test('does not send 404 errors', async ({ request }) => { | ||
| const errorEvents: (string | undefined)[] = []; | ||
| const sentinelEventPromise = waitForError('nitro-3-cloudflare', event => { | ||
| if (event.type) { | ||
| return false; | ||
| } | ||
| errorEvents.push(event.exception?.values?.map(v => v.value).join(', ')); | ||
| return !!event.exception?.values?.some(v => v.value === 'This is a test error'); | ||
| }); | ||
|
|
||
| const notFoundRes = await request.get('/api/non-existent-route'); | ||
| expect(notFoundRes.status()).toBe(404); | ||
|
|
||
| // The sentinel error arrives after anything the 404 could have sent, so waiting for it | ||
| // makes the no-report assertion deterministic without a timeout. | ||
| const sentinelRes = await request.get('/api/test-error'); | ||
| expect(sentinelRes.status()).toBe(500); | ||
|
|
||
| await sentinelEventPromise; | ||
|
|
||
| expect(errorEvents).toHaveLength(1); | ||
| }); | ||
23 changes: 23 additions & 0 deletions
23
dev-packages/e2e-tests/test-applications/nitro-3-cloudflare/tests/transactions.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,23 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
|
|
||
| test('sends an http.server transaction from the Cloudflare Workers runtime', async ({ request }) => { | ||
| const transactionEventPromise = waitForTransaction('nitro-3-cloudflare', transactionEvent => { | ||
| return ( | ||
| transactionEvent.contexts?.trace?.op === 'http.server' && | ||
| (transactionEvent.request?.url?.endsWith('/api/') ?? false) | ||
| ); | ||
| }); | ||
|
|
||
| const res = await request.get('/api/'); | ||
| expect(res.status()).toBe(200); | ||
| expect(await res.json()).toEqual({ hello: 'world' }); | ||
|
|
||
| const transactionEvent = await transactionEventPromise; | ||
|
|
||
| expect(transactionEvent.contexts?.trace).toMatchObject({ | ||
| op: 'http.server', | ||
| origin: 'auto.http.cloudflare', | ||
| }); | ||
| expect(transactionEvent.sdk?.name).toBe('sentry.javascript.cloudflare'); | ||
| }); |
11 changes: 11 additions & 0 deletions
11
dev-packages/e2e-tests/test-applications/nitro-3-cloudflare/tsconfig.json
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,11 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ESNext", | ||
| "module": "ESNext", | ||
| "moduleResolution": "bundler", | ||
| "strict": true, | ||
| "esModuleInterop": true, | ||
| "skipLibCheck": true | ||
| }, | ||
| "include": ["server/**/*.ts", "vite.config.ts"] | ||
| } |
14 changes: 14 additions & 0 deletions
14
dev-packages/e2e-tests/test-applications/nitro-3-cloudflare/vite.config.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,14 @@ | ||
| import { nitro } from 'nitro/vite'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [ | ||
| nitro({ | ||
| preset: 'cloudflare-module', | ||
| serverDir: './server', | ||
| cloudflare: { | ||
| deployConfig: false, | ||
| }, | ||
| }), | ||
| ], | ||
| }); |
11 changes: 11 additions & 0 deletions
11
dev-packages/e2e-tests/test-applications/nitro-3-cloudflare/wrangler.jsonc
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,11 @@ | ||
| { | ||
| "$schema": "node_modules/wrangler/config-schema.json", | ||
| "name": "nitro-3-cloudflare", | ||
| "main": "./.output/server/index.mjs", | ||
| "compatibility_date": "2026-06-29", | ||
| "compatibility_flags": ["nodejs_compat"], | ||
| "assets": { | ||
| "directory": "./.output/public", | ||
| "binding": "ASSETS", | ||
| }, | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from '@sentry/cloudflare'; | ||
| export { sentryCloudflareNitroPlugin } from '../runtime/plugins/cloudflare'; |
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.
Uh oh!
There was an error while loading. Please reload this page.