Migrate from RavenSharp to the SentrySDK

This commit is contained in:
Daan Boerlage 2021-09-17 12:22:26 +02:00
parent f19ddb30b2
commit 989057a0b0
Signed by: daan
GPG key ID: FCE070E1E4956606
3 changed files with 21 additions and 21 deletions

View file

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Discord.Commands;
using Geekbot.Core.Logger;
using SharpRaven;
using SharpRaven.Data;
using Sentry;
using Exception = System.Exception;
namespace Geekbot.Core.ErrorHandling
@ -12,7 +12,6 @@ namespace Geekbot.Core.ErrorHandling
{
private readonly IGeekbotLogger _logger;
private readonly Func<string> _getDefaultErrorText;
private readonly IRavenClient _raven;
private readonly bool _errorsInChat;
public ErrorHandler(IGeekbotLogger logger, RunParameters runParameters, Func<string> getDefaultErrorText)
@ -22,15 +21,15 @@ namespace Geekbot.Core.ErrorHandling
_errorsInChat = runParameters.ExposeErrors;
var sentryDsn = runParameters.SentryEndpoint;
if (!string.IsNullOrEmpty(sentryDsn))
if (string.IsNullOrEmpty(sentryDsn)) return;
SentrySdk.Init(o =>
{
_raven = new RavenClient(sentryDsn) { Release = Constants.BotVersion(), Environment = "Production" };
_logger.Information(LogSource.Geekbot, $"Command Errors will be logged to Sentry: {sentryDsn}");
}
else
{
_raven = null;
}
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")
@ -83,18 +82,19 @@ namespace Geekbot.Core.ErrorHandling
private void ReportExternal(Exception e, MessageDto errorObj)
{
if (_raven == null) return;
if (!SentrySdk.IsEnabled) return;
var sentryEvent = new SentryEvent(e)
{
Tags =
{
["discord_server"] = errorObj.Guild.Name,
["discord_user"] = errorObj.User.Name
},
Message = errorObj.Message.Content,
Extra = errorObj
};
_raven.Capture(sentryEvent);
sentryEvent.SetTag("discord_server", errorObj.Guild.Name);
sentryEvent.SetExtra("Channel", errorObj.Channel);
sentryEvent.SetExtra("Guild", errorObj.Guild);
sentryEvent.SetExtra("Message", errorObj.Message);
sentryEvent.SetExtra("User", errorObj.User);
SentrySdk.CaptureEvent(sentryEvent);
}
}
}