Sentry
Introduction to Sentry
Sentry is an open-source platform for workflow productivity, aggregating errors from across the stack in real time. This monitoring stack is easy to configure, can be easily integrated into a multitude of projects and centralizes the logs of all projects in the same place.
Link to Sentry : https://sentry.io/organizations/affilium-labs/projects/quebec-municipal/?project=4504057672630272
Locate your Sentry DSN by going to the project settings
Project settings > Client Keys (DSN)
Sentry with .NET Core
Here is a brief explanation of the configuration of Sentry with .NET Core. Once Sentry is properly installed and imported, we link Sentry to the desired project using the DSN found previously.
Ensure that your current appsettings file have this configuration:
"Sentry": {
"Dsn": "your_project_dsn"
}
It's in Program.cs we link our exceptions to Sentry. We just send to Sentry exceptions which have HTTP status code equals or greater than 500, because these errors are unexpected server side errors. For example, if a user just enter bad login credentials, we don't have to receive exceptions of this level.
builder.WebHost.UseSentry(o => o.BeforeSend = sentryEvent =>
{
if (sentryEvent.Exception is HttpException httpException)
{
if ((int)httpException.StatusCode < 500)
{
return null; // Don't send this event to Sentry
};
}
sentryEvent.ServerName = null; // Never send Server Name to Sentry
return sentryEvent;
});
var app = builder.Build();
app.UseSentryTracing();