feat(server-utils): Expose channel-based, streamlined fastifyIntegration#21706
Conversation
fastifyIntegration
size-limit report 📦
|
faecc64 to
7edd803
Compare
|
@isaacs we can likely also use this as-is in deno and bun (IMHO we can do that in a follow up) |
|
👋 @JPeer264, @andreiborza — Please review this PR when you get a chance! |
7edd803 to
64f53cd
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ 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.
64f53cd to
fbe0085
Compare
|
Failing test depends on #21845 |
95f0794 to
024cd46
Compare
| 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'); | ||
| }); |
There was a problem hiding this comment.
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.
8a9e626 to
9020bb5
Compare
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).
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).
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).

This is the first part of #20745, streamlining fastify v5 instrumentation:
Some other general notes:
instrumentFastifymethod and no longer calls it in preload, as this does not actually need to be preloaded anymore.