If Sentry.init isn't called, all other Sentry functions are noops
Manually Logging
import*as Sentry from"@sentry/electron";try {aFunctionThatMightFail();} catch (err) {Sentry.captureException(err);}Sentry.captureMessage('Something went wrong');
Adding Context in General
Can add id, username, email, or ip_address
Don't add extra objects of arbitary size as they will be rejected if over 100KB
Sentry.configureScope((scope) => {scope.setUser({"email":"john.doe@example.com"});}); //will be for all messagesSentry.setContext("profile", { name:"Jorge", time:1 });
Adding Context for a Message
Sentry.captureException(new Error("something went wrong"), { extra: { section: "articles", },});
Creating Error Popup
Sentry.init({ dsn:"https://adsfasdfvcxzdsaf@sentry.io/2898629",beforeSend(event, hint) {// Check if it is an exception, and if so, show the report dialogif (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
constexpress=require('express');constapp=express();constSentry=require('@sentry/node');Sentry.init({ dsn:'https://jdfasklfjdajfdiopiuasdfop@sentry.io/5182247' });// The request handler must be the first middleware on the appapp.use(Sentry.Handlers.requestHandler());// All controllers should live hereapp.get('/',functionrootHandler(req, res) {res.end('Hello world!');});// The error handler must be before any other error middleware and after all controllers, by default only captures 500app.use(Sentry.Handlers.errorHandler());// Optional fallthrough error handlerapp.use(functiononError(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) {returntrue; //by default only captures 500, but lets capture all errors } })); //must be first error handler and after all controllers