|
18 | 18 | #include <datadog/tracer.h> |
19 | 19 | #include <datadog/tracer_config.h> |
20 | 20 | #include <datadog/w3c_propagation.h> |
| 21 | +#include <dirent.h> |
| 22 | +#include <stdio.h> |
| 23 | +#include <sys/types.h> |
| 24 | +#include <unistd.h> |
21 | 25 |
|
22 | 26 | #include <chrono> |
23 | 27 | #include <ctime> |
@@ -1844,7 +1848,9 @@ TEST_TRACER("APM tracing disabled") { |
1844 | 1848 | auto finalized_config = finalize_config(config, clock); |
1845 | 1849 | REQUIRE(finalized_config); |
1846 | 1850 | Tracer tracer{*finalized_config}; |
1847 | | - { auto root1 = tracer.create_span(); } |
| 1851 | + { |
| 1852 | + auto root1 = tracer.create_span(); |
| 1853 | + } |
1848 | 1854 | REQUIRE(collector->chunks.size() == 1); |
1849 | 1855 | REQUIRE(collector->chunks.front().size() == 1); |
1850 | 1856 |
|
@@ -1923,7 +1929,9 @@ TEST_TRACER("APM tracing disabled") { |
1923 | 1929 |
|
1924 | 1930 | // When APM Tracing is disabled, we allow one trace per second for service |
1925 | 1931 | // liveness. To ensure consistency, consume the limiter slot. |
1926 | | - { tracer.create_span(); } |
| 1932 | + { |
| 1933 | + tracer.create_span(); |
| 1934 | + } |
1927 | 1935 | collector->chunks.clear(); |
1928 | 1936 |
|
1929 | 1937 | // Case 1: extracted context with priority, but no `_dd.p.ts` → depends if |
@@ -2034,3 +2042,48 @@ TEST_TRACER("APM tracing disabled") { |
2034 | 2042 | } |
2035 | 2043 | } |
2036 | 2044 | } |
| 2045 | + |
| 2046 | +#if defined(__linux__) || defined(__unix__) |
| 2047 | +TEST_TRACER("process discovery") { |
| 2048 | + auto find_memfd = []() -> std::optional<std::string> { |
| 2049 | + DIR* dir = opendir("/proc/self/fd"); |
| 2050 | + if (dir == nullptr) return nullopt; |
| 2051 | + |
| 2052 | + char path[PATH_MAX]; |
| 2053 | + char target[PATH_MAX]; |
| 2054 | + |
| 2055 | + for (struct dirent* entry = readdir(dir); entry != nullptr; |
| 2056 | + entry = readdir(dir)) { |
| 2057 | + if (entry->d_type != DT_LNK) continue; |
| 2058 | + |
| 2059 | + snprintf(path, sizeof(path), "/proc/self/fd/%s", entry->d_name); |
| 2060 | + auto len = readlink(path, target, sizeof(target) - 1); |
| 2061 | + if (len == -1) continue; |
| 2062 | + target[len] = '\0'; |
| 2063 | + |
| 2064 | + if (starts_with(target, "/memfd:datadog-tracer-info-")) { |
| 2065 | + closedir(dir); |
| 2066 | + return path; |
| 2067 | + } |
| 2068 | + } |
| 2069 | + |
| 2070 | + return nullopt; |
| 2071 | + }; |
| 2072 | + |
| 2073 | + TracerConfig cfg; |
| 2074 | + auto finalized_config = finalize_config(cfg); |
| 2075 | + REQUIRE(finalized_config); |
| 2076 | + |
| 2077 | + { |
| 2078 | + Tracer tracer{*finalized_config}; |
| 2079 | + |
| 2080 | + auto fd = find_memfd(); |
| 2081 | + CHECK(fd); |
| 2082 | + |
| 2083 | + // TODO: Read content |
| 2084 | + } |
| 2085 | + |
| 2086 | + auto fd = find_memfd(); |
| 2087 | + CHECK(!fd); |
| 2088 | +} |
| 2089 | +#endif |
0 commit comments