Skip to content

Commit 4cd6415

Browse files
logaretmclaude
andauthored
feat(nitro): Instrument HTTP Server (#19225)
Implements HTTP server instrumentation for both `h3` and `srvx` by listening to their tracing channel events. - `h3` TC PR: h3js/h3#1251 - `srvx` TC PR: h3js/srvx#141 Closes #18123 --- **This PR is part of a stack:** - #20358 - #19224 - #19225 👈 - #19304 --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 014114f commit 4cd6415

38 files changed

+1236
-119
lines changed

.github/workflows/canary.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ jobs:
120120
- test-application: 'nestjs-microservices'
121121
build-command: 'test:build-latest'
122122
label: 'nestjs-microservices (latest)'
123+
- test-application: 'nitro-3'
124+
build-command: 'test:build-canary'
125+
label: 'nitro-3 (canary)'
123126

124127
steps:
125128
- name: Check out current commit
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@sentry:registry=http://127.0.0.1:4873
2+
@sentry-internal:registry=http://127.0.0.1:4873
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Nitro E2E Test</title>
6+
</head>
7+
<body>
8+
<h1>Nitro E2E Test App</h1>
9+
<script type="module" src="/src/main.ts"></script>
10+
</body>
11+
</html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as Sentry from '@sentry/nitro';
2+
3+
Sentry.init({
4+
environment: 'qa', // dynamic sampling bias to keep transactions
5+
dsn: process.env.E2E_TEST_DSN,
6+
tunnel: `http://localhost:3031/`, // proxy server
7+
tracesSampleRate: 1,
8+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "nitro-3",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"build": "vite build",
8+
"start": "PORT=3030 NODE_OPTIONS='--import ./instrument.mjs' node .output/server/index.mjs",
9+
"clean": "npx rimraf node_modules pnpm-lock.yaml .output",
10+
"test": "playwright test",
11+
"test:build": "pnpm install && pnpm build",
12+
"test:assert": "pnpm test"
13+
},
14+
"dependencies": {
15+
"@sentry/browser": "latest || *",
16+
"@sentry/nitro": "latest || *"
17+
},
18+
"devDependencies": {
19+
"@playwright/test": "~1.56.0",
20+
"@sentry-internal/test-utils": "link:../../../test-utils",
21+
"@sentry/core": "latest || *",
22+
"nitro": "^3.0.260415-beta",
23+
"rolldown": "latest",
24+
"vite": "latest"
25+
},
26+
"volta": {
27+
"extends": "../../package.json"
28+
}
29+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { getPlaywrightConfig } from '@sentry-internal/test-utils';
2+
3+
const config = getPlaywrightConfig({
4+
startCommand: `pnpm start`,
5+
});
6+
7+
export default config;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineHandler } from 'nitro/h3';
2+
3+
export default defineHandler(() => {
4+
return { status: 'ok' };
5+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineHandler } from 'nitro/h3';
2+
3+
export default defineHandler(() => {
4+
throw new Error('This is a test error');
5+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { getDefaultIsolationScope, setTag } from '@sentry/core';
2+
import { defineHandler } from 'nitro/h3';
3+
4+
export default defineHandler(() => {
5+
setTag('my-isolated-tag', true);
6+
// Check if the tag leaked into the default (global) isolation scope
7+
setTag('my-global-scope-isolated-tag', getDefaultIsolationScope().getScopeData().tags['my-isolated-tag']);
8+
9+
throw new Error('Isolation test error');
10+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { startSpan } from '@sentry/nitro';
2+
import { defineHandler } from 'nitro/h3';
3+
4+
export default defineHandler(() => {
5+
startSpan({ name: 'db.select', op: 'db' }, () => {
6+
// simulate a select query
7+
});
8+
9+
startSpan({ name: 'db.insert', op: 'db' }, () => {
10+
startSpan({ name: 'db.serialize', op: 'serialize' }, () => {
11+
// simulate serializing data before insert
12+
});
13+
});
14+
15+
return { status: 'ok', nesting: true };
16+
});

0 commit comments

Comments
 (0)