44#include < cstdint>
55#include < fstream>
66#include < iostream>
7- #include < memory>
87#include < regex>
98
109// clang-format off
4645#endif
4746// clang-format on
4847
49- #include < datadog/logger.h>
50-
5148namespace datadog {
5249namespace tracing {
5350namespace {
@@ -295,18 +292,10 @@ Expected<InMemoryFile> InMemoryFile::make(StringView) {
295292namespace container {
296293namespace {
297294#if defined(__linux__) || defined(__unix__)
298- // / Magic numbers from linux/magic.h:
299- // / <https://github.com/torvalds/linux/blob/ca91b9500108d4cf083a635c2e11c884d5dd20ea/include/uapi/linux/magic.h#L71>
300- // constexpr uint64_t CGROUP_SUPER_MAGIC = 0x27e0eb;
301- // constexpr uint64_t CGROUP2_SUPER_MAGIC = 0x63677270;
302-
303295// / Magic number from linux/proc_ns.h:
304296// / <https://github.com/torvalds/linux/blob/5859a2b1991101d6b978f3feb5325dad39421f29/include/linux/proc_ns.h#L41-L49>
305297constexpr ino_t HOST_CGROUP_NAMESPACE_INODE = 0xeffffffb ;
306298
307- // / Represents the cgroup version of the current process.
308- // enum class Cgroup : char { v1, v2 };
309-
310299Optional<ino_t > get_inode (std::string_view path) {
311300 struct stat buf;
312301 if (stat (path.data (), &buf) != 0 ) {
@@ -329,21 +318,18 @@ bool is_running_in_host_namespace() {
329318 return false ;
330319}
331320
332- Optional<std::string> find_container_id_from_cgroup (
333- const std::shared_ptr<tracing::Logger>& logger) {
321+ Optional<std::string> find_container_id_from_cgroup () {
334322 auto cgroup_fd = std::ifstream (" /proc/self/cgroup" , std::ios::in);
335323 if (!cgroup_fd.is_open ()) {
336- logger->log_error (" failed to open /proc/self/cgroup" );
337324 return nullopt ;
338325 }
339326
340- return find_container_id (cgroup_fd, logger );
327+ return find_container_id (cgroup_fd);
341328}
342329#endif
343330} // namespace
344331
345- Optional<std::string> find_container_id (std::istream& source,
346- const std::shared_ptr<tracing::Logger>& logger) {
332+ Optional<std::string> find_container_id (std::istream& source) {
347333 static const std::string uuid_regex_str =
348334 " [0-9a-f]{8}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{4}[-_][0-9a-f]{12}"
349335 " |(?:[0-9a-f]{8}(?:-[0-9a-f]{4}){4}$)" ;
@@ -355,28 +341,25 @@ Optional<std::string> find_container_id(std::istream& source,
355341
356342 std::string line;
357343 while (std::getline (source, line)) {
358- logger->log_error (" Reading line: " + line);
359344 // Example:
360345 // `0::/system.slice/docker-abcdef0123456789abcdef0123456789.scope`
361346 std::smatch match;
362347 if (std::regex_match (line, match, path_reg)) {
363348 assert (match.ready ());
364349 assert (match.size () == 2 );
365350
366- logger->log_error (" Found container ID: " + match.str (1 ));
367351 return match.str (1 );
368352 }
369353 }
370354
371- logger->log_error (" No container ID found" );
372355 return nullopt ;
373356}
374357
375- Optional<ContainerID> get_id (const std::shared_ptr<tracing::Logger>& logger ) {
358+ Optional<ContainerID> get_id () {
376359#if defined(__linux__) || defined(__unix__)
377360 // Determine the container ID or inode
378361 ContainerID id;
379- if (auto maybe_id = find_container_id_from_cgroup (logger )) {
362+ if (auto maybe_id = find_container_id_from_cgroup ()) {
380363 id.value = *maybe_id;
381364 id.type = ContainerID::Type::container_id;
382365 } else if (!is_running_in_host_namespace ()) {
0 commit comments