-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(sveltekit)!: Enable orchestrion instrumentation on Cloudflare #22967
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
Merged
chargome
merged 2 commits into
develop
from
charlygomez/js-3205-sveltekit-cloudflare-orchestrion
Aug 4, 2026
Merged
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
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
dev-packages/e2e-tests/test-applications/sveltekit-cloudflare-pages/docker-compose.yml
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,18 @@ | ||
| services: | ||
| db: | ||
| image: mysql:8.0 | ||
| restart: always | ||
| container_name: e2e-tests-sveltekit-cloudflare-pages-mysql | ||
| # The `mysql` 2.x driver doesn't speak MySQL 8's default | ||
| # `caching_sha2_password` auth, so force the legacy plugin. | ||
| command: ['--default-authentication-plugin=mysql_native_password'] | ||
| ports: | ||
| - '3306:3306' | ||
| environment: | ||
| MYSQL_ROOT_PASSWORD: docker | ||
| healthcheck: | ||
| test: ['CMD-SHELL', 'mysqladmin ping -h 127.0.0.1 -uroot -pdocker'] | ||
| interval: 2s | ||
| timeout: 3s | ||
| retries: 30 | ||
| start_period: 10s |
14 changes: 14 additions & 0 deletions
14
dev-packages/e2e-tests/test-applications/sveltekit-cloudflare-pages/global-setup.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,14 @@ | ||
| import { execSync } from 'child_process'; | ||
| import { dirname } from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
|
||
| export default async function globalSetup() { | ||
| // Start MySQL via Docker Compose. `--wait` blocks until the healthcheck in | ||
| // docker-compose.yml passes, so the worker can connect on the first request. | ||
| execSync('docker compose up -d --wait', { | ||
| cwd: __dirname, | ||
| stdio: 'inherit', | ||
| }); | ||
| } |
12 changes: 12 additions & 0 deletions
12
dev-packages/e2e-tests/test-applications/sveltekit-cloudflare-pages/global-teardown.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,12 @@ | ||
| import { execSync } from 'child_process'; | ||
| import { dirname } from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
|
||
| export default async function globalTeardown() { | ||
| execSync('docker compose down --volumes', { | ||
| cwd: __dirname, | ||
| stdio: 'inherit', | ||
| }); | ||
| } |
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
19 changes: 13 additions & 6 deletions
19
dev-packages/e2e-tests/test-applications/sveltekit-cloudflare-pages/playwright.config.js
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 |
|---|---|---|
| @@ -1,10 +1,17 @@ | ||
| import { defineConfig } from '@playwright/test'; | ||
| import { getPlaywrightConfig } from '@sentry-internal/test-utils'; | ||
|
|
||
| export default defineConfig({ | ||
| webServer: { | ||
| command: 'pnpm run build && pnpm run preview', | ||
| // `vite build` (where the Sentry SvelteKit plugin's orchestrion transform runs) produces the | ||
| // worker; `pnpm preview` (`wrangler pages dev`) serves the built output. `globalSetup` spins up | ||
| // the MySQL container the worker connects to. | ||
| const config = getPlaywrightConfig( | ||
| { | ||
| startCommand: 'pnpm preview', | ||
| port: 4173, | ||
| }, | ||
| { | ||
| globalSetup: './global-setup.mjs', | ||
| globalTeardown: './global-teardown.mjs', | ||
| }, | ||
| ); | ||
|
|
||
| testDir: 'tests', | ||
| }); | ||
| export default config; |
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
44 changes: 44 additions & 0 deletions
44
...ges/e2e-tests/test-applications/sveltekit-cloudflare-pages/src/routes/db-mysql/+server.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,44 @@ | ||
| import { json } from '@sveltejs/kit'; | ||
| import mysql from 'mysql'; | ||
|
|
||
| // The `@sentry/sveltekit` orchestrion transform injects the `orchestrion:mysql:query` | ||
| // diagnostics channel into the bundled `mysql` package at build time. On Cloudflare the | ||
| // transform also registers the matching subscriber factory on the global marker, which | ||
| // `@sentry/cloudflare` reads in `wrapRequestHandler` — so these queries produce `db` spans | ||
| // with no OTel require-hook, which wouldn't work in workerd anyway. | ||
| export const GET = async () => { | ||
| // The connection is created inside the handler: workerd forbids I/O in global scope, and | ||
| // mysql opens its socket lazily on the first query. Explicit host/port because workerd's | ||
| // default resolution differs from Node's. | ||
| const connection = mysql.createConnection({ | ||
| host: '127.0.0.1', | ||
| port: 3306, | ||
| user: 'root', | ||
| password: 'docker', | ||
| }); | ||
|
|
||
| // Swallow connection-level errors so a socket hiccup doesn't become an uncaught exception | ||
| // that fails the request unrelated to the spans. | ||
| connection.on('error', () => { | ||
| // no-op | ||
| }); | ||
|
|
||
| try { | ||
| // The second query is NESTED inside the first's callback. mysql dispatches that callback | ||
| // from its socket data handler (a fresh async context), so the nested query's span only | ||
| // lands on this request's http.server transaction if the channel subscriber restored the | ||
| // parent span across that async boundary. | ||
| await new Promise<void>((resolve, reject) => { | ||
| connection.query('SELECT 1 + 1 AS solution', err1 => { | ||
| if (err1) return reject(err1); | ||
| connection.query('SELECT NOW()', err2 => { | ||
| if (err2) return reject(err2); | ||
| resolve(); | ||
| }); | ||
| }); | ||
| }); | ||
| return json({ status: 'ok' }); | ||
| } finally { | ||
| connection.end(); | ||
| } | ||
| }; |
6 changes: 6 additions & 0 deletions
6
dev-packages/e2e-tests/test-applications/sveltekit-cloudflare-pages/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: 'sveltekit-cloudflare-pages', | ||
| }); |
52 changes: 52 additions & 0 deletions
52
dev-packages/e2e-tests/test-applications/sveltekit-cloudflare-pages/tests/db.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,52 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
|
|
||
| test('a real mysql query emits a db span with orchestrion-channel attributes', async ({ baseURL }) => { | ||
| // The `orchestrion:mysql:query` channel is injected into the bundled `mysql` package at | ||
| // build time by `@sentry/sveltekit`, which — because this app uses the Cloudflare adapter — | ||
| // also registers the subscriber factory on the global marker that `@sentry/cloudflare` reads | ||
| // in `wrapRequestHandler`. The query below therefore produces a `db` span on the request's | ||
| // http.server transaction, with no OTel require-hook (which wouldn't work in workerd). | ||
| const transactionPromise = waitForTransaction('sveltekit-cloudflare-pages', transactionEvent => { | ||
| return ( | ||
| transactionEvent.contexts?.trace?.op === 'http.server' && | ||
| (transactionEvent.spans?.some(span => span.op === 'db') ?? false) | ||
| ); | ||
| }); | ||
|
|
||
| const res = await fetch(`${baseURL}/db-mysql`); | ||
| expect(res.status).toBe(200); | ||
|
|
||
| const transactionEvent = await transactionPromise; | ||
| const dbSpans = transactionEvent.spans!.filter(span => span.op === 'db'); | ||
|
|
||
| const firstQuery = dbSpans.find(span => span.description === 'SELECT 1 + 1 AS solution'); | ||
| expect(firstQuery).toBeDefined(); | ||
| expect(firstQuery!.data?.['sentry.origin']).toBe('auto.db.mysql'); | ||
| expect(firstQuery!.data?.['db.system']).toBe('mysql'); | ||
| expect(firstQuery!.data?.['db.statement']).toBe('SELECT 1 + 1 AS solution'); | ||
| expect(firstQuery!.data?.['net.peer.name']).toBe('127.0.0.1'); | ||
| expect(firstQuery!.data?.['net.peer.port']).toBe(3306); | ||
| expect(firstQuery!.data?.['db.user']).toBe('root'); | ||
| }); | ||
|
|
||
| test('a nested query lands on the same transaction (async context restored)', async ({ baseURL }) => { | ||
| // The second query runs inside the first query's callback — i.e. across mysql's async | ||
| // socket-callback dispatch. Both spans appearing on the SAME http.server transaction proves | ||
| // the channel subscriber restored the parent span across that async boundary (otherwise the | ||
| // nested query would start its own trace and never join this transaction). | ||
| const transactionPromise = waitForTransaction('sveltekit-cloudflare-pages', transactionEvent => { | ||
| return ( | ||
| transactionEvent.contexts?.trace?.op === 'http.server' && | ||
| (transactionEvent.spans?.filter(span => span.op === 'db').length ?? 0) >= 2 | ||
| ); | ||
| }); | ||
|
|
||
| const res = await fetch(`${baseURL}/db-mysql`); | ||
| expect(res.status).toBe(200); | ||
|
|
||
| const transactionEvent = await transactionPromise; | ||
| const descriptions = transactionEvent.spans!.filter(span => span.op === 'db').map(span => span.description); | ||
| expect(descriptions).toContain('SELECT 1 + 1 AS solution'); | ||
| expect(descriptions).toContain('SELECT NOW()'); | ||
| }); |
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
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.
q: Shouldn't we consolidate
injectChannelSubscribersandbuildTimeInstrumentationinto one?(not important for this PR though)
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.
No,
buildTimeInstrumentationis just the global opt-out andinjectChannelSubscribersis changing how we register the subscribers. afaik we do not unify these two?