Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


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

```json
"sentryTest": {
Expand Down
4 changes: 4 additions & 0 deletions dev-packages/e2e-tests/test-applications/express-5/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist
dist-bun
dist-cloudflare
.wrangler
11 changes: 11 additions & 0 deletions dev-packages/e2e-tests/test-applications/express-5/bun-build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Bundles the app with `@sentry/bun/plugin`. Under `bun run` the SDK cannot inject diagnostics channels into
// packages, so only a bundled app gets the Express and MySQL spans.
import { sentryBunPlugin } from '@sentry/bun/plugin';
import { join } from 'node:path';

await Bun.build({
entrypoints: [join(import.meta.dir, 'src/main.ts')],
target: 'bun',
outdir: join(import.meta.dir, 'dist-bun'),
plugins: [sentryBunPlugin({ telemetry: false })],
});
7 changes: 7 additions & 0 deletions dev-packages/e2e-tests/test-applications/express-5/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"imports": {
"@sentry/deno/import": "./node_modules/@sentry/deno/build/import.mjs"
},
"nodeModulesDir": "manual",
"unstable": ["sloppy-imports"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ services:
db:
image: mysql:8.0
restart: always
container_name: e2e-tests-node-express-v5-mysql
container_name: e2e-tests-express-5-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']
Expand Down
59 changes: 59 additions & 0 deletions dev-packages/e2e-tests/test-applications/express-5/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"name": "express-5",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "tsc",
"start": "node dist/main.js",
"start:bun": "bun dist-bun/main.js",
"start:deno": "deno run -A --preload=@sentry/deno/import --preload=./src/instrument.ts src/main.ts",
"start:cloudflare": "wrangler dev --config ./dist-cloudflare/express_5/wrangler.json --port 3030",
"test": "playwright test",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"test:build": "pnpm install && pnpm build",
"test:build:bun": "pnpm install && pnpm build && bun ./bun-build.mjs",
"test:build:cloudflare": "pnpm install && pnpm build && vite build",
"test:assert": "pnpm test"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.26.0",
"@sentry/bun": "file:../../packed/sentry-bun-packed.tgz",
"@sentry/cloudflare": "file:../../packed/sentry-cloudflare-packed.tgz",
"@sentry/deno": "file:../../packed/sentry-deno-packed.tgz",
"@sentry/node": "file:../../packed/sentry-node-packed.tgz",
"@trpc/server": "11.8.1",
"@trpc/client": "11.8.1",
"@types/express": "^4.17.21",
"@types/node": "^18.19.1",
"express": "^5.1.0",
"mysql": "^2.18.1",
"typescript": "~5.7.2",
"zod": "^4.6.6"
},
"devDependencies": {
"@cloudflare/vite-plugin": "^1.47.0",
"@playwright/test": "1.64.1",
"@sentry-internal/test-utils": "file:../../packed/sentry-internal-test-utils-packed.tgz",
"@sentry/core": "file:../../packed/sentry-core-packed.tgz",
"vite": "^8.1.5",
"wrangler": "^4.120.0"
},
"sentryTest": {
"optionalVariants": [
{
"runtime": "bun",
"build-command": "pnpm test:build:bun",
"label": "express-5 (bun)"
},
{
"runtime": "deno",
"label": "express-5 (deno)"
},
{
"runtime": "cloudflare",
"build-command": "pnpm test:build:cloudflare",
"label": "express-5 (cloudflare)"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { getPlaywrightConfig, getRuntime } from '@sentry-internal/test-utils';

const startCommands = {
node: 'pnpm start',
bun: 'pnpm start:bun',
deno: 'pnpm start:deno',
cloudflare: 'pnpm start:cloudflare',
};

const config = getPlaywrightConfig({
startCommand: startCommands[getRuntime()],
});

export default {
...config,
globalSetup: './global-setup.mjs',
globalTeardown: './global-teardown.mjs',
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
allowBuilds:
esbuild: true
workerd: true
minimumReleaseAge: 0
overrides:
'@types/qs': '6.9.17'
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
import * as Sentry from '@sentry/node';

declare global {
namespace globalThis {
var transactionIds: string[];
}
}

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
includeLocalVariables: true,
debug: !!process.env.DEBUG,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
integrations: [Sentry.nodeRuntimeMetricsIntegration({ collectionIntervalMs: 1_000 })],
});

import { TRPCError, initTRPC } from '@trpc/server';
import * as trpcExpress from '@trpc/server/adapters/express';
import express from 'express';
// @ts-ignore -- `mysql` ships no type declarations; only needed at runtime.
import mysql from 'mysql';
import { z } from 'zod';
import { mcpRouter } from './mcp';
import * as Sentry from './sentry';

const connection = mysql.createConnection({
user: 'root',
password: 'docker',
});
declare global {
namespace globalThis {
var transactionIds: string[];
}
}

const app = express();
const port = 3030;
export const app = express();

app.use(mcpRouter);

Expand Down Expand Up @@ -60,8 +43,15 @@ app.get('/test-param/:param', function (req, res) {
});

app.get('/test-mysql', function (req, res) {
// One connection per request, because on Cloudflare a socket only works in the request that opened it.
const connection = mysql.createConnection({
user: 'root',
password: 'docker',
});

connection.query('SELECT 1 + 1 AS solution', function () {
connection.query('SELECT NOW()', ['1', '2'], () => {
connection.end();
res.send({ status: 'ok' });
});
});
Expand Down Expand Up @@ -103,6 +93,20 @@ app.get('/test-local-variables-caught', function (req, res) {
res.send({ exceptionId, randomVariableToRecord });
});

app.get('/test-isolation/:id', async function (req, res) {
Sentry.setTag('isolation-id', req.params.id);
// Lets the concurrent requests of the isolation test overlap.
await new Promise(resolve => setTimeout(resolve, 200));
Sentry.captureException(new Error(`Isolated error ${req.params.id}`));
res.send({});
});

// The test runs a server on port 3040 that records the headers of the request.
app.get('/test-outgoing-fetch', async function (_req, res) {
const response = await fetch('http://localhost:3040/outgoing');
res.send({ status: response.status });
});

// @ts-ignore
app.use(function onError(err, req, res, next) {
// The error id is attached to `res.sentry` to be returned
Expand All @@ -111,10 +115,6 @@ app.use(function onError(err, req, res, next) {
res.end(res.sentry + '\n');
});

app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});

Sentry.addEventProcessor(event => {
global.transactionIds = global.transactionIds || [];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/bun';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
debug: !!process.env.DEBUG,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/deno';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
debug: !!process.env.DEBUG,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as Sentry from '@sentry/node';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_DSN,
includeLocalVariables: true,
debug: !!process.env.DEBUG,
tunnel: `http://localhost:3031/`, // proxy server
tracesSampleRate: 1,
integrations: [Sentry.nodeRuntimeMetricsIntegration({ collectionIntervalMs: 1_000 })],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import './instrument';

