Skip to content

feat!: Use handler span op for terminal request handlers - #22871

Merged
msonnb merged 4 commits into
developfrom
ms/js-3105-handler-function-op
Aug 6, 2026
Merged

feat!: Use handler span op for terminal request handlers#22871
msonnb merged 4 commits into
developfrom
ms/js-3105-handler-function-op

Conversation

@msonnb

@msonnb msonnb commented Jul 30, 2026

Copy link
Copy Markdown
Member

Collapses the terminal request-handler span ops across the server frameworks to the cross-framework handler op, so every "this is where the user's route handler runs" span shares one op regardless of framework.

Hono’s app.request() is an internal HTTP dispatch (one sub-app calling another in-process), so it is semantically an inbound server request and is now traced as http.server

Part of #22446

@linear-code

linear-code Bot commented Jul 30, 2026

Copy link
Copy Markdown

JS-3105

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 30.12 kB - -
@sentry/browser - with treeshaking flags 28.32 kB - -
@sentry/browser (incl. Tracing) 47.53 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.54 kB - -
@sentry/browser (incl. Tracing, Profiling) 52.29 kB - -
@sentry/browser (incl. Tracing, Replay) 86.91 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 76.33 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 91.6 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 104.25 kB - -
@sentry/browser (incl. Feedback) 47.45 kB - -
@sentry/browser (incl. sendFeedback) 34.96 kB - -
@sentry/browser (incl. FeedbackAsync) 40.1 kB - -
@sentry/browser (incl. Metrics) 31.2 kB - -
@sentry/browser (incl. Logs) 31.41 kB - -
@sentry/browser (incl. Metrics & Logs) 32.11 kB - -
@sentry/react 31.93 kB - -
@sentry/react (incl. Tracing) 49.79 kB - -
@sentry/vue 35.2 kB - -
@sentry/vue (incl. Tracing) 49.51 kB - -
@sentry/svelte 30.14 kB - -
CDN Bundle 32.13 kB - -
CDN Bundle (incl. Tracing) 47.81 kB - -
CDN Bundle (incl. Logs, Metrics) 33.67 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.19 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.02 kB - -
CDN Bundle (incl. Tracing, Replay) 85.45 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.27 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.59 kB - -
CDN Bundle - uncompressed 95.27 kB - -
CDN Bundle (incl. Tracing) - uncompressed 142.78 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.9 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 146.75 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.6 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 262.03 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 275.74 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 279.69 kB - -
@sentry/nextjs (client) 52.36 kB - -
@sentry/sveltekit (client) 47.99 kB - -
@sentry/core/server 65.54 kB +0.02% +7 B 🔺
@sentry/core/browser 51.82 kB - -
@sentry/node 120.46 kB +0.02% +20 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 84.09 kB +0.01% +1 B 🔺
@sentry/aws-serverless 92.59 kB +0.01% +1 B 🔺
@sentry/cloudflare (withSentry) - minified 217.81 kB - -
@sentry/cloudflare (withSentry) 537.06 kB - -

View base workflow run

@msonnb msonnb changed the title feat(node)!: Use function span op for terminal request handlers feat!: Use function span op for terminal request handlers Jul 30, 2026
@msonnb
msonnb marked this pull request as ready for review July 31, 2026 07:35
@msonnb
msonnb requested review from a team as code owners July 31, 2026 07:35
@msonnb
msonnb requested review from isaacs, mydea, nicohrubec and s1gr1d and removed request for a team July 31, 2026 07:35
Base automatically changed from ms/js-3105-middleware-span-op to develop July 31, 2026 11:17

@nicohrubec nicohrubec left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks like the PR needs to be rebased because it looks like the diff still includes the changes from #22852

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some minor notes/questions, nothing worth gating, imo. Looks good!

At some point when these are all finished, we're going to likely want to add a note in MIGRATION.md to the effect that ignoreSpans: [{ op: 'express.router.middleware' }] or whatever will no longer work, because the op field is getting blunter.


