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
20 changes: 20 additions & 0 deletions dev-packages/e2e-tests/test-applications/nitro-3-tunnel/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Nitro Tunnel E2E Test</title>
</head>
<body>
<script type="module">
import * as Sentry from '@sentry/browser';

Sentry.init({
dsn: 'http://public@localhost:3031/1337',
// Plain Nitro has no client SDK to pass `baseURL` on, so the browser names it. The server picks it up itself.
tunnel: { basePath: '/app' },
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: 1,
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as Sentry from '@sentry/nitro';

Sentry.init({
dsn: 'http://public@localhost:3031/1337',
integrations: [Sentry.serveTunnelIntegration()],
tracesSampleRate: 1,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "nitro-3-tunnel",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "vite build",
"start": "PORT=3030 NODE_OPTIONS='--import ./instrument.mjs' node .output/server/index.mjs",
"clean": "npx rimraf node_modules pnpm-lock.yaml .output",
"test:build": "pnpm install && pnpm build",
"test:assert": "TEST_ENV=production playwright test && TEST_ENV=development playwright test"
},
"dependencies": {
"@sentry/browser": "latest || *",
"@sentry/nitro": "latest || *"
},
"devDependencies": {
"@playwright/test": "1.64.1",
"@sentry-internal/test-utils": "file:../../packed/sentry-internal-test-utils-packed.tgz",
"nitro": "^3.0.260522-beta",
"vite": "latest"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getPlaywrightConfig } from '@sentry-internal/test-utils';

export default getPlaywrightConfig({
startCommand:
process.env.TEST_ENV === 'development'
? `PORT=3030 NODE_OPTIONS='--import ./instrument.mjs' pnpm exec vite dev --port 3030`
: `pnpm start`,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minimumReleaseAge: 0
overrides:
'unstorage': '2.0.0-alpha.7'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineHandler } from 'nitro/h3';

export default defineHandler(() => ({ ok: true }));
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('Tunnel test error');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineHandler, HTTPError } from 'nitro/h3';

export default defineHandler(event => {
if (event.req.method === 'POST') {
throw new HTTPError({ status: 401, statusText: 'blocked by user auth' });
}
});
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-tunnel',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runManagedTunnelSuite } from '@sentry-internal/test-utils/tunnel-suite';

runManagedTunnelSuite({ appName: 'nitro-3-tunnel', basePath: '/app' });
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { withSentryConfig } from '@sentry/nitro';
import { nitro } from 'nitro/vite';
import { defineConfig } from 'vite';

export default defineConfig({
// @ts-expect-error The Nitro plugin's types don't accept the config `withSentryConfig` returns
plugins: [nitro(withSentryConfig({ serverDir: './server', baseURL: '/app/' }))],
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import * as Sentry from '@sentry/nitro';

Sentry.init({
environment: 'qa', // dynamic sampling bias to keep transactions
dsn: process.env.E2E_TEST_TUNNEL ? 'http://public@localhost:3031/1337' : process.env.E2E_TEST_DSN,
dsn: process.env.E2E_TEST_DSN,
tunnel: `http://localhost:3031/`, // proxy server
integrations: process.env.E2E_TEST_TUNNEL ? [Sentry.serveTunnelIntegration()] : [],
tracesSampleRate: 1,
});
19 changes: 1 addition & 18 deletions dev-packages/e2e-tests/test-applications/nitro-3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
"clean": "npx rimraf node_modules pnpm-lock.yaml .output",
"test": "playwright test",
"test:build": "pnpm install && pnpm build",
"test:assert": "pnpm test",
"test:build:tunnel-basepath": "pnpm install && E2E_TEST_TUNNEL=1 E2E_TEST_BASE_PATH=/app pnpm build",
"test:assert:tunnel-basepath": "E2E_TEST_TUNNEL=1 E2E_TEST_BASE_PATH=/app playwright test tunnel",
"test:assert:tunnel-basepath-dev": "TEST_ENV=development E2E_TEST_TUNNEL=1 E2E_TEST_BASE_PATH=/app playwright test tunnel"
"test:assert": "pnpm test"
},
"dependencies": {
"@sentry/browser": "latest || *",
Expand All @@ -26,19 +23,5 @@
"nitro": "^3.0.260522-beta",
"rolldown": "latest",
"vite": "latest"
},
"sentryTest": {
"variants": [
{
"build-command": "pnpm test:build:tunnel-basepath",
"assert-command": "pnpm test:assert:tunnel-basepath",
"label": "nitro-3 (tunnel-basepath)"
},
{
"build-command": "pnpm install",
"assert-command": "pnpm test:assert:tunnel-basepath-dev",
"label": "nitro-3 (tunnel-basepath-dev)"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { defineHandler, getQuery, HTTPError, setResponseHeader } from 'nitro/h3';
import { defineHandler, getQuery, setResponseHeader } from 'nitro/h3';

export default defineHandler(event => {
// The tunnel variant checks that the managed tunnel answers before an auth middleware like this one.
if (process.env.E2E_TEST_TUNNEL && event.req.method === 'POST' && event.req.headers.get('x-auth') !== 'ok') {
throw new HTTPError({ status: 401, statusText: 'blocked by user auth' });
}

setResponseHeader(event, 'x-sentry-test-middleware', 'executed');

const query = getQuery(event);
Expand Down
12 changes: 2 additions & 10 deletions dev-packages/e2e-tests/test-applications/nitro-3/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import * as Sentry from '@sentry/browser';

declare const __E2E_TEST_TUNNEL__: boolean;
declare const __E2E_TEST_BASE_PATH__: string;

// Let's us test trace propagation
Sentry.init({
environment: 'qa',
dsn: __E2E_TEST_TUNNEL__ ? 'http://public@localhost:3031/1337' : 'https://public@dsn.ingest.sentry.io/1337',
// Plain Nitro has no client SDK to pass `baseURL` on, so the browser names it. The server picks it up itself.
tunnel: __E2E_TEST_TUNNEL__
? __E2E_TEST_BASE_PATH__
? { basePath: __E2E_TEST_BASE_PATH__ }
: true
: 'http://localhost:3031/', // proxy server
dsn: 'https://public@dsn.ingest.sentry.io/1337',
tunnel: 'http://localhost:3031/', // proxy server
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: 1.0,
});

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ import { nitro } from 'nitro/vite';
import { defineConfig } from 'vite';

export default defineConfig({
define: {
__E2E_TEST_TUNNEL__: JSON.stringify(!!process.env.E2E_TEST_TUNNEL),
__E2E_TEST_BASE_PATH__: JSON.stringify(process.env.E2E_TEST_BASE_PATH ?? ''),
},
plugins: [
nitro(
// FIXME: Nitro plugin has a type issue
// @ts-expect-error
withSentryConfig({
serverDir: './server',
experimental: { tasks: true },
...(process.env.E2E_TEST_BASE_PATH && { baseURL: `${process.env.E2E_TEST_BASE_PATH}/` }),
}),
),
],
Expand Down
11 changes: 11 additions & 0 deletions dev-packages/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
"types": "./build/types/cloudflare.d.ts",
"default": "./build/cjs/cloudflare.js"
}
},
"./tunnel-suite": {
"import": {
"types": "./build/types/tunnel-suite.d.ts",
"default": "./build/esm/tunnel-suite.js"
},
"require": {
"types": "./build/types/tunnel-suite.d.ts",
"default": "./build/cjs/tunnel-suite.js"
}
}
},
"sideEffects": false,
Expand All @@ -61,6 +71,7 @@
"@playwright/test": "1.64.1"
},
"dependencies": {
"@sentry/conventions": "^0.33.0",
"express": "^4.22.3",
"ws": "^8.20.1"
},
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/test-utils/rollup.npm.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollu

export default makeNPMConfigVariants(
makeBaseNPMConfig({
entrypoints: ['src/index.ts', 'src/cli.ts', 'src/cloudflare.ts'],
entrypoints: ['src/index.ts', 'src/cli.ts', 'src/cloudflare.ts', 'src/tunnel-suite.ts'],
packageSpecificConfig: {
output: {
// set exports to 'named' or 'auto' so that rollup doesn't warn
Expand Down
Loading
Loading