From 1f518e980c323b728e43b85d9f829738bd18754e Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Fri, 17 Sep 2021 14:04:30 +0200 Subject: [PATCH] Move Sentry SDK init to the main init process --- src/Bot/Program.cs | 20 +++++++++++++++++++- src/Core/ErrorHandling/ErrorHandler.cs | 12 ------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Bot/Program.cs b/src/Bot/Program.cs index 3429fbc..4d7526b 100644 --- a/src/Bot/Program.cs +++ b/src/Bot/Program.cs @@ -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}"); + } } } \ No newline at end of file diff --git a/src/Core/ErrorHandling/ErrorHandler.cs b/src/Core/ErrorHandling/ErrorHandler.cs index a5ccc8e..0b55bd8 100644 --- a/src/Core/ErrorHandling/ErrorHandler.cs +++ b/src/Core/ErrorHandling/ErrorHandler.cs @@ -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")