Gathering detailed insights and metrics for @immobiliarelabs/fastify-sentry
Gathering detailed insights and metrics for @immobiliarelabs/fastify-sentry
Gathering detailed insights and metrics for @immobiliarelabs/fastify-sentry
Gathering detailed insights and metrics for @immobiliarelabs/fastify-sentry
🚧 Sentry errors handler for fastify that just works! Install, add your DSN and you're good to go!
npm install @immobiliarelabs/fastify-sentry
Typescript
Module System
Min. Node Version
Node Version
NPM Version
53.6
Supply Chain
97.6
Quality
90.7
Maintenance
100
Vulnerability
94.1
License
JavaScript (97.07%)
TypeScript (2.77%)
Shell (0.16%)
Total Downloads
1,431,278
Last Day
521
Last Week
11,388
Last Month
61,153
Last Year
861,269
89 Stars
913 Commits
12 Forks
7 Watching
32 Branches
17 Contributors
Latest Version
9.0.1
Package Id
@immobiliarelabs/fastify-sentry@9.0.1
Unpacked Size
27.44 kB
Size
8.51 kB
File Count
11
NPM Version
10.9.1
Node Version
20.12.1
Publised On
28 Nov 2024
Cumulative downloads
Total Downloads
Last day
-85.8%
521
Compared to previous day
Last week
-32.4%
11,388
Compared to previous week
Last month
-1.8%
61,153
Compared to previous month
Last year
64.8%
861,269
Compared to previous year
28
In our Fastify applications, no matter how good our code is sometimes errors happens, we may need to catch and send them to Sentry for further analysis! This plugin aim to do just that, as easily as possible!
Plug, add your Sentry's DSN
and you're good to go!
This plugin standardize options and payload format then registers a default errorHandler that uses Sentry
to report errors, it also decorates the fastify
instance with the Sentry
object so you can use it for your custom needs.
⚠️ Fastify 4 introduced some breaking changes, please refer to this version support table to find what works best for you!
You can install it with npm
1# lastest stable version 2$ npm i -S @immobiliarelabs/fastify-sentry 3# latest development version 4$ npm i -S @immobiliarelabs/fastify-sentry@next
or yarn
1# lastest stable version 2$ yarn add @immobiliarelabs/fastify-sentry 3# latest development version 4$ yarn add @immobiliarelabs/fastify-sentry@next
Please check these migration guides if you are migrating from an older version of the plugin.
1const fastify = require('fastify')(); 2 3fastify.register(require('@immobiliarelabs/fastify-sentry'), { 4 dsn: '<your sentry dsn>', 5 environment: 'production', 6 release: '1.0.0', 7});
1const fastify = require('fastify')(); 2 3fastify.register(require('@immobiliarelabs/fastify-sentry'), { 4 dsn: '<your sentry dsn>', 5 environment: 'production', 6 release: '1.0.0', 7}); 8 9fastify.get('/user/:id', async function (req, reply) { 10 const user = await getUserFromStorage(req.params.id); 11 if (user.blocked) { 12 this.Sentry.captureMessage('Blocked user tried to get in'); 13 ... 14 } else { 15 ... 16 } 17});
You can find more examples of usage in the examples folder :wink:.
As for everything, using Sentry comes at a cost. You can see the benchmarks here
This module exports a plugin registration function.
The exported plugin adds the following decorators:
fastify.Sentry
: a reference to the Sentry
instancereply.sentryEventId
<string>
: the id of a captured exception, accessible when defining a custom errorResponse
handler in the plugin optionsreply.sentryTransaction
: the current request transaction, accessible when enabling tracing in Sentry
and adds a custom error handler that reports to Sentry all the errors that have a 5xx
status code.
options
The plugin extends the standard Sentry options object with the following properties:
Attach the default error handler to the
fastify
instance.
type: boolean
default: true
Decide if the error should be sent to
Sentry
This function is called in the default error handler that the plugin adds.
type: function
parameters:
error
<FastifyError>
request
<FastifyRequest>
reply
<FastifyReply>
returns:
boolean
: true
if the error should be sent, false
otherwise.
default: a function that returns true
if the status code of the error is 5xx
Custom handler to respond the client.
This function is called in the dafult error handler right after the exception is captured, so the reply
is decorated with event id assigned by the Sentry
SDK.
type: function
parameters:
error
<FastifyError>
request
<FastifyRequest>
reply
<FastifyReply>
returns: void
Get the request transaction name.
type: function
parameters:
request
<FastifyRequest>
returns: string
Extract request metadata to attach the
Sentry
event.
type: function
parameters:
request
<FastifyRequest>
keys
<string[]>
the fields to extract from the request (headers
, method
, protocol
, url
, cookies
, query_string
, data
)returns: object
containing the extracted metadata. It can contain one or more properties named after the keys
passed as parameter as well as other properties.
default: a function that returns an object like this:
1{ 2 headers: {}, 3 method: 'method, 4 protocol: 'https, 5 cookies: {}, 6 query_string: {}, 7 data: 'request body as string' 8}
Extract user metadata to attach the
Sentry
event.
type: function
parameters:
request
<FastifyRequest>
returns: object
containing the extracted metadata.
default: a function that looks for a user object in the request
and returns an object like this:
1{ 2 id: '', 3 username: '', 4 email: '', 5}
Skip the
Sentry.init
call that initializes the SDK. Useful if working in an environment that already initializes the Sentry SDK.
type: boolean
default: false
The package has a /utils
export that you can import
with CommonJS
1const utils = require('@immobiliarelabs/fastify-sentry/utils')
or ESM
1import utils from '@immobiliarelabs/fastify-sentry/utils'
and has a set of utilities used internally that can be useful when implementing your custom functions to pass to the plugin initialization.
This is the default function used to build the transaction name.
This is the default function used to extract the request metadata.
The default function used to extract the user metadata.
The default function used to extract the body from the request.
An internal function used to get the transaction name and source.
The default function used to decide if an error event should be sent to Sentry.
The default function used to reply to a request that errored.
Version | |
---|---|
fastify | >=4.0.0 |
sentry | ^7.0.0 |
Node.js | >=18 |
fastify-sentry
was created by the amazing Node.js team at ImmobiliareLabs, the Tech dept of Immobiliare.it, the #1 real estate company in Italy.
We are currently using fastify-sentry
in our products as well as our internal toolings.
If you are using fastify-sentry in production drop us a message.
Made with ❤️ by ImmobiliareLabs & Contributors
We'd love for you to contribute to fastify-sentry
!
If you have any questions on how to use fastify-sentry
, bugs and enhancement please feel free to reach out by opening a GitHub Issue.
fastify-sentry
is licensed under the MIT license.
See the LICENSE file for more information.
No vulnerabilities found.
No security vulnerabilities found.