Track current shard in Sentry reports

This commit is contained in:
Ske 2020-02-12 14:37:11 +01:00
parent 1d3acb2392
commit b68e221fc6

View File

@ -269,7 +269,8 @@ namespace PluralKit.Bot
public async Task HandleMessage(SocketMessage arg) public async Task HandleMessage(SocketMessage arg)
{ {
if (_client.GetShardFor((arg.Channel as IGuildChannel)?.Guild).ConnectionState != ConnectionState.Connected) var shard = _client.GetShardFor((arg.Channel as IGuildChannel)?.Guild);
if (shard.ConnectionState != ConnectionState.Connected)
return; // Discard messages while the bot "catches up" to avoid unnecessary CPU pressure causing timeouts return; // Discard messages while the bot "catches up" to avoid unnecessary CPU pressure causing timeouts
RegisterMessageMetrics(arg); RegisterMessageMetrics(arg);
@ -290,6 +291,7 @@ namespace PluralKit.Bot
{"guild", ((msg.Channel as IGuildChannel)?.GuildId ?? 0).ToString()}, {"guild", ((msg.Channel as IGuildChannel)?.GuildId ?? 0).ToString()},
{"message", msg.Id.ToString()}, {"message", msg.Id.ToString()},
}); });
_sentryScope.SetTag("shard", shard.ShardId.ToString());
// Add to last message cache // Add to last message cache
_lastMessageCache.AddMessage(arg.Channel.Id, arg.Id); _lastMessageCache.AddMessage(arg.Channel.Id, arg.Id);
@ -374,7 +376,8 @@ namespace PluralKit.Bot
{"message", message.Id.ToString()}, {"message", message.Id.ToString()},
{"reaction", reaction.Emote.Name} {"reaction", reaction.Emote.Name}
}); });
_sentryScope.SetTag("shard", _client.GetShardIdFor((channel as IGuildChannel)?.Guild).ToString());
return _proxy.HandleReactionAddedAsync(message, channel, reaction); return _proxy.HandleReactionAddedAsync(message, channel, reaction);
} }
@ -386,7 +389,8 @@ namespace PluralKit.Bot
{"guild", ((channel as IGuildChannel)?.GuildId ?? 0).ToString()}, {"guild", ((channel as IGuildChannel)?.GuildId ?? 0).ToString()},
{"message", message.Id.ToString()}, {"message", message.Id.ToString()},
}); });
_sentryScope.SetTag("shard", _client.GetShardIdFor((channel as IGuildChannel)?.Guild).ToString());
return _proxy.HandleMessageDeletedAsync(message, channel); return _proxy.HandleMessageDeletedAsync(message, channel);
} }
@ -399,19 +403,21 @@ namespace PluralKit.Bot
{"guild", ((channel as IGuildChannel)?.GuildId ?? 0).ToString()}, {"guild", ((channel as IGuildChannel)?.GuildId ?? 0).ToString()},
{"messages", string.Join(",", messages.Select(m => m.Id))}, {"messages", string.Join(",", messages.Select(m => m.Id))},
}); });
_sentryScope.SetTag("shard", _client.GetShardIdFor((channel as IGuildChannel)?.Guild).ToString());
return _proxy.HandleMessageBulkDeleteAsync(messages, channel); return _proxy.HandleMessageBulkDeleteAsync(messages, channel);
} }
public async Task HandleMessageEdited(Cacheable<IMessage, ulong> oldMessage, SocketMessage newMessage, ISocketMessageChannel channel) public async Task HandleMessageEdited(Cacheable<IMessage, ulong> oldMessage, SocketMessage newMessage, ISocketMessageChannel channel)
{ {
_sentryScope.AddBreadcrumb(newMessage.Content ?? "", "event.messageEdit", data: new Dictionary<string, string>() _sentryScope.AddBreadcrumb(newMessage.Content, "event.messageEdit", data: new Dictionary<string, string>()
{ {
{"channel", channel.Id.ToString()}, {"channel", channel.Id.ToString()},
{"guild", ((channel as IGuildChannel)?.GuildId ?? 0).ToString()}, {"guild", ((channel as IGuildChannel)?.GuildId ?? 0).ToString()},
{"message", newMessage.Id.ToString()} {"message", newMessage.Id.ToString()}
}); });
_sentryScope.SetTag("shard", _client.GetShardIdFor((channel as IGuildChannel)?.Guild).ToString());
// If this isn't a guild, bail // If this isn't a guild, bail
if (!(channel is IGuildChannel gc)) return; if (!(channel is IGuildChannel gc)) return;