Constructs a Sentry API sink with the specified Sentry server address.
23 {
24 if (sentryAddress.empty())
25 {
26 return;
27 }
29
30
31 sentry_options_t *sentryOptions = sentry_options_new();
32 sentry_options_set_release(sentryOptions, PROJECT_FULL_REVISION);
33 sentry_options_set_dsn(sentryOptions, sentryAddress.c_str());
34
35
36 sentry_init(sentryOptions);
37
38
39 sentry_set_tag("compiler.name", COMPILER_NAME);
40 sentry_set_tag("compiler.version", COMPILER_VERSION);
41 sentry_set_tag("build", BUILD_TYPE);
42
43
44 std::string versionBuffer;
45 const sentry_value_t versionContext = sentry_value_new_object();
46 versionBuffer = "v" + std::string(PROJECT_FULL_REVISION);
47 sentry_value_set_by_key(versionContext, PROJECT_NAME, sentry_value_new_string(versionBuffer.c_str()));
48 versionBuffer = std::string(PROJECT_BUILD_DATE) + " " + PROJECT_BUILD_TIME;
49 sentry_value_set_by_key(versionContext, "Release Date", sentry_value_new_string(versionBuffer.c_str()));
50
51
52
53
54
55
56
57
58 sentry_set_context("Version", versionContext);
59
60
61 std::array<char, BUFSIZ> hostBuffer{};
62 gethostname(hostBuffer.data(), BUFSIZ);
63 const sentry_value_t hostContext = sentry_value_new_object();
64 sentry_value_set_by_key(hostContext, "Hostname", sentry_value_new_string(hostBuffer.data()));
65
66
67 const std::string cpuInfoPath = "/proc/cpuinfo";
68 std::string word;
69
71 sentry_value_set_by_key(hostContext, "Thread count", sentry_value_new_string(word.c_str()));
73 sentry_value_set_by_key(hostContext, "Core count", sentry_value_new_string(word.c_str()));
75 sentry_value_set_by_key(hostContext, "Model", sentry_value_new_string(word.c_str()));
77 sentry_value_set_by_key(hostContext, "Vendor ID", sentry_value_new_string(word.c_str()));
78
79 sentry_set_context("Host", hostContext);
80
81
82 const sentry_value_t networkContext = sentry_value_new_object();
83
84 if (ifaddrs *ifaddr = nullptr; getifaddrs(&ifaddr) != -1)
85 {
86
87 for (ifaddrs *ifa = ifaddr; ifa != nullptr; ifa = ifa->ifa_next)
88 {
89 if (ifa->ifa_addr == nullptr)
90 {
91 continue;
92 }
93
94 switch (ifa->ifa_addr->sa_family)
95 {
96 case AF_INET:
97 if (((ifa->ifa_flags & IFF_PROMISC) != 0) || ((ifa->ifa_flags & IFF_UP) != 0))
98 {
99 std::array<char, INET_ADDRSTRLEN> host{};
100 inet_ntop(AF_INET, &(reinterpret_cast<sockaddr_in *>(ifa->ifa_addr))->sin_addr, host.data(),
101 INET_ADDRSTRLEN);
102 sentry_value_set_by_key(networkContext, (std::string(ifa->ifa_name) + ".ipv4").c_str(),
103 sentry_value_new_string(host.data()));
104 }
105 break;
106 case AF_INET6:
107 if (((ifa->ifa_flags & IFF_PROMISC) != 0) || ((ifa->ifa_flags & IFF_UP) != 0))
108 {
109 std::array<char, INET6_ADDRSTRLEN> host{};
110 inet_ntop(AF_INET6, &(reinterpret_cast<sockaddr_in6 *>(ifa->ifa_addr))->sin6_addr, host.data(),
111 INET6_ADDRSTRLEN);
112 sentry_value_set_by_key(networkContext, (std::string(ifa->ifa_name) + ".ipv6").c_str(),
113 sentry_value_new_string(host.data()));
114 }
115 break;
116 case AF_PACKET:
117 if (((ifa->ifa_flags & IFF_PROMISC) != 0) || ((ifa->ifa_flags & IFF_UP) != 0))
118 {
119 std::array<char, MAC_LEN> host{};
120 const auto *sock = reinterpret_cast<sockaddr_ll *>(ifa->ifa_addr);
121 if (snprintf(host.data(),
MAC_LEN,
"%02x:%02x:%02x:%02x:%02x:%02x", sock->sll_addr[0],
122 sock->sll_addr[1], sock->sll_addr[2], sock->sll_addr[3], sock->sll_addr[4],
123 sock->sll_addr[5]) > 0)
124 {
125 sentry_value_set_by_key(networkContext, (std::string(ifa->ifa_name) + ".mac").c_str(),
126 sentry_value_new_string(host.data()));
127 }
128 }
129 break;
130 default:
131 break;
132 }
133 }
134 freeifaddrs(ifaddr);
135 }
136 sentry_set_context("Network", networkContext);
137 }
std::vector< std::string > findFromFile(const std::string &filePath, const std::string &pattern, std::string &lastWord)