Move Sentry SDK init to the main init process

This commit is contained in:
Daan Boerlage 2021-09-17 14:04:30 +02:00
parent 5c507b026c
commit 1f518e980c
Signed by: daan
GPG key ID: FCE070E1E4956606
2 changed files with 19 additions and 13 deletions

View file

@ -26,6 +26,8 @@ using Geekbot.Core.WikipediaClient;
using Geekbot.Web;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Sentry;
using Constants = Geekbot.Core.Constants;
namespace Geekbot.Bot
{
@ -90,7 +92,9 @@ namespace Geekbot.Bot
_logger.Information(LogSource.Api, "Starting Web API");
StartWebApi();
RegisterSentry();
_logger.Information(LogSource.Geekbot, "Done and ready for use");
await Task.Delay(-1);
@ -224,5 +228,19 @@ namespace Geekbot.Bot
var highscoreManager = new HighscoreManager(_databaseInitializer.Initialize(), _userRepository);
WebApiStartup.StartWebApi(_logger, _runParameters, _commands, _databaseInitializer.Initialize(), _client, _globalSettings, highscoreManager);
}
private void RegisterSentry()
{
var sentryDsn = _runParameters.SentryEndpoint;
if (string.IsNullOrEmpty(sentryDsn)) return;
SentrySdk.Init(o =>
{
o.Dsn = sentryDsn;
o.Release = Constants.BotVersion();
o.Environment = "Production";
o.TracesSampleRate = 1.0;
});
_logger.Information(LogSource.Geekbot, $"Command Errors will be logged to Sentry: {sentryDsn}");
}
}
}

View file

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.Core.Logger;
@ -19,17 +18,6 @@ namespace Geekbot.Core.ErrorHandling
_logger = logger;
_getDefaultErrorText = getDefaultErrorText;
_errorsInChat = runParameters.ExposeErrors;
var sentryDsn = runParameters.SentryEndpoint;
if (string.IsNullOrEmpty(sentryDsn)) return;
SentrySdk.Init(o =>
{
o.Dsn = sentryDsn;
o.Release = Constants.BotVersion();
o.Environment = "Production";
});
_logger.Information(LogSource.Geekbot, $"Command Errors will be logged to Sentry: {sentryDsn}");
}
public async Task HandleCommandException(Exception e, ICommandContext context, string errorMessage = "def")