feat(server-utils): Expose channel-based, streamlined fastifyIntegration#21706
feat(server-utils): Expose channel-based, streamlined fastifyIntegration#21706mydea wants to merge 9 commits into
fastifyIntegration#21706Conversation
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
| setNotFoundHandlerOriginal.call( | ||
| this, | ||
| hooks, | ||
| handlerWrapper(handler, 'notFoundHandler', { | ||
| [ATTRIBUTE_HOOK_NAME]: `${this.pluginName} - not-found-handler`, | ||
| [ATTRIBUTE_FASTIFY_TYPE]: HOOK_TYPE_INSTANCE, | ||
| [ATTRIBUTE_HOOK_CALLBACK_NAME]: handler.name?.length > 0 ? handler.name : ANONYMOUS_FUNCTION_NAME, | ||
| }), | ||
| ); |
There was a problem hiding this comment.
Bug: The setNotFoundHandlerPatched function doesn't guard against an undefined handler before wrapping it, leading to a TypeError when the 404 handler is invoked.
Severity: HIGH
Suggested Fix
Add a guard in setNotFoundHandlerPatched to check if handler is undefined. If it is, avoid wrapping it and instead pass undefined directly to the original setNotFoundHandler.call().
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/instrumentation.ts#L303-L311
Potential issue: The patched function `setNotFoundHandlerPatched` unconditionally wraps
the optional `handler` argument. Fastify's API allows calling `setNotFoundHandler` with
only a hooks object and no handler, which results in the `handler` argument being
`undefined`. When a 404 request is subsequently processed, the wrapper function attempts
to execute `handler.call(this, ...args)`, which will throw a `TypeError` because
`handler` is `undefined`. This crash occurs under valid and documented API usage for
Fastify.
Did we get this right? 👍 / 👎 to inform future reviews.

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.