use Sentry hints

This commit is contained in:
Lee 2024-07-06 00:24:06 +01:00
parent fa932b7fc2
commit 9395ae73b9
3 changed files with 26 additions and 1 deletions

@ -69,7 +69,6 @@ public class EmbedUtils {
if (channel != null) { if (channel != null) {
channel.sendMessageEmbeds(embed.build()).queue(); channel.sendMessageEmbeds(embed.build()).queue();
} }
Sentry.captureException(ex); // Capture the exception
return embed; return embed;
} }
} }

@ -8,6 +8,8 @@ import cc.fascinated.bat.config.Config;
import cc.fascinated.bat.features.FeatureProfile; import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser; import cc.fascinated.bat.model.BatUser;
import io.sentry.Hint;
import io.sentry.Sentry;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
@ -232,6 +234,14 @@ public class CommandService extends ListenerAdapter {
} catch (Exception ex) { } catch (Exception ex) {
log.error("An error occurred while executing command \"{}\"", command.getInfo().getName(), ex); log.error("An error occurred while executing command \"{}\"", command.getInfo().getName(), ex);
event.replyEmbeds(EmbedUtils.genericInteractionError(ex).build()).setEphemeral(true).queue(); event.replyEmbeds(EmbedUtils.genericInteractionError(ex).build()).setEphemeral(true).queue();
Hint hint = new Hint();
hint.set("command", command.getInfo().getName());
hint.set("user", user.getId());
if (guild != null) {
hint.set("guild", guild.getId());
}
Sentry.captureException(ex, hint); // Capture the exception
} }
} }
} }

@ -5,6 +5,8 @@ import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.model.BatGuild; import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser; import cc.fascinated.bat.model.BatUser;
import cc.fascinated.bat.model.DiscordMessage; import cc.fascinated.bat.model.DiscordMessage;
import io.sentry.Hint;
import io.sentry.Sentry;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import net.dv8tion.jda.api.entities.Invite; import net.dv8tion.jda.api.entities.Invite;
@ -165,6 +167,13 @@ public class EventService extends ListenerAdapter {
} catch (Exception ex) { } catch (Exception ex) {
log.error("An error occurred while handling a modal interaction.", ex); log.error("An error occurred while handling a modal interaction.", ex);
event.replyEmbeds(EmbedUtils.genericInteractionError(ex).build()).setEphemeral(true).queue(); event.replyEmbeds(EmbedUtils.genericInteractionError(ex).build()).setEphemeral(true).queue();
Hint hint = new Hint();
hint.set("componentId", event.getComponentId());
hint.set("user", user.getId());
if (event.getGuild() != null) {
hint.set("guild", event.getGuild().getId());
}
Sentry.captureException(ex, hint); // Capture the exception
} }
} }
@ -183,6 +192,13 @@ public class EventService extends ListenerAdapter {
} catch (Exception ex) { } catch (Exception ex) {
log.error("An error occurred while handling a modal interaction.", ex); log.error("An error occurred while handling a modal interaction.", ex);
event.replyEmbeds(EmbedUtils.genericInteractionError(ex).build()).setEphemeral(true).queue(); event.replyEmbeds(EmbedUtils.genericInteractionError(ex).build()).setEphemeral(true).queue();
Hint hint = new Hint();
hint.set("modalId", event.getModalId());
hint.set("user", user.getId());
if (event.getGuild() != null) {
hint.set("guild", event.getGuild().getId());
}
Sentry.captureException(ex, hint); // Capture the exception
} }
} }