import { app } from './app';

const port = 3030;

app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mc
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
import { z } from 'zod';
import { wrapMcpServerWithSentry } from '@sentry/node';
import { wrapMcpServerWithSentry } from './sentry';

// Helper to check if request is an initialize request (compatible with all MCP SDK versions)
function isInitializeRequest(body: unknown): boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@sentry/bun';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@sentry/cloudflare';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '@sentry/deno';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// The app imports the Sentry API from this file. Each other runtime has a `sentry.<runtime>.ts` with its own SDK.
export * from '@sentry/node';
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { startEventProxyServer } from '@sentry-internal/test-utils';

startEventProxyServer({
port: 3031,
proxyServerName: 'node-express-v5',
proxyServerName: 'express-5',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { getRuntime } from '@sentry-internal/test-utils';

export const RUNTIME = getRuntime();
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { expect, test } from '@playwright/test';
import { waitForError, collectStreamedSpansUntilSegment } from '@sentry-internal/test-utils';
import { RUNTIME } from './constants';

test('Sends correct error event', async ({ baseURL }) => {
const errorEventPromise = waitForError('node-express-v5', event => {
const errorEventPromise = waitForError('express-5', event => {
return !event.type && event.exception?.values?.[0]?.value === 'This is an exception with id 123';
});

const segmentEventPromise = collectStreamedSpansUntilSegment('node-express-v5', 'GET /test-exception/:id');
const segmentEventPromise = collectStreamedSpansUntilSegment('express-5', 'GET /test-exception/:id');

await fetch(`${baseURL}/test-exception/123`);

Expand Down Expand Up @@ -49,7 +50,12 @@ test('Sends correct error event', async ({ baseURL }) => {
});

test('Should record caught exceptions with local variable', async ({ baseURL }) => {
const errorEventPromise = waitForError('node-express-v5', event => {
test.skip(
RUNTIME !== 'node',
'`includeLocalVariables` reads the variables with `node:inspector`, which works on Node only.',
);

const errorEventPromise = waitForError('express-5', event => {
return event.transaction === 'GET /test-local-variables-caught';
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { waitForEnvelopeItem } from '@sentry-internal/test-utils';
import type { SerializedLogContainer } from '@sentry/core';

test('should send logs', async ({ baseURL }) => {
const logEnvelopePromise = waitForEnvelopeItem('node-express-v5', envelope => {
const logEnvelopePromise = waitForEnvelopeItem('express-5', envelope => {
return envelope[0].type === 'log' && (envelope[1] as SerializedLogContainer).items[0]?.level === 'debug';
});

Expand Down
Loading
Loading