diff options
author | Cara Salter <cara@devcara.com> | 2023-04-06 21:43:29 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2023-04-06 21:43:29 -0400 |
commit | acd1befde66db492149992199fadca92e55cc97b (patch) | |
tree | 16251d96cd8efd5323fa8f095bb29f110030f387 /src | |
parent | 555810bedc0cf9d9d954f56b5a2c8c92522ad27f (diff) | |
download | 142bot-acd1befde66db492149992199fadca92e55cc97b.tar.gz 142bot-acd1befde66db492149992199fadca92e55cc97b.zip |
sentry: Add sentry support
Change-Id: I3cff2a05c63e88abddc8eff6a3ee9a9f73a5172d
Diffstat (limited to 'src')
-rw-r--r-- | src/bot.cpp | 4 | ||||
-rw-r--r-- | src/db.cpp | 7 | ||||
-rw-r--r-- | src/main.cpp | 17 |
3 files changed, 27 insertions, 1 deletions
diff --git a/src/bot.cpp b/src/bot.cpp index ad818a0..d0f6377 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -1,4 +1,5 @@ +#include "sentry.h" #include <dpp/snowflake.h> #include <stdlib.h> #include <string> @@ -37,7 +38,8 @@ Bot::Bot(bool devel, dpp::cluster* cluster) { * Returns false on any error */ bool Bot::run_database_migrations() { - + sentry_value_t crumb = sentry_value_new_breadcrumb("debug", "Running database migrations"); + sentry_value_set_by_key(crumb, "level", sentry_value_new_string("debug")); // Start a transaction this->core->log(dpp::ll_info, "Attempting database migrations..."); pqxx::work w(this->conn); @@ -24,6 +24,7 @@ #include <pqxx/pqxx> #include <fmt/format.h> #include <cstdarg> +#include <sentry.h> using namespace std; @@ -36,6 +37,7 @@ namespace db { **/ pqxx::connection connect(const std::string &host, const std::string &user, const std::string &pass, const std::string &db, int port) { std::lock_guard<std::mutex> db_lock(db_mutex); + std::string cn_s = "postgresql://"; @@ -60,6 +62,11 @@ namespace db { cn_s = cn_s + "/" + db; } + sentry_value_t crumb = sentry_value_new_breadcrumb("default", "Started Database Connection"); + sentry_value_set_by_key(crumb, "level", sentry_value_new_string("db")); + sentry_value_set_by_key(crumb, "data", sentry_value_new_string(cn_s.c_str())); + sentry_add_breadcrumb(crumb); + try { pqxx::connection c{cn_s}; return c; diff --git a/src/main.cpp b/src/main.cpp index f54e418..db79289 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,15 +9,31 @@ #include <spdlog/sinks/rotating_file_sink.h> #include <string> +#include <sentry.h> + +#include "142bot_config.h" + using namespace std; using json = nlohmann::json; + + int main(int argc, char const *argv[]) { std::ifstream f("config.json"); json cfg = json::parse(f); string token = cfg.value("token", "bad-token"); + sentry_options_t *options = sentry_options_new(); + sentry_options_set_dsn(options, "https://26f71a6064ee478c8d944b976b89eb3c@o4504969688317952.ingest.sentry.io/4504969689563136"); + // This is also the default-path. For further information and recommendations: + // https://docs.sentry.io/platforms/native/configuration/options/#database-path + sentry_options_set_database_path(options, ".sentry-native"); + sentry_options_set_release(options, "142bot@" + onefortytwobot_VERSION_MAJOR + '.' + onefortytwobot_VERSION_MINOR); + sentry_options_set_debug(options, 0); + sentry_options_set_environment(options, onefortytwobot_env); + sentry_options_set_symbolize_stacktraces(options, 1); + sentry_init(options); dpp::cluster bot(token, dpp::intents::i_all_intents); std::shared_ptr<spdlog::logger> log; @@ -68,5 +84,6 @@ int main(int argc, char const *argv[]) { bot.on_message_reaction_add(std::bind(&Bot::onMessageReactionAdd, &client, std::placeholders::_1)); bot.start(dpp::st_wait); + sentry_close(); return 0; } |