Skip to content

Commit 271954d

Browse files
JPeer264claude
andcommitted
test(e2e): Run express-5 on Bun, Deno and Cloudflare
Renames `node-express-v5` to `express-5` and adds optional Bun, Deno and Cloudflare variants next to the required Node job. Each runtime inits its own SDK, and the app reads the Sentry API from `src/sentry.ts`, which each variant replaces with its SDK. - Node still runs the CommonJS build. `src/main.ts` is the entry now, so that the Worker can import the app without the Node init. - Bun bundles `src/main.ts` with `@sentry/bun/plugin`. - Deno runs the TypeScript sources with `--preload=@sentry/deno/import`. - Cloudflare builds with Vite and `sentryCloudflareVitePlugin`. The app registers its routes at module scope, like the Express docs show. New tests cover parameterized route names, per-request isolation, incoming trace continuation and outgoing `fetch` propagation. They pass on all four runtimes without a `RUNTIME` branch. Tests that branch on `RUNTIME`: - Local variables and the Node runtime metrics run on Node only. - The MCP SSE transport is skipped on Cloudflare. workerd cancels the write to the response of another request, also without Sentry. - The `http.server` span has no `http.response.status_text` on Bun, and comes from the Worker `Request` on Cloudflare. The MySQL route opens its connection in the request, because on Cloudflare a socket only works in the request that opened it. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent ae0f584 commit 271954d

38 files changed

Lines changed: 387 additions & 128 deletions

