Refactor Sentry scope enrichment
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using App.Metrics;
|
||||
@@ -129,21 +128,6 @@ namespace PluralKit.Bot
|
||||
{
|
||||
_metrics.Measure.Meter.Mark(BotMetrics.MessagesReceived);
|
||||
_lastMessageCache.AddMessage(evt.Channel.Id, evt.Message.Id);
|
||||
|
||||
// Add message info as Sentry breadcrumb
|
||||
_sentryScope.AddBreadcrumb(evt.Message.Content, "event.message", data: new Dictionary<string, string>
|
||||
{
|
||||
{"user", evt.Author.Id.ToString()},
|
||||
{"channel", evt.Channel.Id.ToString()},
|
||||
{"guild", evt.Channel.GuildId.ToString()},
|
||||
{"message", evt.Message.Id.ToString()},
|
||||
});
|
||||
_sentryScope.SetTag("shard", evt.Client.ShardId.ToString());
|
||||
|
||||
// Also report information about the bot's permissions in the channel
|
||||
// We get a lot of permission errors so this'll be useful for determining problems
|
||||
var perms = evt.Channel.BotPermissions();
|
||||
_sentryScope.AddBreadcrumb(perms.ToPermissionString(), "permissions");
|
||||
}
|
||||
}
|
||||
}
|
@@ -12,37 +12,19 @@ namespace PluralKit.Bot
|
||||
public class MessageDeleted: IEventHandler<MessageDeleteEventArgs>, IEventHandler<MessageBulkDeleteEventArgs>
|
||||
{
|
||||
private readonly ProxyService _proxy;
|
||||
private readonly Scope _sentryScope;
|
||||
|
||||
public MessageDeleted(Scope sentryScope, ProxyService proxy)
|
||||
public MessageDeleted(ProxyService proxy)
|
||||
{
|
||||
_sentryScope = sentryScope;
|
||||
_proxy = proxy;
|
||||
}
|
||||
|
||||
public Task Handle(MessageDeleteEventArgs evt)
|
||||
{
|
||||
_sentryScope.AddBreadcrumb("", "event.messageDelete", data: new Dictionary<string, string>()
|
||||
{
|
||||
{"channel", evt.Channel.Id.ToString()},
|
||||
{"guild", evt.Channel.GuildId.ToString()},
|
||||
{"message", evt.Message.Id.ToString()},
|
||||
});
|
||||
_sentryScope.SetTag("shard", evt.Client.ShardId.ToString());
|
||||
|
||||
return _proxy.HandleMessageDeletedAsync(evt);
|
||||
}
|
||||
|
||||
public Task Handle(MessageBulkDeleteEventArgs evt)
|
||||
{
|
||||
_sentryScope.AddBreadcrumb("", "event.messageDelete", data: new Dictionary<string, string>()
|
||||
{
|
||||
{"channel", evt.Channel.Id.ToString()},
|
||||
{"guild", evt.Channel.Id.ToString()},
|
||||
{"messages", string.Join(",", evt.Messages.Select(m => m.Id))},
|
||||
});
|
||||
_sentryScope.SetTag("shard", evt.Client.ShardId.ToString());
|
||||
|
||||
return _proxy.HandleMessageBulkDeleteAsync(evt);
|
||||
}
|
||||
}
|
||||
|
@@ -35,14 +35,6 @@ namespace PluralKit.Bot
|
||||
|
||||
// Also, if this is in DMs don't bother either
|
||||
if (evt.Channel.Guild == null) return;
|
||||
|
||||
_sentryScope.AddBreadcrumb(evt.Message.Content ?? "<unknown>", "event.messageEdit", data: new Dictionary<string, string>()
|
||||
{
|
||||
{"channel", evt.Channel.Id.ToString()},
|
||||
{"guild", evt.Channel.GuildId.ToString()},
|
||||
{"message", evt.Message.Id.ToString()}
|
||||
});
|
||||
_sentryScope.SetTag("shard", evt.Client.ShardId.ToString());
|
||||
|
||||
// If this isn't the last message in the channel, don't do anything
|
||||
if (_lastMessageCache.GetLastMessage(evt.Channel.Id) != evt.Message.Id) return;
|
||||
|
@@ -10,25 +10,14 @@ namespace PluralKit.Bot
|
||||
public class ReactionAdded: IEventHandler<MessageReactionAddEventArgs>
|
||||
{
|
||||
private readonly ProxyService _proxy;
|
||||
private readonly Scope _sentryScope;
|
||||
|
||||
public ReactionAdded(ProxyService proxy, Scope sentryScope)
|
||||
public ReactionAdded(ProxyService proxy)
|
||||
{
|
||||
_proxy = proxy;
|
||||
_sentryScope = sentryScope;
|
||||
}
|
||||
|
||||
public Task Handle(MessageReactionAddEventArgs evt)
|
||||
{
|
||||
_sentryScope.AddBreadcrumb("", "event.reaction", data: new Dictionary<string, string>()
|
||||
{
|
||||
{"user", evt.User.Id.ToString()},
|
||||
{"channel", (evt.Channel?.Id ?? 0).ToString()},
|
||||
{"guild", (evt.Channel?.GuildId ?? 0).ToString()},
|
||||
{"message", evt.Message.Id.ToString()},
|
||||
{"reaction", evt.Emoji.Name}
|
||||
});
|
||||
_sentryScope.SetTag("shard", evt.Client.ShardId.ToString());
|
||||
return _proxy.HandleReactionAddedAsync(evt);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user