Skip to content

feat(v9/node): Add shouldHandleError option to fastifyIntegration #17123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2025

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Jul 22, 2025

Backport of #16845

closes #17123

…16845)

Resolves: #16819

This requires the Fastify integration to be manually added while
initialising Sentry.

```typescript
Sentry.init({
  integrations: [
    Sentry.fastifyIntegration({
      shouldHandleError(_error, _request, reply) {
        return reply.statusCode >= 500;
      },
    });
  },
});
```

If `shouldHandleError` is provided in `setupFastifyErrorHandler`, it
overrides `shouldHandleError` provided from `fastifyIntegration`. So
this should not break any existing (pre-DC) usage.

In summary: 
- When `setupFastifyErrorHandler` is not used, `shouldHandleError` at
`Sentry.init` will be used.
- When `setupFastifyErrorHandler` is used but without
`shouldHandleError`, `shouldHandleError` at `Sentry.init` will be used.
- When in both `setupFastifyErrorHandler` and `Sentry.init` are used
with `shouldHandleError`, the one in `setupFastifyErrorHandler` is used.

Works for all Fastify versions supported (v3, v4, v5)

Note: E2E tests for this now requires to test overrides, so they need to
be run twice with both overriden and non-overriden applications. Not the
prettiest solution, but I could not figure out an alternative.
@Lms24 Lms24 changed the base branch from develop to v9 July 22, 2025 13:28
@Lms24 Lms24 self-assigned this Jul 22, 2025
@Lms24 Lms24 requested review from onurtemizkan, a team, AbhiPrasad and andreiborza and removed request for a team July 22, 2025 13:29
cursor[bot]

This comment was marked as outdated.

Copy link
Collaborator

@onurtemizkan onurtemizkan left a comment

Choose a reason for hiding this comment

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

Both comments from cursor are for what we're doing intentionally. We could have added a warning for the first one maybe. But as that part is for current users so I think we can assume they are using the handler correctly already.

Copy link

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

Bug: Incorrect Start Command Causes Test Failures

The startCommand in node-fastify-5/playwright.override.config.mjs is incorrectly set to pnpm start instead of pnpm start:override. This prevents the override tests from running app-handle-error-override.ts and properly testing the shouldHandleError functionality, unlike Fastify 3 and 4 override configurations.

dev-packages/e2e-tests/test-applications/node-fastify-5/playwright.override.config.mjs#L3-L4

const config = getPlaywrightConfig({
startCommand: `pnpm start`,

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@Lms24 Lms24 enabled auto-merge (squash) July 24, 2025 07:39
Copy link
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.79 kB - -
@sentry/browser - with treeshaking flags 22.35 kB - -
@sentry/browser (incl. Tracing) 39.66 kB - -
@sentry/browser (incl. Tracing, Replay) 77.79 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 67.59 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 82.5 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 94.59 kB - -
@sentry/browser (incl. Feedback) 40.48 kB - -
@sentry/browser (incl. sendFeedback) 28.48 kB - -
@sentry/browser (incl. FeedbackAsync) 33.37 kB - -
@sentry/react 25.55 kB - -
@sentry/react (incl. Tracing) 41.62 kB - -
@sentry/vue 28.24 kB - -
@sentry/vue (incl. Tracing) 41.45 kB - -
@sentry/svelte 23.81 kB - -
CDN Bundle 25.18 kB - -
CDN Bundle (incl. Tracing) 39.42 kB - -
CDN Bundle (incl. Tracing, Replay) 75.42 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 80.89 kB - -
CDN Bundle - uncompressed 73.45 kB - -
CDN Bundle (incl. Tracing) - uncompressed 116.86 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 231 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 243.81 kB - -
@sentry/nextjs (client) 43.66 kB - -
@sentry/sveltekit (client) 40.08 kB - -
@sentry/node 169.07 kB +0.04% +66 B 🔺
@sentry/node - without tracing 100.22 kB - -
@sentry/aws-serverless 128.38 kB -0.01% -1 B 🔽

View base workflow run

@Lms24 Lms24 merged commit b6cad7b into v9 Jul 24, 2025
166 of 170 checks passed
@Lms24 Lms24 deleted the lms/feat-v9-fastify-shouldHandleError branch July 24, 2025 07:56
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