‎dev-packages/e2e-tests/README.md‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ is the reference setup.
190190
`deno run -A --preload=@sentry/deno/import --preload=./instrument.deno.mjs ./node_modules/@react-router/serve/bin.cjs ./build/server/index.js`.
191191
The app's `deno.json` maps `@sentry/deno/import` to `node_modules`, because the e2e dependencies are `file:` tarballs
192192
that `npm:@sentry/deno/import` does not resolve. `nuxt-4` starts the Nitro output with no preload:
193-
`bun .output/server/index.mjs` and `deno run -A .output/server/index.mjs`.
193+
`bun .output/server/index.mjs` and `deno run -A .output/server/index.mjs`. `express-5` builds CommonJS for Node, so
194+
Deno runs its TypeScript sources (`src/main.ts`), and `deno.json` turns on `sloppy-imports` for the relative imports
195+
without a file extension.
194196
- **Cloudflare**: the app has the Cloudflare dependencies installed all the time. The Cloudflare build has its own
195197
`vite.cloudflare.config.ts` with `@cloudflare/vite-plugin` and `sentryCloudflareVitePlugin` from
196198
`@sentry/cloudflare/vite`, which the runner uses in place of `vite.config.ts` (see runtime-specific files). List the
@@ -199,9 +201,10 @@ is the reference setup.
199201
separate file (for example `workers/app.ts`) and exports a plain handler: the Sentry plugin wraps it with
200202
`withSentry` and reads the init options from `instrument.server.ts` next to the entry. The start command runs
201203
`wrangler dev` on the build output. Code at module scope must not do I/O (for example open a database connection),
202-
because workerd does not allow it. `nextjs-16` has no Vite build: its Cloudflare variant builds with
203-
`opennextjs-cloudflare build --config wrangler.opennext.jsonc` and wraps the generated Worker in `worker.ts` with
204-
`withSentry` from `@sentry/nextjs/cloudflare`.
204+
because workerd does not allow it. A socket also works only in the request that opened it, so `express-5` opens its
205+
MySQL connection in the request. In an app without `"type": "module"`, name the config `vite.config.mts`. `nextjs-16`
206+
has no Vite build: its Cloudflare variant builds with `opennextjs-cloudflare build --config wrangler.opennext.jsonc`
207+
and wraps the generated Worker in `worker.ts` with `withSentry` from `@sentry/nextjs/cloudflare`.
205208
- **Cloudflare in `vite dev`**: to run the Worker in `vite dev` (for example the dev tests of the `hono-4` Cloudflare
206209
variant), start it with `CLOUDFLARE_INCLUDE_PROCESS_ENV=true vite dev`. The runner gives `E2E_TEST_DSN` to the app
207210
only as a process env var. `wrangler dev` adds it to the Worker `env` with `--var "E2E_TEST_DSN:$E2E_TEST_DSN"`, but
@@ -221,9 +224,10 @@ is the reference setup.
221224
- **Bun**: under `bun run` before Bun 1.4.6 the SDK cannot inject diagnostics channels into packages that stay outside
222225
the build (for example Express behind `react-router-serve`), so those produce no spans on Bun. Where a test depends on them, branch
223226
on `RUNTIME` and say why in a comment. An app that starts its own server can instead bundle it with
224-
`@sentry/bun/plugin`, as `nestjs-12/bun-build.mjs` does. Bun 1.3 renames classes in bundles (`class Foo2`), which
225-
changes span names taken from class names, so `nestjs-12` pins Bun 1.4 (see #26289). `nuxt-4` builds with
226-
`bun --bun nuxt build` on Bun, because the Nitro prerenderer loads its `bun-sqlite` connector in the build process.
227+
`@sentry/bun/plugin`, as `nestjs-12/bun-build.mjs` and `express-5/bun-build.mjs` do. Bun 1.3 renames classes in
228+
bundles (`class Foo2`), which changes span names taken from class names, so `nestjs-12` pins Bun 1.4 (see #26289).
229+
`nuxt-4` builds with `bun --bun nuxt build` on Bun, because the Nitro prerenderer loads its `bun-sqlite` connector in
230+
the build process.
227231

228232
```json
229233
"sentryTest": {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
dist-bun
3+
dist-cloudflare
4+
.wrangler
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Bundles the app with `@sentry/bun/plugin`. Under `bun run` the SDK cannot inject diagnostics channels into
2+
// packages, so only a bundled app gets the Express and MySQL spans.
3+
import { sentryBunPlugin } from '@sentry/bun/plugin';
4+
import { join } from 'node:path';
5+
6+
await Bun.build({
7+
entrypoints: [join(import.meta.dir, 'src/main.ts')],
8+
target: 'bun',
9+
outdir: join(import.meta.dir, 'dist-bun'),
10+
plugins: [sentryBunPlugin({ telemetry: false })],
11+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"imports": {
3+
"@sentry/deno/import": "./node_modules/@sentry/deno/build/import.mjs"
4+
},
5+
"nodeModulesDir": "manual",
6+
"unstable": ["sloppy-imports"]
7+
}

dev-packages/e2e-tests/test-applications/node-express-v5/docker-compose.yml renamed to dev-packages/e2e-tests/test-applications/express-5/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ services:
22
db:
33
image: mysql:8.0
44
restart: always
5-
container_name: e2e-tests-node-express-v5-mysql
5+
container_name: e2e-tests-express-5-mysql
66
# The `mysql` 2.x driver doesn't speak MySQL 8's default
77
# `caching_sha2_password` auth, so force the legacy plugin.
88
command: ['--default-authentication-plugin=mysql_native_password']

dev-packages/e2e-tests/test-applications/node-express-v5/global-setup.mjs renamed to dev-packages/e2e-tests/test-applications/express-5/global-setup.mjs

File renamed without changes.

dev-packages/e2e-tests/test-applications/node-express-v5/global-teardown.mjs renamed to dev-packages/e2e-tests/test-applications/express-5/global-teardown.mjs

File renamed without changes.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "express-5",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"build": "tsc",
7+
"start": "node dist/main.js",
8+
"start:bun": "bun dist-bun/main.js",
9+
"start:deno": "deno run -A --preload=@sentry/deno/import --preload=./src/instrument.ts src/main.ts",
10+
"start:cloudflare": "wrangler dev --config ./dist-cloudflare/express_5/wrangler.json --port 3030",
11+
"test": "playwright test",
12+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
13+
"test:build": "pnpm install && pnpm build",
14+
"test:build:bun": "pnpm install && pnpm build && bun ./bun-build.mjs",
15+
"test:build:cloudflare": "pnpm install && pnpm build && vite build",
16+
"test:assert": "pnpm test"
17+
},
18+
"dependencies": {
19+
"@modelcontextprotocol/sdk": "^1.26.0",
20+
"@sentry/bun": "file:../../packed/sentry-bun-packed.tgz",
21+
"@sentry/cloudflare": "file:../../packed/sentry-cloudflare-packed.tgz",
22+
"@sentry/deno": "file:../../packed/sentry-deno-packed.tgz",
23+
"@sentry/node": "file:../../packed/sentry-node-packed.tgz",
24+
"@trpc/server": "11.8.1",
25+
"@trpc/client": "11.8.1",
26+
"@types/express": "^4.17.21",
27+
"@types/node": "^18.19.1",
28+
"express": "^5.1.0",
29+
"mysql": "^2.18.1",
30+
"typescript": "~5.7.2",
31+
"zod": "~3.25.0"
32+
},
33+
"devDependencies": {
34+
"@cloudflare/vite-plugin": "^1.47.0",
35+
"@playwright/test": "1.64.1",
36+
"@sentry-internal/test-utils": "file:../../packed/sentry-internal-test-utils-packed.tgz",
37+
"@sentry/core": "file:../../packed/sentry-core-packed.tgz",
38+
"vite": "^8.1.5",
39+
"wrangler": "^4.120.0"
40+
},
41+
"sentryTest": {
42+
"optionalVariants": [
43+
{
44+
"runtime": "bun",
45+
"build-command": "pnpm test:build:bun",
46+
"label": "express-5 (bun)"
47+
},
48+
{
49+
"runtime": "deno",
50+
"label": "express-5 (deno)"
51+
},
52+
{
53+
"runtime": "cloudflare",
54+
"build-command": "pnpm test:build:cloudflare",
55+
"label": "express-5 (cloudflare)"
56+
}
57+
]
58+
}
59+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { getPlaywrightConfig, getRuntime } from '@sentry-internal/test-utils';
2+
3+
const startCommands = {
4+
node: 'pnpm start',
5+
bun: 'pnpm start:bun',
6+
deno: 'pnpm start:deno',
7+
cloudflare: 'pnpm start:cloudflare',
8+
};
9+
10+
const config = getPlaywrightConfig({
11+
startCommand: startCommands[getRuntime()],
12+
});
13+
14+
export default {
15+
...config,
16+
globalSetup: './global-setup.mjs',
17+
globalTeardown: './global-teardown.mjs',
18+
};

dev-packages/e2e-tests/test-applications/node-express-v5/pnpm-workspace.yaml renamed to dev-packages/e2e-tests/test-applications/express-5/pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
allowBuilds:
2+
esbuild: true
3+
workerd: true
14
minimumReleaseAge: 0
25
overrides:
36
'@types/qs': '6.9.17'

0 commit comments

Comments
 (0)