Skip to content

feat(server-utils): Expose channel-based, streamlined fastifyIntegration#21706

Open
mydea wants to merge 8 commits into
developfrom
ref/streamline-fastify-otel-vendored
Open

feat(server-utils): Expose channel-based, streamlined fastifyIntegration#21706
mydea wants to merge 8 commits into
developfrom
ref/streamline-fastify-otel-vendored

Conversation

@mydea

@mydea mydea commented Jun 23, 2026

Copy link
Copy Markdown
Member

This is the first part of #20745, streamlining fastify v5 instrumentation:

  • This is already diagnostics channel based!
  • Moved it from node to server-utils package, which now exports a fastifyIntegration (with support for fastify v5 only as of now) which can also be used by deno and bun and others in follow ups.
  • The integration itself was updated to properly use sentry-specific methods etc.
  • Missing is some any/eslint cleanup - there is a lot of this going on and it is rather cumbersome to fix it so I opted to mostly leave it as is.
  • Also added some node integration tests for fastify v5 for easier testing/iteration - this was previously only covered by e2e tests.
  • Already moved it to use sentry conventions while at it

Some other general notes:

  • This deprecates the instrumentFastify method and no longer calls it in preload, as this does not actually need to be preloaded anymore.
  • error handler stuff is still exported from server-utils as we need this for the old-style error handler. this can probably all be moved to server-utils in later steps when we moved the v3/v4 instrumentation as well.
  • The auto-error handling in fastify v5 does not work on node 18. this is a pre-existing problem though and not related to this PR, you'll have to add the error handler there.

@mydea mydea self-assigned this Jun 23, 2026
@mydea mydea changed the title Ref/streamline fastify otel vendored feat(server-utils): Expose channel-based, streamlined fastifyIntegration Jun 23, 2026
Comment thread dev-packages/node-integration-tests/suites/tracing/fastify/scenario.mjs Dismissed
@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.47 kB - -
@sentry/browser - with treeshaking flags 25.91 kB - -
@sentry/browser (incl. Tracing) 45.96 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.75 kB - -
@sentry/browser (incl. Tracing, Replay) 85.17 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.77 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.87 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.53 kB - -
@sentry/browser (incl. Feedback) 44.66 kB - -
@sentry/browser (incl. sendFeedback) 32.26 kB - -
@sentry/browser (incl. FeedbackAsync) 37.4 kB - -
@sentry/browser (incl. Metrics) 28.54 kB - -
@sentry/browser (incl. Logs) 28.78 kB - -
@sentry/browser (incl. Metrics & Logs) 29.47 kB - -
@sentry/react 29.27 kB - -
@sentry/react (incl. Tracing) 48.28 kB - -
@sentry/vue 32.62 kB - -
@sentry/vue (incl. Tracing) 47.83 kB - -
@sentry/svelte 27.5 kB - -
CDN Bundle 29.88 kB - -
CDN Bundle (incl. Tracing) 47.9 kB - -
CDN Bundle (incl. Logs, Metrics) 31.44 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.24 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.74 kB - -
CDN Bundle (incl. Tracing, Replay) 85.26 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.53 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.1 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.35 kB - -
CDN Bundle - uncompressed 88.95 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.02 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 93.65 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 148.99 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.47 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 263.89 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 267.85 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 277.58 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 281.53 kB - -
@sentry/nextjs (client) 50.67 kB - -
@sentry/sveltekit (client) 46.37 kB - -
@sentry/core/server 76.32 kB - -
@sentry/core/browser 63.48 kB - -
@sentry/node-core 61.63 kB -0.01% -1 B 🔽
@sentry/node 122.67 kB -0.77% -944 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.55 kB - -
@sentry/node - without tracing 73.69 kB - -
@sentry/aws-serverless 84.89 kB - -
@sentry/cloudflare (withSentry) - minified 175.71 kB - -
@sentry/cloudflare (withSentry) 437.11 kB - -

View base workflow run

instrumentSentryHttp,
instrumentExpress,
instrumentConnect,
instrumentFastify,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Preload misses early Fastify instances

High Severity

Removing v5 Fastify instrumentation from the preload list means fastify.initialization is only subscribed during fastifyIntegration setupOnce at Sentry.init(). Any Fastify instance created before init (common with @sentry/node/preload and deferred init) never receives the tracing plugin.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit faecc64. Configure 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.

this is fine, init should still be called before other stuff

@mydea mydea force-pushed the ref/streamline-fastify-otel-vendored branch from faecc64 to 7edd803 Compare June 23, 2026 11:51
@mydea mydea marked this pull request as ready for review June 23, 2026 11:51
@mydea mydea requested a review from a team as a code owner June 23, 2026 11:51
@mydea mydea requested review from JPeer264 and andreiborza and removed request for a team June 23, 2026 11:51

@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.

There are 2 total unresolved issues (including 1 from previous review).

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 7edd803. Configure here.


const hookType = spanAttributes[ATTRIBUTE_FASTIFY_TYPE];
const op =
hookType === HOOK_TYPE_INSTANCE ? HOOK_OP : hookType === HOOK_TYPE_HANDLER ? REQUEST_HANDLER_OP : undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Route hooks lack span op

Medium Severity

Route-level Fastify hooks wired in otelWireRoute use fastify.type route-hook, but handlerWrapper only assigns hook.fastify / request_handler.fastify for instance hooks and handlers. Route hooks such as route preHandler spans therefore get no sentry.op, unlike the integration test expectations and prior span enrichment behavior.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7edd803. Configure 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.

seems to be fine in all tests. not sure what a reasonable fallback op would be here...

@mydea

mydea commented Jun 23, 2026

Copy link
Copy Markdown
Member Author

@isaacs we can likely also use this as-is in deno and bun (IMHO we can do that in a follow up)

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