11#include <netpacket/packet.h>
15#include <spdlog/spdlog.h>
23 void setVersionContext()
25 std::string versionBuffer;
26 const sentry_value_t versionContext = sentry_value_new_object();
27 versionBuffer =
"v" + std::string(PROJECT_FULL_REVISION);
28 sentry_value_set_by_key(versionContext, PROJECT_NAME, sentry_value_new_string(versionBuffer.c_str()));
29 versionBuffer = std::string(PROJECT_BUILD_DATE) +
" " + PROJECT_BUILD_TIME;
30 sentry_value_set_by_key(versionContext,
"Release Date", sentry_value_new_string(versionBuffer.c_str()));
31 sentry_set_context(
"Version", versionContext);
37 std::array<char, BUFSIZ> hostBuffer{};
38 gethostname(hostBuffer.data(), BUFSIZ);
39 const sentry_value_t hostContext = sentry_value_new_object();
40 sentry_value_set_by_key(hostContext,
"Hostname", sentry_value_new_string(hostBuffer.data()));
43 const std::string cpuInfoPath =
"/proc/cpuinfo";
47 sentry_value_set_by_key(hostContext,
"Thread count", sentry_value_new_string(word.c_str()));
49 sentry_value_set_by_key(hostContext,
"Core count", sentry_value_new_string(word.c_str()));
51 sentry_value_set_by_key(hostContext,
"Model", sentry_value_new_string(word.c_str()));
53 sentry_value_set_by_key(hostContext,
"Vendor ID", sentry_value_new_string(word.c_str()));
55 sentry_set_context(
"Host", hostContext);
59 void setNetworkContext()
61 ifaddrs *ifaddr =
nullptr;
62 if (getifaddrs(&ifaddr) < 0)
68 const sentry_value_t networkContext = sentry_value_new_object();
69 for (ifaddrs *ifa = ifaddr; ifa !=
nullptr; ifa = ifa->ifa_next)
71 if (ifa->ifa_addr ==
nullptr || ((ifa->ifa_flags & IFF_PROMISC) != 0) || ((ifa->ifa_flags & IFF_UP) != 0))
76 switch (ifa->ifa_addr->sa_family)
79 std::array<char, INET_ADDRSTRLEN> host{};
80 inet_ntop(AF_INET, &(
reinterpret_cast<sockaddr_in *
>(ifa->ifa_addr))->sin_addr, host.data(),
82 sentry_value_set_by_key(networkContext, (std::string(ifa->ifa_name) +
".ipv4").c_str(),
83 sentry_value_new_string(host.data()));
87 std::array<char, INET6_ADDRSTRLEN> host{};
88 inet_ntop(AF_INET6, &(
reinterpret_cast<sockaddr_in6 *
>(ifa->ifa_addr))->sin6_addr, host.data(),
90 sentry_value_set_by_key(networkContext, (std::string(ifa->ifa_name) +
".ipv6").c_str(),
91 sentry_value_new_string(host.data()));
95 std::array<char, MAC_LEN> host{};
96 if (
const auto *sock =
reinterpret_cast<sockaddr_ll *
>(ifa->ifa_addr);
97 snprintf(host.data(),
MAC_LEN,
"%02x:%02x:%02x:%02x:%02x:%02x", sock->sll_addr[0],
98 sock->sll_addr[1], sock->sll_addr[2], sock->sll_addr[3], sock->sll_addr[4],
99 sock->sll_addr[5]) > 0)
101 sentry_value_set_by_key(networkContext, (std::string(ifa->ifa_name) +
".mac").c_str(),
102 sentry_value_new_string(host.data()));
112 sentry_set_context(
"Network", networkContext);
120 if (sentryAddress.empty())
124 _sentryAvailable =
true;
127 sentry_options_t *sentryOptions = sentry_options_new();
128 sentry_options_set_release(sentryOptions, PROJECT_FULL_REVISION);
129 sentry_options_set_dsn(sentryOptions, sentryAddress.c_str());
132 sentry_init(sentryOptions);
135 sentry_set_tag(
"compiler.name", COMPILER_NAME);
136 sentry_set_tag(
"compiler.version", COMPILER_VERSION);
137 sentry_set_tag(
"build", BUILD_TYPE);
156 if (!_sentryAvailable)
162 case spdlog::level::warn:
163 sentry_capture_event(sentry_value_new_message_event(
164 SENTRY_LEVEL_WARNING,
"main", std::string(msg.payload.data(), msg.payload.size()).c_str()));
166 case spdlog::level::err:
167 sentry_capture_event(sentry_value_new_message_event(
168 SENTRY_LEVEL_ERROR,
"main", std::string(msg.payload.data(), msg.payload.size()).c_str()));
170 case spdlog::level::critical:
171 sentry_capture_event(sentry_value_new_message_event(
172 SENTRY_LEVEL_FATAL,
"main", std::string(msg.payload.data(), msg.payload.size()).c_str()));
174 case spdlog::level::trace:
175 case spdlog::level::debug:
176 case spdlog::level::info:
177 case spdlog::level::off:
std::vector< std::string > findFromFile(const std::string &filePath, const std::string &pattern, std::string &lastWord)
sentry_api_sink(const std::string &sentryAddress)
void sink_it_(const details::log_msg &msg) override