-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core): Emit low-cardinality http.server span names when streaming #23596
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| tracesSampleRate: 1.0, | ||
| transport: loggingTransport, | ||
| traceLifecycle: 'stream', | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { sendPortToRunner } from '@sentry-internal/node-integration-tests'; | ||
| import http from 'http'; | ||
|
|
||
| // A bare `node:http` server: no framework ever resolves a route, so the server span | ||
| // keeps whatever name it was given at span start. | ||
| const server = http.createServer((_request, response) => { | ||
| response.end('Hello Node.js Server!'); | ||
| }); | ||
|
|
||
| server.listen(0, () => { | ||
| sendPortToRunner(server.address().port); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { afterAll, describe, expect } from 'vitest'; | ||
| import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner'; | ||
|
|
||
| describe('httpServerSpans-streamed (no route)', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| createEsmAndCjsTests(__dirname, 'server.mjs', 'instrument.mjs', (createRunner, test) => { | ||
| test('names the server span after the request method, not the URL path', async () => { | ||
| const runner = createRunner() | ||
| .expect({ | ||
| span: container => { | ||
| const serverSpan = container.items.find( | ||
| item => | ||
| item.attributes['sentry.op']?.type === 'string' && item.attributes['sentry.op'].value === 'http.server', | ||
| ); | ||
|
|
||
| expect(serverSpan).toBeDefined(); | ||
| expect(serverSpan?.is_segment).toBe(true); | ||
| // Without a route the name must not carry the URL path. | ||
| expect(serverSpan?.name).toBe('GET'); | ||
| expect(serverSpan?.attributes['sentry.source']).toEqual({ type: 'string', value: 'url' }); | ||
|
Check failure on line 23 in dev-packages/node-integration-tests/suites/tracing/httpServerSpans-streamed-unrouted/test.ts
|
||
| // The path is still available as an attribute, which is what `ignoreSpans`/`tracesSampler` match on. | ||
| expect(serverSpan?.attributes['url.path']).toEqual({ type: 'string', value: '/users/42' }); | ||
| }, | ||
| }) | ||
| .start(); | ||
|
|
||
| await runner.makeRequest('get', '/users/42'); | ||
|
|
||
| await runner.completed(); | ||
| }); | ||
| }); | ||
| }); | ||
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.
Routed spans keep method-only names
High Severity
With streaming enabled,
http.serverspans start named only after the request method, assuming route instrumentations later rename them toMETHOD /route. Native Express and similar integrations only callsetTransactionNameon the isolation scope and never update the span, so routed requests keep a method-only name.Additional Locations (1)
packages/node/src/integrations/http/httpServerSpansIntegration.ts#L165-L170Reviewed by Cursor Bugbot for commit 75d96fd. Configure here.