-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
30 lines (27 loc) · 794 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"use strict";
const fastifyPlugin = require("fastify-plugin");
const Sentry = require("@sentry/node");
function sentryConnector(fastify, options, done) {
Sentry.init({
dsn: options.dsn,
environment: options.environment ? options.environment : "local"
});
fastify.setErrorHandler((err, req, reply) => {
Sentry.withScope(scope => {
scope.setUser({
ip_address: req.raw.ip
});
scope.setTag("path", req.raw.url);
// will be tagged with my-tag="my value"
Sentry.captureException(err);
options.errorHandler
? options.errorHandler(err, req, reply)
: reply.send({
error: 500,
message: "Internal Server Error"
});
});
});
done();
}
module.exports = fastifyPlugin(sentryConnector);