const attributes: Record<string, string> = {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: ORIGIN,
[SENTRY_OP]: REQUEST_HANDLER_OP,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I'm reading this right, this puts a op: 'function' span as the parent of another op: 'function' span (on line 356), which seems a bit odd? Do we need an op here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it's indeed a bit odd, will take a look in a follow-up 👍

/**
* Patches `app.request()` on a Hono instance so that each internal dispatch
* is traced as a `hono.request` span — child of whatever span is active at
* is traced as an `http.server` span — child of whatever span is active at

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I had remembered seeing cases where http.server was assumed to be on root spans, and went looking for cases where it might be used as an indicator of root-ness. But they do not. Every one of them already holds the root before testing the op. So, I think this is safe.


function startMetadataSpan(metadata: SpanMetadata, original: () => unknown): unknown {
const hapiType = metadata.attributes[AttributeNames.HAPI_TYPE];
const op = hapiType === HapiLayerType.PLUGIN ? WEB_SERVER_FUNCTION_SPAN_OP : `${hapiType}.hapi`;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So, we still have op fields with .hapi? I thought that we were trying to make them all known conventional types? (If this is coming in a subsequent PR, ignore, it's fine to do these piecemeal, of course.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes this (and koa, express) will be updated to router which needs to land in conventions first

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same comment here as the .hapi op above

@msonnb
msonnb force-pushed the ms/js-3105-handler-function-op branch from fa5721f to d78a45b Compare August 4, 2026 08:53

@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 d78a45b. Configure here.

@msonnb

msonnb commented Aug 4, 2026

Copy link
Copy Markdown
Member Author

At some point when these are all finished, we're going to likely want to add a note in MIGRATION.md to the effect that ignoreSpans: [{ op: 'express.router.middleware' }] or whatever will no longer work, because the op field is getting blunter.

yup i was planning on doing the MIGRATION note all at once at the end 👍

@msonnb
msonnb marked this pull request as draft August 5, 2026 06:49
@msonnb
msonnb force-pushed the ms/js-3105-handler-function-op branch from d78a45b to d09a042 Compare August 5, 2026 15:35
@msonnb msonnb changed the title feat!: Use function span op for terminal request handlers feat!: Use handler span op for terminal request handlers Aug 5, 2026
@msonnb
msonnb marked this pull request as ready for review August 5, 2026 16:00
@msonnb

msonnb commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

Discussed with @Lms24 that we'll add a new handler op to conventions (release pending) that we use here instead. This avoids collapsing too much into function since request handlers are a pretty common thing across frameworks and SDKs.

msonnb and others added 4 commits August 6, 2026 11:57
Migrate the terminal request-handler span ops across the server
integrations to the cross-framework `function` op, and trace Hono's
internal `app.request()` dispatch as an `http.server` span:

- express: `request_handler.express` -> `function`
- fastify: `request_handler.fastify` -> `function`
- elysia:  `request_handler.elysia`  -> `function`
- nestjs:  `handler.nestjs`          -> `function`
- hono:    `hono.request`            -> `http.server`

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
A plugin-registered hapi route runs the user's request handler, so it is a
terminal handler like the express/fastify/hono routes in this migration.
Map `plugin.hapi` to the cross-framework `function` op; `router.hapi` and
`server.ext.hapi` (framework routing/extension lifecycle) keep their ops.

Op is set via the `sentry.op` attribute only; `hapi.type` is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@msonnb
msonnb force-pushed the ms/js-3105-handler-function-op branch from d09a042 to 9eb802c Compare August 6, 2026 09:57
@msonnb
msonnb merged commit 868c7fc into develop Aug 6, 2026
526 of 529 checks passed
@msonnb
msonnb deleted the ms/js-3105-handler-function-op branch August 6, 2026 11:34
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.

4 participants