Skip to content

feat(core): emit low cardinality request handler span names - #23614

Open
isaacs wants to merge 2 commits into
developfrom
isaacs/low-cardinality-request-handler-span-names
Open

feat(core): emit low cardinality request handler span names#23614
isaacs wants to merge 2 commits into
developfrom
isaacs/low-cardinality-request-handler-span-names

Conversation

@isaacs

@isaacs isaacs commented Aug 26, 2026

Copy link
Copy Markdown
Member

Name handler spans after the route they serve when span streaming is enabled, or Request handler if no route set. Static mode left as is.

Drop Hapi method, as the template dictates. NestJS resolves no route when the span starts. The NestJS callback name stays on nestjs.callback.

Elysia sets context.route when the request enters the compiled handler, which is before the Handle phase reports. Read it in the trace listener so streamed handler spans carry the route instead of the Request handler fallback. The fallback now applies only when the context has no route.

Set code.function.name only on the child spans this renames, and only when the handler has a name. Static mode keeps the handler name in the span name, so the attribute adds nothing there, and an anonymous handler has no name to record.

Register the Fastify test route from a plugin. Fastify installs the SDK's onRoute hook when it flushes its plugin list, which is after root-level routes are in place. A root-level route therefore produces no route handler span, and the test never reached that code path.

Also: correct REQUEST_HANDLER_SPAN_NAME_FALLBACK: the conventions spell the fallback Request handler, and its @see link pointed at the resource section.

closes #23533

@isaacs

isaacs commented Aug 26, 2026

Copy link
Copy Markdown
Member Author

bugbot run

@isaacs isaacs changed the title feat(core): emit low cardinality request handler span names (#23533) feat(core): emit low cardinality request handler span names Aug 26, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3bf00a6. Configure here.

@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 28.57 kB - -
@sentry/browser - with treeshaking flags 26.92 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.82 kB - -
@sentry/browser (incl. Tracing) 48.59 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.6 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.51 kB - -
@sentry/browser (incl. Tracing, Replay) 88.04 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.45 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 92.75 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 105.45 kB - -
@sentry/browser (incl. Feedback) 45.81 kB - -
@sentry/browser (incl. sendFeedback) 33.36 kB - -
@sentry/browser (incl. FeedbackAsync) 38.46 kB - -
@sentry/browser (incl. Metrics) 29.51 kB - -
@sentry/browser (incl. Logs) 29.8 kB - -
@sentry/browser (incl. Metrics & Logs) 30.43 kB - -
@sentry/react 30.31 kB - -
@sentry/react (incl. Tracing) 50.8 kB - -
@sentry/vue 35.69 kB - -
@sentry/vue (incl. Tracing) 50.82 kB - -
@sentry/svelte 28.59 kB - -
CDN Bundle 30.36 kB - -
CDN Bundle (incl. Tracing) 49.06 kB - -
CDN Bundle (incl. Logs, Metrics) 32.56 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 50.94 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 72.98 kB - -
CDN Bundle (incl. Tracing, Replay) 86.56 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.44 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 92.34 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.27 kB - -
CDN Bundle - uncompressed 89.97 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.74 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.26 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.43 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.36 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.17 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 271.85 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.87 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 285.53 kB - -
@sentry/nextjs (client) 53.34 kB - -
@sentry/sveltekit (client) 49.02 kB - -
@sentry/core/server 65.23 kB +0.03% +15 B 🔺
@sentry/core/browser 52.33 kB -0.01% -1 B 🔽
@sentry/node 121.76 kB +0.06% +70 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.18 kB - -
@sentry/node - without tracing 87.61 kB +0.1% +79 B 🔺
@sentry/aws-serverless 96.03 kB +0.1% +87 B 🔺
@sentry/cloudflare (withSentry) - minified 199.48 kB - -
@sentry/cloudflare (withSentry) 495.44 kB - -

View base workflow run

@isaacs
isaacs force-pushed the isaacs/low-cardinality-request-handler-span-names branch 2 times, most recently from 3293c93 to 7673348 Compare August 26, 2026 03:20

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7673348. Configure here.

Comment thread packages/elysia/src/withElysia.ts
@isaacs
isaacs force-pushed the isaacs/low-cardinality-request-handler-span-names branch from 277e858 to 9b21ab4 Compare August 26, 2026 15:09
@isaacs
isaacs marked this pull request as ready for review August 26, 2026 15:11
@isaacs
isaacs requested review from a team as code owners August 26, 2026 15:11
@isaacs
isaacs requested review from JPeer264, andreiborza, chargome and s1gr1d and removed request for a team August 26, 2026 15:11
Name `handler` spans after the route they serve when span streaming is
enabled, or `Request handler` if no route set. Static mode left as is.

Drop Hapi method, as the template dictates. NestJS resolves no
route when the span starts. The NestJS callback name stays on
`nestjs.callback`.

Elysia sets `context.route` when the request enters the compiled
handler, which is before the `Handle` phase reports. Read it in the
trace listener so streamed handler spans carry the route instead of
the `Request handler` fallback. The fallback now applies only when
the context has no route.

Set `code.function.name` only on the child spans this renames, and
only when the handler has a name. Static mode keeps the handler name
in the span name, so the attribute adds nothing there, and an
anonymous handler has no name to record.

Register the Fastify test route from a plugin. Fastify installs the
SDK's `onRoute` hook when it flushes its plugin list, which is after
root-level routes are in place. A root-level route therefore produces
no route handler span, and the test never reached that code path.

Also: correct `REQUEST_HANDLER_SPAN_NAME_FALLBACK`: the conventions
spell the fallback `Request handler`, and its `@see` link pointed at the
resource section.

closes #23533

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@isaacs
isaacs force-pushed the isaacs/low-cardinality-request-handler-span-names branch from 9b21ab4 to 667c4bd Compare August 26, 2026 15:12
Comment on lines 15 to 22
getIsolationScope,
getRootSpan,
getTraceData,
hasSpanStreamingEnabled,
REQUEST_HANDLER_SPAN_NAME_FALLBACK,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
setHttpStatus,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The function hasSpanStreamingEnabled is imported twice from @sentry/core in the same import statement, which is a syntax error and will prevent the module from loading.
Severity: CRITICAL

Suggested Fix

Remove one of the two duplicate hasSpanStreamingEnabled imports from the destructured import list in packages/elysia/src/withElysia.ts to resolve the syntax error.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: packages/elysia/src/withElysia.ts#L15-L22

Potential issue: The `import` statement from `@sentry/core` in
`packages/elysia/src/withElysia.ts` includes the named import `hasSpanStreamingEnabled`
twice. In JavaScript and TypeScript, duplicate bindings within a single `import`
statement are a syntax error. This will cause a `SyntaxError` when the module is parsed,
preventing the file from loading and breaking the entire `@sentry/elysia` integration
for all users. The application will fail to start if it uses this package.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit low cardinality request handler span names

1 participant