Skip to content

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

Merged
mydea merged 12 commits into
developfrom
ref/streamline-fastify-otel-vendored
Jul 1, 2026
Merged

feat(server-utils): Expose channel-based, streamlined fastifyIntegration#21706
mydea merged 12 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.62 kB - -
@sentry/browser - with treeshaking flags 26.05 kB - -
@sentry/browser (incl. Tracing) 46.07 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.82 kB - -
@sentry/browser (incl. Tracing, Profiling) 50.84 kB - -
@sentry/browser (incl. Tracing, Replay) 85.31 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 74.91 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 89.99 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.67 kB - -
@sentry/browser (incl. Feedback) 44.8 kB - -
@sentry/browser (incl. sendFeedback) 32.42 kB - -
@sentry/browser (incl. FeedbackAsync) 37.55 kB - -
@sentry/browser (incl. Metrics) 28.68 kB - -
@sentry/browser (incl. Logs) 28.93 kB - -
@sentry/browser (incl. Metrics & Logs) 29.61 kB - -
@sentry/react 29.41 kB - -
@sentry/react (incl. Tracing) 48.38 kB - -
@sentry/vue 32.85 kB - -
@sentry/vue (incl. Tracing) 47.93 kB - -
@sentry/svelte 27.64 kB - -
CDN Bundle 30.02 kB - -
CDN Bundle (incl. Tracing) 48.02 kB - -
CDN Bundle (incl. Logs, Metrics) 31.58 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.35 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.79 kB - -
CDN Bundle (incl. Tracing, Replay) 85.51 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.79 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.32 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.56 kB - -
CDN Bundle - uncompressed 89.42 kB - -
CDN Bundle (incl. Tracing) - uncompressed 145.35 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.12 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 149.32 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.66 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 264.36 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 268.32 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 278.06 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.01 kB - -
@sentry/nextjs (client) 50.76 kB - -
@sentry/sveltekit (client) 46.46 kB - -
@sentry/core/server 77.75 kB - -
@sentry/core/browser 64.06 kB - -
@sentry/node-core 61.47 kB - -
@sentry/node 121.97 kB -0.7% -857 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.45 kB -0.01% -1 B 🔽
@sentry/node - without tracing 73.2 kB -0.01% -1 B 🔽
@sentry/aws-serverless 84.09 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 180.62 kB - -
@sentry/cloudflare (withSentry) 446.93 kB - -

View base workflow run

Comment thread packages/node/src/integrations/tracing/index.ts
@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
@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)

@mydea mydea requested a review from nicohrubec June 26, 2026 08:00
@github-actions

Copy link
Copy Markdown
Contributor

👋 @JPeer264, @andreiborza — Please review this PR when you get a chance!

@mydea mydea force-pushed the ref/streamline-fastify-otel-vendored branch from 7edd803 to 64f53cd Compare June 29, 2026 08:16

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

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 64f53cd. Configure here.

Comment thread packages/server-utils/src/integrations/tracing-channel/fastify/index.ts Outdated
Comment thread packages/node/src/integrations/tracing/fastify/index.ts Outdated
@mydea mydea force-pushed the ref/streamline-fastify-otel-vendored branch from 64f53cd to fbe0085 Compare June 29, 2026 11:45
@mydea

mydea commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

Failing test depends on #21845

@mydea mydea force-pushed the ref/streamline-fastify-otel-vendored branch from 95f0794 to 024cd46 Compare June 29, 2026 13:50
Comment on lines +15 to +24
export function subscribeToFastifyErrorChannel(): void {
diagnosticsChannel.subscribe('tracing:fastify.request.handler:error', message => {
const { error, request, reply } = message as {
error: Error;
request: FastifyRequest;
reply: FastifyReply;
};

handleFastifyError.call(handleFastifyError, error, request, reply, 'diagnostics-channel');
});

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 subscribeToFastifyErrorChannel function lacks an idempotency guard, allowing duplicate diagnosticsChannel subscriptions if called multiple times, which would cause duplicate error captures.
Severity: LOW

Suggested Fix

Add an internal idempotency guard to subscribeToFastifyErrorChannel. A simple boolean flag, similar to the _isInstrumented flag used in instrumentation.ts, can be used to track if the subscription has already been made and prevent re-subscribing.

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/server-utils/src/integrations/tracing-channel/fastify/errors.ts#L15-L24

Potential issue: The `subscribeToFastifyErrorChannel` function subscribes to Node's
`diagnosticsChannel` without an internal mechanism to prevent multiple subscriptions.
Node's `diagnosticsChannel.subscribe()` does not deduplicate handlers, so if this
function is called more than once, it will register the same handler multiple times.
While the SDK's `setupOnce()` mechanism provides protection in normal production
scenarios by using a global `installedIntegrations` array, this protection is fragile.
The function is exported (though deprecated) and could be called directly, or the global
state could be cleared (as it is in tests), leading to duplicate error captures for a
single event.

@mydea mydea force-pushed the ref/streamline-fastify-otel-vendored branch from 8a9e626 to 9020bb5 Compare June 30, 2026 09:51
@mydea mydea merged commit 88e7ad5 into develop Jul 1, 2026
561 of 564 checks passed
@mydea mydea deleted the ref/streamline-fastify-otel-vendored branch July 1, 2026 06:23
andreiborza added a commit that referenced this pull request Jul 1, 2026
Re-enabled now that the streamlined fastify integration (#21706) names spans at
creation instead of renaming via updateName(), so the SentryTracerProvider no
longer stamps sentry.source: 'custom'. Verified locally via e2e (11/11 pass each).
andreiborza added a commit that referenced this pull request Jul 1, 2026
Re-enabled now that the streamlined fastify integration (#21706) names spans at
creation instead of renaming via updateName(), so the SentryTracerProvider no
longer stamps sentry.source: 'custom'. Verified locally via e2e (11/11 pass each).
andreiborza added a commit that referenced this pull request Jul 2, 2026
Re-enabled now that the streamlined fastify integration (#21706) names spans at
creation instead of renaming via updateName(), so the SentryTracerProvider no
longer stamps sentry.source: 'custom'. Verified locally via e2e (11/11 pass each).
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