Sentry.init({
dsn: "https://adsfasdfvcxzdsaf@sentry.io/2898629",
beforeSend(event, hint) {
// Check if it is an exception, and if so, show the report dialog
if (event.exception) {
Sentry.showReportDialog({ eventId: event.event_id });
}
return event;
}
});
Server-Side
Elixir
{:sentry, "8.0.0"},
{:jason, "~> 1.1"},
{:hackney, "~> 1.8"},
# if you are using plug_cowboy
{:plug_cowboy, "~> 2.3"},
Usage
Node Specific
const express = require('express');
const app = express();
const Sentry = require('@sentry/node');
Sentry.init({ dsn: 'https://jdfasklfjdajfdiopiuasdfop@sentry.io/5182247' });
// The request handler must be the first middleware on the app
app.use(Sentry.Handlers.requestHandler());
// All controllers should live here
app.get('/', function rootHandler(req, res) {
res.end('Hello world!');
});
// The error handler must be before any other error middleware and after all controllers, by default only captures 500
app.use(Sentry.Handlers.errorHandler());
// Optional fallthrough error handler
app.use(function onError(err, req, res, next) {
// The error id is attached to `res.sentry` to be returned
// and optionally displayed to the user for support.
res.statusCode = 500;
res.end(res.sentry + "\n");
});
app.listen(3000);
To capture all errors instead of just over 500
app.use(
Sentry.Handlers.errorHandler({
shouldHandleError(err) {
return true; //by default only captures 500, but lets capture all errors
}
})
); //must be first error handler and after all controllers