Add bugsnag
This commit is contained in:
parent
99245b9ead
commit
863fcd5e9d
3 changed files with 70 additions and 17 deletions
|
@ -19,6 +19,8 @@
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Bugsnag" Version="2.2.0" />
|
||||||
|
<PackageReference Include="Bugsnag.AspNet.Core" Version="2.2.0" />
|
||||||
<PackageReference Include="CommandLineParser" Version="2.2.1" />
|
<PackageReference Include="CommandLineParser" Version="2.2.1" />
|
||||||
<PackageReference Include="Discord.Net">
|
<PackageReference Include="Discord.Net">
|
||||||
<Version>2.0.0-beta2-00984</Version>
|
<Version>2.0.0-beta2-00984</Version>
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Bugsnag;
|
||||||
|
using Bugsnag.Payload;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.Net;
|
using Discord.Net;
|
||||||
|
using Geekbot.net.Lib.GlobalSettings;
|
||||||
using Geekbot.net.Lib.Localization;
|
using Geekbot.net.Lib.Localization;
|
||||||
using Geekbot.net.Lib.Logger;
|
using Geekbot.net.Lib.Logger;
|
||||||
using SharpRaven;
|
using SharpRaven;
|
||||||
using SharpRaven.Data;
|
using SharpRaven.Data;
|
||||||
|
using Exception = System.Exception;
|
||||||
|
|
||||||
namespace Geekbot.net.Lib.ErrorHandling
|
namespace Geekbot.net.Lib.ErrorHandling
|
||||||
{
|
{
|
||||||
|
@ -16,8 +21,9 @@ namespace Geekbot.net.Lib.ErrorHandling
|
||||||
private readonly ITranslationHandler _translation;
|
private readonly ITranslationHandler _translation;
|
||||||
private readonly IRavenClient _raven;
|
private readonly IRavenClient _raven;
|
||||||
private readonly bool _errorsInChat;
|
private readonly bool _errorsInChat;
|
||||||
|
private readonly IClient _bugsnag;
|
||||||
|
|
||||||
public ErrorHandler(IGeekbotLogger logger, ITranslationHandler translation, bool errorsInChat)
|
public ErrorHandler(IGeekbotLogger logger, ITranslationHandler translation, IGlobalSettings globalSettings, bool errorsInChat)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_translation = translation;
|
_translation = translation;
|
||||||
|
@ -33,6 +39,21 @@ namespace Geekbot.net.Lib.ErrorHandling
|
||||||
{
|
{
|
||||||
_raven = null;
|
_raven = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var bugsnagApiKey = globalSettings.GetKey("BugsnagApiKey");
|
||||||
|
if (!string.IsNullOrEmpty(bugsnagApiKey))
|
||||||
|
{
|
||||||
|
_bugsnag = new Bugsnag.Client(new Bugsnag.Configuration
|
||||||
|
{
|
||||||
|
ApiKey = bugsnagApiKey,
|
||||||
|
AppVersion = Constants.BotVersion()
|
||||||
|
});
|
||||||
|
_logger.Information(LogSource.Geekbot, "Command Errors will be logged to Bugsnag");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_bugsnag = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HandleCommandException(Exception e, ICommandContext context, string errorMessage = "def")
|
public async Task HandleCommandException(Exception e, ICommandContext context, string errorMessage = "def")
|
||||||
|
@ -65,20 +86,8 @@ namespace Geekbot.net.Lib.ErrorHandling
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_raven == null) return;
|
ReportExternal(e, errorObj);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -98,6 +107,48 @@ namespace Geekbot.net.Lib.ErrorHandling
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ReportExternal(Exception e, MessageDto errorObj)
|
||||||
|
{
|
||||||
|
if (_raven != null)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
_bugsnag?.Notify(e, (report) =>
|
||||||
|
{
|
||||||
|
report.Event.Metadata.Add("Discord Location", new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{"Guild Name", errorObj.Guild.Name},
|
||||||
|
{"Guild Id", errorObj.Guild.Id},
|
||||||
|
{"Channel Name", errorObj.Channel.Name},
|
||||||
|
{"Channel Id", errorObj.Channel.Id}
|
||||||
|
});
|
||||||
|
report.Event.Metadata.Add("Message Info", new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{"Content", errorObj.Message.Content},
|
||||||
|
{"Id", errorObj.Message.Id},
|
||||||
|
{"Attachments", errorObj.Message.Attachments.ToString()},
|
||||||
|
{"ChannelMentions", errorObj.Message.ChannelMentions.ToString()},
|
||||||
|
{"UserMentions", errorObj.Message.UserMentions.ToString()},
|
||||||
|
{"RoleMentions", errorObj.Message.RoleMentions.ToString()},
|
||||||
|
});
|
||||||
|
report.Event.Severity = Severity.Error;
|
||||||
|
report.Event.User = new User
|
||||||
|
{
|
||||||
|
Id = errorObj.User.Id,
|
||||||
|
Name = errorObj.User.Name
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -162,7 +162,7 @@ namespace Geekbot.net
|
||||||
|
|
||||||
_logger.Information(LogSource.Geekbot, "Registering Stuff");
|
_logger.Information(LogSource.Geekbot, "Registering Stuff");
|
||||||
var translationHandler = new TranslationHandler(_databaseInitializer.Initialize(), _logger);
|
var translationHandler = new TranslationHandler(_databaseInitializer.Initialize(), _logger);
|
||||||
var errorHandler = new ErrorHandler(_logger, translationHandler, _runParameters.ExposeErrors);
|
var errorHandler = new ErrorHandler(_logger, translationHandler, _globalSettings, _runParameters.ExposeErrors);
|
||||||
var reactionListener = new ReactionListener(_redis.Db);
|
var reactionListener = new ReactionListener(_redis.Db);
|
||||||
_services.AddSingleton<IErrorHandler>(errorHandler);
|
_services.AddSingleton<IErrorHandler>(errorHandler);
|
||||||
_services.AddSingleton<ITranslationHandler>(translationHandler);
|
_services.AddSingleton<ITranslationHandler>(translationHandler);
|
||||||
|
|
Loading…
Reference in a new issue