forked from alex-ppg/fastify-sentry
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f01554e
commit a0d023f
Showing
6 changed files
with
421 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
## Installation | ||
|
||
```bash | ||
npm i @zentered/fastify-sentry -s | ||
npm i @zentered/fastify-sentry | ||
|
||
or | ||
|
||
|
@@ -26,32 +26,29 @@ const errorHandler = (err, req, reply) => { | |
}) | ||
} | ||
|
||
fastify.register(fastifySentry, { | ||
dsn: 'https://[email protected]/0000000', | ||
environment: 'test', | ||
errorHandler: errorHandler | ||
app.register(fastifySentry, { | ||
dsn: process.env.SENTRY_DSN, | ||
environment: 'development', | ||
tracing: true, | ||
tracesSampleRate: 1.0 | ||
}) | ||
|
||
fastify.get('/', async (request, reply) => { | ||
// Errors in async functions are automatically caught | ||
throw new Error('Oops') | ||
}) | ||
|
||
fastify.get('/other-path', (request, reply) => { | ||
// On the other hand, you need to pass the Error object to "reply.send" for it to be logged as Fastify does not catch errors in synchronous functions! | ||
reply.send(new Error('I did it again!')) | ||
}) | ||
``` | ||
|
||
## Description | ||
|
||
This plugin adds the Sentry SDK error handler by using `fastify.setErrorHandler`. This means that the Sentry SDK will only catch any errors thrown in routes with `async` functions. In order to properly log errors thrown within synchronous functions, you need to pass the error object within `reply.send`. It also adds certain metadata, namely the `path` and the `ip` parameters of `req.raw`, to both the `User` context and `Tag` context of Sentry. If you use jwt authentication, the user id is also added to Sentry. | ||
This plugin adds the Sentry SDK error handler by using `setErrorHandler`. It also adds certain metadata, namely the `path` and the `ip` parameters of the request, to both the `User` context and `Tag` context of Sentry. If you use jwt authentication, the user id is also added to Sentry. | ||
|
||
## Options | ||
|
||
| Option | Description | | ||
| ------ | ------------------------------------------------------------------- | | ||
| `dsn` | Required, the DSN specified by Sentry.io to properly log errors to. | | ||
| Option | Description | | ||
| --------- | ------------------------------------------------------------------- | | ||
| `dsn` | Required, the DSN specified by Sentry.io to properly log errors to. | | ||
| `tracing` | Default `false`, enable Sentry tracing. | | ||
|
||
You can find further options in the [Node.js Guide on Sentry.io](https://docs.sentry.io/platforms/node/) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.