Skip to content

feat(core, node): portable Connect integration#20882

Closed
isaacs wants to merge 1 commit into
developfrom
isaacschlueter/portable-connect-integration
Closed

feat(core, node): portable Connect integration#20882
isaacs wants to merge 1 commit into
developfrom
isaacschlueter/portable-connect-integration

Conversation

@isaacs
Copy link
Copy Markdown
Member

@isaacs isaacs commented May 13, 2026

Platform-portable Connect tracing integration in @sentry/core (patchConnectModule, setupConnectErrorHandler), similar to portable Express integration, and rewire the Node SDK's Connect integration to call into it through the otel InstrumentationBase class.

Remove OTel-specific span attribute fix-up. Spans created with correct origin (auto.http.connect) and op directly in the middleware.

@isaacs isaacs requested a review from a team as a code owner May 13, 2026 21:30
isaacs added a commit that referenced this pull request May 13, 2026
Platform-portable Connect tracing integration in `@sentry/core`
(`patchConnectModule`, `setupConnectErrorHandler`), similar to portable
Express integration, and rewire the Node SDK's Connect integration to
call into it through the otel InstrumentationBase class.

Remove OTel-specific span attribute fix-up. Spans created with correct
origin (`auto.http.connect`) and op directly in the middleware.
@isaacs isaacs force-pushed the isaacschlueter/portable-connect-integration branch from 051bd5b to 93b0b34 Compare May 13, 2026 21:30
isaacs added a commit that referenced this pull request May 13, 2026
Platform-portable Connect tracing integration in `@sentry/core`
(`patchConnectModule`, `setupConnectErrorHandler`), similar to portable
Express integration, and rewire the Node SDK's Connect integration to
call into it through the otel InstrumentationBase class.

Remove OTel-specific span attribute fix-up. Spans created with correct
origin (`auto.http.connect`) and op directly in the middleware.
@isaacs isaacs force-pushed the isaacschlueter/portable-connect-integration branch from 93b0b34 to eebfaa1 Compare May 13, 2026 21:31
@github-actions
Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 26.89 kB - -
@sentry/browser - with treeshaking flags 25.33 kB - -
@sentry/browser (incl. Tracing) 44.79 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 46.8 kB - -
@sentry/browser (incl. Tracing, Profiling) 49.78 kB - -
@sentry/browser (incl. Tracing, Replay) 84.42 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 73.87 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.12 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 101.77 kB - -
@sentry/browser (incl. Feedback) 44.08 kB - -
@sentry/browser (incl. sendFeedback) 31.7 kB - -
@sentry/browser (incl. FeedbackAsync) 36.81 kB - -
@sentry/browser (incl. Metrics) 27.98 kB - -
@sentry/browser (incl. Logs) 28.13 kB - -
@sentry/browser (incl. Metrics & Logs) 28.8 kB - -
@sentry/react 28.64 kB - -
@sentry/react (incl. Tracing) 47.06 kB - -
@sentry/vue 31.82 kB - -
@sentry/vue (incl. Tracing) 46.67 kB - -
@sentry/svelte 26.91 kB - -
CDN Bundle 29.28 kB - -
CDN Bundle (incl. Tracing) 47.2 kB - -
CDN Bundle (incl. Logs, Metrics) 30.65 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 48.34 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70 kB - -
CDN Bundle (incl. Tracing, Replay) 84.62 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 85.68 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 90.43 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 91.52 kB - -
CDN Bundle - uncompressed 86.14 kB - -
CDN Bundle (incl. Tracing) - uncompressed 141.7 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 90.33 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 145.16 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 215.18 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 260.43 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 263.88 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 274.13 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 277.57 kB - -
@sentry/nextjs (client) 49.57 kB - -
@sentry/sveltekit (client) 45.28 kB - -
@sentry/node-core 61.97 kB +0.02% +11 B 🔺
@sentry/node 166.36 kB -0.34% -564 B 🔽
@sentry/node - without tracing 74.38 kB +0.01% +6 B 🔺
@sentry/aws-serverless 109.18 kB +0.01% +3 B 🔺
@sentry/cloudflare (withSentry) - minified 170.88 kB - -
@sentry/cloudflare (withSentry) 431.1 kB - -

View base workflow run

Comment thread packages/core/src/integrations/connect/index.ts
Copy link
Copy Markdown
Member

@JPeer264 JPeer264 left a comment

Choose a reason for hiding this comment

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

IIRC this was the one which got split out from #20393, amirite?

isaacs added a commit that referenced this pull request May 19, 2026
Platform-portable Connect tracing integration in `@sentry/core`
(`patchConnectModule`, `setupConnectErrorHandler`), similar to portable
Express integration, and rewire the Node SDK's Connect integration to
call into it through the otel InstrumentationBase class.

Remove OTel-specific span attribute fix-up. Spans created with correct
origin (`auto.http.connect`) and op directly in the middleware.
@isaacs isaacs force-pushed the isaacschlueter/portable-connect-integration branch from eebfaa1 to 52c43e5 Compare May 19, 2026 19:34
Platform-portable Connect tracing integration in `@sentry/core`
(`patchConnectModule`, `setupConnectErrorHandler`), similar to portable
Express integration, and rewire the Node SDK's Connect integration to
call into it through the otel InstrumentationBase class.

Remove OTel-specific span attribute fix-up. Spans created with correct
origin (`auto.http.connect`) and op directly in the middleware.
@isaacs isaacs force-pushed the isaacschlueter/portable-connect-integration branch from 52c43e5 to 32896c0 Compare May 19, 2026 19:35
return originalHandle.apply(this, args);
});
} catch (e) {
DEBUG_BUILD && debug.error('Failed to patch connect handle method:', e);
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: When the handle method is called without an out callback, the stack layer added by addNewStackLayer is never removed, causing route stack corruption on subsequent calls.
Severity: HIGH

Suggested Fix

The completeStack() function should be called to clean up the stack layer after originalHandle completes, regardless of whether an out callback was provided. This can be achieved by calling it after the originalHandle.apply call, ensuring the layer is always popped.

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/core/src/integrations/connect/index.ts#L254

Potential issue: The patched `handle` method calls `addNewStackLayer(req)` to push a new
layer onto the route stack. However, the corresponding cleanup function,
`completeStack()`, is only scheduled to be called within a patched `out` callback.
According to Connect.js documentation, the `out` callback is optional and often omitted
in nested application scenarios. When `handle` is invoked without `out`, a layer is
pushed but never popped. If the same request object is reused across multiple `handle`
calls, this leads to an accumulation of stale layers, corrupting the route stack and
causing `generateRoute(req)` to report incorrect route names.

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

@isaacs
Copy link
Copy Markdown
Member Author

isaacs commented May 19, 2026

This actually needs to be somewhat re-factored to work off the now-vendored Connect integration. And, tbh, it might make more sense to go with orchestrion, and make it a v11 integration anyway.

This was always a somewhat experimental low-stakes/low-value patch, so it's no great loss. Not a ton of people using Connect anyway, compared with Express and other node frameworks.

Closing this for now.

@isaacs isaacs closed this May 19, 2026
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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.

Reviewed by Cursor Bugbot for commit 32896c0. Configure here.

const app = connect.apply(this, args) as ConnectApp;
patchConnectApp(app, options);
return app;
} as ConnectModule;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Connect export loses static props

Medium Severity

patchConnectModule returns a new factory function and the Node instrumentation hook uses that as the patched connect export. Unlike the in-place Express patch, nothing copies static members from the original export (for example connect.mime), so code that reads them after Sentry.init() breaks.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 32896c0. Configure here.

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.

2 participants