Skip to content

Commit

Permalink
feat: update to fastify v5
Browse files Browse the repository at this point in the history
Add support for fastify 5.

BREAKING CHANGE: fastify 4 is no longer supported, @fastify/sensible custom
error handling is no longer supported either.
  • Loading branch information
dnlup committed Nov 11, 2024
1 parent 3a39e93 commit 194acd4
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 44 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,10 @@ and has a set of utilities used internally that can be useful when implementing

| | Version |
| --- | --- |
| fastify | `>=4.0.0` |
| fastify | `^5.0.0` |
| sentry | `^7.0.0` |
| Node.js | `>=18` |

## Powered Apps

`fastify-sentry` was created by the amazing Node.js team at [ImmobiliareLabs](https://github.com/immobiliare), the Tech dept of [Immobiliare.it](https://www.immobiliare.it), the #1 real estate company in Italy.
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const fastifySentry = function (fastify, opts, next) {

module.exports = fp(fastifySentry, {
name: '@immobiliarelabs/fastify-sentry',
fastify: '4.x',
fastify: '5.x',
});
module.exports.default = fastifySentry;
module.exports.fastifySentry = fastifySentry;
14 changes: 3 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.13.4",
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@fastify/sensible": "^5.1.0",
"@fastify/sensible": "^6.0.1",
"@saithodev/semantic-release-backmerge": "^4.0.1",
"@semantic-release/changelog": "^6.0.0",
"@semantic-release/commit-analyzer": "^11.0.0",
Expand All @@ -77,12 +75,11 @@
"@types/node": "^20.1.0",
"autocannon": "^7.4.0",
"concurrently": "^8.0.1",
"cz-conventional-changelog": "^3.2.0",
"eslint": "^8.0.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^5.0.0",
"fastify": "^4.0.3",
"fastify": "^5.1.0",
"husky": "^8.0.0",
"is-ci": "^3.0.0",
"lint-staged": "^15.2.0",
Expand All @@ -94,11 +91,6 @@
"tsd": "^0.30.0",
"typescript": "^5.0.2"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"types": "./index.d.ts",
"tsd": {
"directory": "test/types"
Expand All @@ -108,6 +100,6 @@
"@sentry/tracing": "^7.105.0",
"@sentry/utils": "^7.105.0",
"cookie": "^0.7.0",
"fastify-plugin": "^4.3.0"
"fastify-plugin": "^5.0.1"
}
}
8 changes: 4 additions & 4 deletions tap-snapshots/test/plugin.test.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Object {
},
"method": "GET",
"query_string": Object {},
"url": "http://localhost:80/oops",
"url": "http://localhost/oops",
},
"tags": undefined,
"transaction": "GET /oops",
Expand Down Expand Up @@ -82,7 +82,7 @@ Object {
},
"method": "POST",
"query_string": Object {},
"url": "http://localhost:80/body",
"url": "http://localhost/body",
},
"tags": undefined,
"transaction": "POST /body",
Expand All @@ -107,7 +107,7 @@ Object {
},
"method": "GET",
"query_string": Object {},
"url": "http://localhost:80/oops",
"url": "http://localhost/oops",
"user": Object {
"email": "[email protected]",
"username": "some",
Expand Down Expand Up @@ -141,7 +141,7 @@ Object {
},
"method": "POST",
"query_string": Object {},
"url": "http://localhost:80/body",
"url": "http://localhost/body",
"user": Object {
"email": "[email protected]",
"username": "some",
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"license": "ISC",
"dependencies": {
"@immobiliarelabs/fastify-sentry": "file:../pack.tgz",
"fastify": "^4.21.0"
"fastify": "^5.1.0"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"license": "ISC",
"dependencies": {
"@immobiliarelabs/fastify-sentry": "file:../pack.tgz",
"fastify": "^4.21.0"
"fastify": "^5.1.0"
}
}
24 changes: 0 additions & 24 deletions test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const tap = require('tap');
const { defaultIntegrations } = require('@sentry/node');
const sensible = require('@fastify/sensible');
const {
setup,
resetModuleCache,
Expand Down Expand Up @@ -161,29 +160,6 @@ tap.test('event with transactions enabled', async (t) => {
t.matchSnapshot(extractMetaFromEvent(report));
});

tap.test('@fastify/sensible explicit internal errors support', async (t) => {
const app = await setup(
{ dsn: DSN, environment: 'fastify-sentry-test' },
async (s) => {
s.register(sensible);
},
async (s) => {
s.get('/sensible', async function () {
throw this.httpErrors.internalServerError('My Error');
});
}
);
const response = await app.inject({
method: 'GET',
path: '/sensible',
});
t.equal(500, response.statusCode);
await app.Sentry.flush();
t.equal(testkit.reports().length, 1);
const payload = JSON.parse(response.payload);
t.equal('My Error', payload.message);
});

tap.test('custom `shouldHandleError`', async (t) => {
const app = await setup({
shouldHandleError: () => false,
Expand Down
2 changes: 1 addition & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ exports.shouldHandleError = shouldHandleError;

const errorResponse = function (error, request, reply) {
// @fastify/sensible explicit internal errors support
if (reply.statusCode === 500 && error.explicitInternalServerError !== true) {
if (reply.statusCode === 500) {
reply.send(new Error('Something went wrong'));
} else {
reply.send(error);
Expand Down

0 comments on commit 194acd4

Please sign in to comment.