Skip to content

feat(server-utils): Implement orchestrion-based express integration - #21889

Merged
mydea merged 11 commits into
developfrom
fn/express-orchestrion
Jul 8, 2026
Merged

feat(server-utils): Implement orchestrion-based express integration#21889
mydea merged 11 commits into
developfrom
fn/express-orchestrion

Conversation

@mydea

@mydeamydea commented Jul 1, 2026

Copy link
Copy Markdown
Member

Closes#20917

This adds a new expressChannelIntegration based on orchestrion. It should keep feature parity — we have a lot of Express tests, and the core tracing tests now run against this integration (via the orchestrion variant), which gives good coverage for now.

A follow up would be to also handle the error handler automatically where possible.

Route resolution: metadata is only set for genuinely matched routes

The OpenTelemetry Express integration patches every layer's handle, reconstructs the route from the layers that ran (getConstructedRoute), and validates it against the request URL (getActualMatchedRoute) to discard paths that didn't truly match.

This integration instead hooks Express's per-layer Layer.prototype.handle_request (v4) / handleRequest (v5, the router package). Express only calls that method for a layer whose path and method matched, so a request_handler span only ever exists for a route that genuinely matched. Route metadata — http.route, the root http.server span's route attribute, and the transaction name — is therefore taken directly from the matched route, with no separate reconstruct/validate step.

The observable consequence, which is intentional:

  • 404 / no route matched — no route-dispatch layer runs, so no request_handler span is created and no route (or route-based transaction name) is set.
  • Only middleware ran (no route matched) — middleware produces middleware-type spans, which never set route attributes.

This is a different mechanism from the OTel path, but it lands on the same net result: getActualMatchedRoute returns undefined in exactly these cases, so the OTel integration also emits no route there. We get it structurally, from the injection point, rather than by validating after the fact.

@mydeamydea changed the title Fn/express orchestrionfeat(server-utils): Implement orchestrion-based express integrationJul 1, 2026
Comment threadpackages/node/src/sdk/experimentalUseDiagnosticsChannelInjection.ts Outdated
@mydea
mydeaforce-pushed the fn/express-orchestrion branch from b086dd5 to 9b43cbbCompareJuly 1, 2026 14:06
@mydea
mydeaforce-pushed the fn/express-orchestrion branch 3 times, most recently from d72f9d1 to e9acef3CompareJuly 6, 2026 09:50
@mydeamydea self-assigned this Jul 6, 2026
@mydea
mydea marked this pull request as ready for review July 6, 2026 10:37
@mydea
mydea requested a review from a team as a code ownerJuly 6, 2026 10:37
@mydea
mydea requested review from JPeer264 and andreiborza and removed request for a teamJuly 6, 2026 10:37

// Express only treats a 4-arg handler as an error handler and skips it in
// the normal request pipeline; match the OTel integration and don't trace it.
if (layer.handle?.length === 4) {

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.

super-l: In theory we could add all of these checks in one if:

!layer||!Array.isArray(args)||layer.handle?.length===4|| ...

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I think it's fine to keep it like this to keep the comments and things a bit clearer 🤔

if (isOrchestrionEnabled()) {
// The orchestrion router span stays open until the response finishes, so
// it spans the whole sub-stack it dispatched (~the 100ms handler delay).
expect(routerDurationMs).toBeGreaterThan(50);

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.

l: Maybe it makes sense to also have an upper boundary as well?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

not sure what would be reasonable, we basically just want to test that there is any reasonable duration, I don't think we care about an upper limit?

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.

yeah good question about what a reasonable duration is. let's see if this leads to any issues. fine by me to leave it as is for now

@cursorcursorBot 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 2 potential issues.

Fix All in Cursor

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

Reviewed by Cursor Bugbot for commit 0405e01. Configure here.

// The OTel integration ends router spans immediately, so the router span
// is a ~0ms marker regardless of how long its sub-stack runs.
expect(routerDurationMs).toBeLessThan(50);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Test uses conditional instead of separate test cases

Low Severity

The test at this location uses if (isOrchestrionEnabled()) { ... } else { ... } to branch assertions inside a single test body. Per testing conventions, conditionals in a single test are flagged — the recommendation is to split the different paths into separate tests (e.g., one for orchestrion behavior and one for OTel behavior) to improve clarity and avoid accidentally hiding failures in one branch.

Fix in CursorFix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 0405e01. Configure here.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

fine here I'd say

@mydea
mydeaforce-pushed the fn/express-orchestrion branch from 0405e01 to c98196cCompareJuly 8, 2026 07:28
@github-actions

github-actionsBot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser27.59 kB--
@sentry/browser - with treeshaking flags26.03 kB--
@sentry/browser (incl. Tracing)46.27 kB--
@sentry/browser (incl. Tracing + Span Streaming)48.03 kB--
@sentry/browser (incl. Tracing, Profiling)51.03 kB--
@sentry/browser (incl. Tracing, Replay)85.56 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags75.17 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)90.26 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)102.91 kB--
@sentry/browser (incl. Feedback)44.76 kB--
@sentry/browser (incl. sendFeedback)32.38 kB--
@sentry/browser (incl. FeedbackAsync)37.51 kB--
@sentry/browser (incl. Metrics)28.67 kB--
@sentry/browser (incl. Logs)28.91 kB--
@sentry/browser (incl. Metrics & Logs)29.59 kB--
@sentry/react29.38 kB--
@sentry/react (incl. Tracing)48.53 kB--
@sentry/vue33.03 kB--
@sentry/vue (incl. Tracing)48.16 kB--
@sentry/svelte27.61 kB--
CDN Bundle30 kB--
CDN Bundle (incl. Tracing)48.26 kB--
CDN Bundle (incl. Logs, Metrics)31.57 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)49.57 kB--
CDN Bundle (incl. Replay, Logs, Metrics)70.81 kB--
CDN Bundle (incl. Tracing, Replay)85.73 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)87.04 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)91.55 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)92.83 kB--
CDN Bundle - uncompressed89.35 kB--
CDN Bundle (incl. Tracing) - uncompressed145.99 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed94.05 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed149.96 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed218.75 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed265.16 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed269.12 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed278.86 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed282.81 kB--
@sentry/nextjs (client)50.94 kB--
@sentry/sveltekit (client)46.68 kB--
@sentry/core/server78.38 kB--
@sentry/core/browser64.74 kB--
@sentry/node-core62.72 kB-0.01%-1 B 🔽
@sentry/node124.6 kB--
@sentry/node (incl. diagnostics channel injection)134.02 kB+0.86%+1.14 kB 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection)69.95 kB--
@sentry/node/light50.72 kB-0.01%-1 B 🔽
@sentry/node - without tracing74.05 kB-0.01%-1 B 🔽
@sentry/aws-serverless85.5 kB--
@sentry/cloudflare (withSentry) - minified181.68 kB--
@sentry/cloudflare (withSentry)449.39 kB--

View base workflow run

@mydea
mydeaforce-pushed the fn/express-orchestrion branch from c98196c to e637718CompareJuly 8, 2026 08:32
@mydea
mydeaforce-pushed the fn/express-orchestrion branch from e637718 to 430b676CompareJuly 8, 2026 11:42
@mydea
mydea merged commit 57fa2bb into developJul 8, 2026
216 checks passed
@mydea
mydea deleted the fn/express-orchestrion branch July 8, 2026 12:32
Sign up for freeto 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.

Rewrite ExpressInstrumentation to orchestrion

2 participants

@mydea@JPeer264