Skip to content

Commit 43f214a

Browse files
Add temporary logging to stdout and stderr for the container-id parsing
1 parent 136d4cc commit 43f214a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/datadog/platform_util.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <cassert>
44
#include <cstdint>
55
#include <fstream>
6+
#include <iostream>
67
#include <regex>
78

89
// clang-format off
@@ -342,7 +343,10 @@ Optional<Cgroup> get_cgroup_version() {
342343

343344
Optional<std::string> find_container_id_from_cgroup() {
344345
auto cgroup_fd = std::ifstream("/proc/self/cgroup", std::ios::in);
345-
if (!cgroup_fd.is_open()) return nullopt;
346+
if (!cgroup_fd.is_open()) {
347+
std::cerr << "failed to open /proc/self/cgroup" << std::endl;
348+
return nullopt;
349+
}
346350

347351
return find_container_id(cgroup_fd);
348352
}
@@ -361,17 +365,20 @@ Optional<std::string> find_container_id(std::istream& source) {
361365

362366
std::string line;
363367
while (std::getline(source, line)) {
368+
std::cout << "Reading line: " << line << std::endl;
364369
// Example:
365370
// `0::/system.slice/docker-abcdef0123456789abcdef0123456789.scope`
366371
std::smatch match;
367372
if (std::regex_match(line, match, path_reg)) {
368373
assert(match.ready());
369374
assert(match.size() == 2);
370375

376+
std::cout << "Found container ID: " << match.str(1) << std::endl;
371377
return match.str(1);
372378
}
373379
}
374380

381+
std::cout << "No container ID found" << std::endl;
375382
return nullopt;
376383
}
377384

0 commit comments

Comments
 (0)