12#include <netpacket/packet.h>
16#include <spdlog/spdlog.h>
24 void setVersionContext()
26 std::string versionBuffer;
27 const sentry_value_t versionContext = sentry_value_new_object();
28 versionBuffer =
"v" + std::string(PROJECT_FULL_REVISION);
29 sentry_value_set_by_key(versionContext, PROJECT_NAME, sentry_value_new_string(versionBuffer.c_str()));
30 versionBuffer = std::string(PROJECT_BUILD_DATE) +
" " + PROJECT_BUILD_TIME;
31 sentry_value_set_by_key(versionContext,
"Release Date", sentry_value_new_string(versionBuffer.c_str()));
32 sentry_set_context(
"Version", versionContext);
38 std::array<char, BUFSIZ> hostBuffer{};
39 gethostname(hostBuffer.data(), BUFSIZ);
40 const sentry_value_t hostContext = sentry_value_new_object();
41 sentry_value_set_by_key(hostContext,
"Hostname", sentry_value_new_string(hostBuffer.data()));
44 const std::filesystem::path cpuInfoPath =
"/proc/cpuinfo";
48 sentry_value_set_by_key(hostContext,
"Thread count", sentry_value_new_string(word.c_str()));
50 sentry_value_set_by_key(hostContext,
"Core count", sentry_value_new_string(word.c_str()));
52 sentry_value_set_by_key(hostContext,
"Model", sentry_value_new_string(word.c_str()));
54 sentry_value_set_by_key(hostContext,
"Vendor ID", sentry_value_new_string(word.c_str()));
56 sentry_set_context(
"Host", hostContext);
60 void setNetworkContext()
62 ifaddrs *ifaddr =
nullptr;
63 if (getifaddrs(&ifaddr) < 0)
69 const sentry_value_t networkContext = sentry_value_new_object();
70 for (
const ifaddrs *ifa = ifaddr; ifa !=
nullptr; ifa = ifa->ifa_next)
72 if (ifa->ifa_addr ==
nullptr || ((ifa->ifa_flags & IFF_RUNNING) == 0) ||
73 (ifa->ifa_flags & IFF_LOOPBACK) != 0)
78 switch (ifa->ifa_addr->sa_family)
81 std::array<char, INET_ADDRSTRLEN> host{};
82 inet_ntop(AF_INET, &(std::bit_cast<sockaddr_in *>(ifa->ifa_addr))->sin_addr, host.data(),
84 sentry_value_set_by_key(networkContext, (std::string(ifa->ifa_name) +
".ipv4").c_str(),
85 sentry_value_new_string(host.data()));
89 std::array<char, INET6_ADDRSTRLEN> host{};
90 inet_ntop(AF_INET6, &(std::bit_cast<sockaddr_in6 *>(ifa->ifa_addr))->sin6_addr, host.data(),
92 sentry_value_set_by_key(networkContext, (std::string(ifa->ifa_name) +
".ipv6").c_str(),
93 sentry_value_new_string(host.data()));
97 std::array<char, MAC_LEN> host{};
98 if (
const auto *sock = std::bit_cast<sockaddr_ll *>(ifa->ifa_addr);
99 std::format_to_n(host.data(),
MAC_LEN,
"{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}",
100 sock->sll_addr[0], sock->sll_addr[1], sock->sll_addr[2], sock->sll_addr[3],
101 sock->sll_addr[4], sock->sll_addr[5])
104 sentry_value_set_by_key(networkContext, (std::string(ifa->ifa_name) +
".mac").c_str(),
105 sentry_value_new_string(host.data()));
115 sentry_set_context(
"Network", networkContext);
123 if (sentryAddress.empty())
130 sentry_options_t *sentryOptions = sentry_options_new();
131 sentry_options_set_release(sentryOptions, PROJECT_FULL_REVISION);
132 sentry_options_set_dsn(sentryOptions, sentryAddress.c_str());
133 sentry_options_set_debug(sentryOptions, 0);
134 sentry_options_set_logger_level(sentryOptions, SENTRY_LEVEL_WARNING);
137 sentry_init(sentryOptions);
140 sentry_set_tag(
"compiler.name", COMPILER_NAME);
141 sentry_set_tag(
"compiler.version", COMPILER_VERSION);
142 sentry_set_tag(
"build", BUILD_TYPE);
167 case spdlog::level::warn:
168 sentry_capture_event(sentry_value_new_message_event(
169 SENTRY_LEVEL_WARNING,
"main", std::string(msg.payload.data(), msg.payload.size()).c_str()));
171 case spdlog::level::err:
172 sentry_capture_event(sentry_value_new_message_event(
173 SENTRY_LEVEL_ERROR,
"main", std::string(msg.payload.data(), msg.payload.size()).c_str()));
175 case spdlog::level::critical:
176 sentry_capture_event(sentry_value_new_message_event(
177 SENTRY_LEVEL_FATAL,
"main", std::string(msg.payload.data(), msg.payload.size()).c_str()));
179 case spdlog::level::trace:
180 case spdlog::level::debug:
181 case spdlog::level::info:
182 case spdlog::level::off:
std::vector< std::string > findFromFile(const std::filesystem::path &filePath, const std::string &pattern, std::string &lastWord)
sentry_api_sink(const std::string &sentryAddress)
void sink_it_(const details::log_msg &msg) override