From 4d10f7aef88d0e50cbede21fa7c8ef681c016252 Mon Sep 17 00:00:00 2001 From: Xavier Lamorlette Date: Fri, 24 Apr 2026 19:27:58 +0200 Subject: [PATCH 01/12] For system tests, get the agent URL from the tracer configuration instead of simply checking the environment variable --- test/system-tests/request_handler.cpp | 36 +++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/test/system-tests/request_handler.cpp b/test/system-tests/request_handler.cpp index 0e318c388..3104bf881 100644 --- a/test/system-tests/request_handler.cpp +++ b/test/system-tests/request_handler.cpp @@ -12,6 +12,21 @@ #include "httplib.h" #include "utils.h" +namespace { + +std::string get_agent_url_from_traces_url(std::string traces_url) { + // Strip the API path from the traces URL to get the agent URL + constexpr std::string_view traces_api_path = "/v0.4/traces"; + if (traces_url.size() >= traces_api_path.size() && + traces_url.compare(traces_url.size() - traces_api_path.size(), + traces_api_path.size(), traces_api_path) == 0) { + traces_url.resize(traces_url.size() - traces_api_path.size()); + } + return traces_url; +} + +} // namespace + RequestHandler::RequestHandler( datadog::tracing::FinalizedTracerConfig& tracerConfig, std::shared_ptr scheduler, @@ -47,17 +62,18 @@ void RequestHandler::on_trace_config(const httplib::Request& /* req */, httplib::Response& res) { auto tracer_cfg = nlohmann::json::parse(tracer_.config()); + const std::string agent_url = get_agent_url_from_traces_url(tracer_cfg["collector"]["config"]["traces_url"]); + // clang-format off - auto response_body = nlohmann::json{ - { "config", { - { "dd_service", tracer_cfg["defaults"]["service"]}, - { "dd_env", tracer_cfg["defaults"]["environment"]}, - { "dd_version", tracer_cfg["environment_variables"]["version"]}, - { "dd_trace_enabled", tracer_cfg["environment_variables"]["report_traces"]}, - { "dd_trace_agent_url", tracer_cfg["environment_variables"]["DD_TRACE_AGENT_URL"]} - } - } - }; + auto response_body = nlohmann::json{ + {"config", { + {"dd_service", tracer_cfg["defaults"]["service"]}, + {"dd_env", tracer_cfg["defaults"]["environment"]}, + {"dd_version", tracer_cfg["environment_variables"]["version"]}, + {"dd_trace_enabled", tracer_cfg["environment_variables"]["report_traces"]}, + {"dd_trace_agent_url", agent_url} + }} + }; // clang-format on if (tracer_cfg.contains("trace_sampler")) { From 40225efb2e4c01ba02a1aadbfb9f19c7e7010969 Mon Sep 17 00:00:00 2001 From: Xavier Lamorlette Date: Fri, 5 Jun 2026 19:03:36 +0200 Subject: [PATCH 02/12] For system tests, get version from tracer configuration instead of environment variable --- test/system-tests/request_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system-tests/request_handler.cpp b/test/system-tests/request_handler.cpp index 3104bf881..58a39b513 100644 --- a/test/system-tests/request_handler.cpp +++ b/test/system-tests/request_handler.cpp @@ -69,7 +69,7 @@ void RequestHandler::on_trace_config(const httplib::Request& /* req */, {"config", { {"dd_service", tracer_cfg["defaults"]["service"]}, {"dd_env", tracer_cfg["defaults"]["environment"]}, - {"dd_version", tracer_cfg["environment_variables"]["version"]}, + {"dd_version", tracer_cfg["defaults"]["version"]}, {"dd_trace_enabled", tracer_cfg["environment_variables"]["report_traces"]}, {"dd_trace_agent_url", agent_url} }} From 4866bc43bac1ac0ddd46c16c8d10746d5dbdd39d Mon Sep 17 00:00:00 2001 From: Xavier Lamorlette Date: Fri, 5 Jun 2026 19:08:44 +0200 Subject: [PATCH 03/12] For system tests, get dd_trace_enabled from tracer configuration instead of environment variable --- test/system-tests/request_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system-tests/request_handler.cpp b/test/system-tests/request_handler.cpp index 58a39b513..973ab09ac 100644 --- a/test/system-tests/request_handler.cpp +++ b/test/system-tests/request_handler.cpp @@ -70,7 +70,7 @@ void RequestHandler::on_trace_config(const httplib::Request& /* req */, {"dd_service", tracer_cfg["defaults"]["service"]}, {"dd_env", tracer_cfg["defaults"]["environment"]}, {"dd_version", tracer_cfg["defaults"]["version"]}, - {"dd_trace_enabled", tracer_cfg["environment_variables"]["report_traces"]}, + {"dd_trace_enabled", tracer_cfg["report_traces"]}, {"dd_trace_agent_url", agent_url} }} }; From 1a8e8109c40b053137cd16758e2108b189d89b3f Mon Sep 17 00:00:00 2001 From: Xavier Lamorlette Date: Fri, 5 Jun 2026 19:19:19 +0200 Subject: [PATCH 04/12] nano code cleaning --- test/system-tests/request_handler.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/system-tests/request_handler.cpp b/test/system-tests/request_handler.cpp index 973ab09ac..df6055837 100644 --- a/test/system-tests/request_handler.cpp +++ b/test/system-tests/request_handler.cpp @@ -16,6 +16,7 @@ namespace { std::string get_agent_url_from_traces_url(std::string traces_url) { // Strip the API path from the traces URL to get the agent URL + // This API path is defined in src/datadog/datadog_agent.cpp. constexpr std::string_view traces_api_path = "/v0.4/traces"; if (traces_url.size() >= traces_api_path.size() && traces_url.compare(traces_url.size() - traces_api_path.size(), @@ -25,7 +26,7 @@ std::string get_agent_url_from_traces_url(std::string traces_url) { return traces_url; } -} // namespace +} // namespace RequestHandler::RequestHandler( datadog::tracing::FinalizedTracerConfig& tracerConfig, @@ -62,7 +63,8 @@ void RequestHandler::on_trace_config(const httplib::Request& /* req */, httplib::Response& res) { auto tracer_cfg = nlohmann::json::parse(tracer_.config()); - const std::string agent_url = get_agent_url_from_traces_url(tracer_cfg["collector"]["config"]["traces_url"]); + const std::string agent_url = get_agent_url_from_traces_url( + tracer_cfg["collector"]["config"]["traces_url"]); // clang-format off auto response_body = nlohmann::json{ From 449f83ba1b75c8d6c15f7f9a6a33f5fff71eb39e Mon Sep 17 00:00:00 2001 From: Xavier Lamorlette Date: Mon, 10 Aug 2026 15:00:33 +0200 Subject: [PATCH 05/12] typo --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e468810b6..828ab056d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,7 @@ Before submitting new features or changes to current functionality, please [open issue](https://github.com/DataDog/dd-trace-cpp/issues/new) and discuss your ideas or propose the changes you wish to make. After a resolution is reached, a PR can be submitted for review. -Sefer to the [documentation](docs) to learn about the architecture of the Datadog C++ Tracer Library +Refer to the [documentation](docs) to learn about the architecture of the Datadog C++ Tracer Library and its development processes. In particular, review: - [Conventions](docs/conventions.md); From a71bb14d3dd6d37aaa86753b59069dd7c040a572 Mon Sep 17 00:00:00 2001 From: Xavier Lamorlette Date: Tue, 11 Aug 2026 15:13:16 +0200 Subject: [PATCH 06/12] extract build_agent_url_from_environment_variables() from load_datadog_agent_env_config() --- include/datadog/datadog_agent_config.h | 6 ++-- src/datadog/datadog_agent_config.cpp | 43 ++++++++++++++++---------- test/test_tracer_config.cpp | 6 ++-- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/include/datadog/datadog_agent_config.h b/include/datadog/datadog_agent_config.h index e3deb5c40..1b179ecfc 100644 --- a/include/datadog/datadog_agent_config.h +++ b/include/datadog/datadog_agent_config.h @@ -23,8 +23,7 @@ #include "http_client.h" #include "remote_config/listener.h" -namespace datadog { -namespace tracing { +namespace datadog::tracing { class EventScheduler; class Logger; @@ -100,5 +99,4 @@ Expected finalize_config( const DatadogAgentConfig& config, const std::shared_ptr& logger, const Clock& clock); -} // namespace tracing -} // namespace datadog +} // namespace datadog::tracing diff --git a/src/datadog/datadog_agent_config.cpp b/src/datadog/datadog_agent_config.cpp index 20967db7e..76f8d4681 100644 --- a/src/datadog/datadog_agent_config.cpp +++ b/src/datadog/datadog_agent_config.cpp @@ -10,8 +10,29 @@ #include "platform_util.h" #include "threaded_event_scheduler.h" -namespace datadog { -namespace tracing { +namespace datadog::tracing { + +namespace { + +Optional build_agent_url_from_environmment_variables() { + if (Optional url_env = lookup(environment::DD_TRACE_AGENT_URL)) { + return std::string{*url_env}; + } + + Optional env_host = lookup(environment::DD_AGENT_HOST); + Optional env_port = lookup(environment::DD_TRACE_AGENT_PORT); + if (env_host || env_port) { + std::string agent_url = "http://"; + append(agent_url, env_host.value_or("localhost")); + agent_url += ':'; + append(agent_url, env_port.value_or("8126")); + return agent_url; + } + + return nullopt; +} + +} // namespace Expected load_datadog_agent_env_config() { DatadogAgentConfig env_config; @@ -31,18 +52,9 @@ Expected load_datadog_agent_env_config() { env_config.remote_configuration_poll_interval_seconds = *res; } - auto env_host = lookup(environment::DD_AGENT_HOST); - auto env_port = lookup(environment::DD_TRACE_AGENT_PORT); - - if (auto url_env = lookup(environment::DD_TRACE_AGENT_URL)) { - env_config.url = std::string{*url_env}; - } else if (env_host || env_port) { - std::string configured_url = "http://"; - append(configured_url, env_host.value_or("localhost")); - configured_url += ':'; - append(configured_url, env_port.value_or("8126")); - - env_config.url = std::move(configured_url); + if (Optional agent_url = + build_agent_url_from_environmment_variables()) { + env_config.url = *std::move(agent_url); } return env_config; @@ -158,5 +170,4 @@ Expected finalize_config( return result; } -} // namespace tracing -} // namespace datadog +} // namespace datadog::tracing diff --git a/test/test_tracer_config.cpp b/test/test_tracer_config.cpp index c313fb407..c3672338f 100644 --- a/test/test_tracer_config.cpp +++ b/test/test_tracer_config.cpp @@ -26,15 +26,13 @@ #include "null_logger.h" #include "test.h" -namespace datadog { -namespace tracing { +namespace datadog::tracing { std::ostream& operator<<(std::ostream& stream, PropagationStyle style) { return stream << to_string_view(style); } -} // namespace tracing -} // namespace datadog +} // namespace datadog::tracing using namespace datadog::test; using namespace datadog::tracing; From 1e6d6fabf82be158f6ceada3b42360f39d79b219 Mon Sep 17 00:00:00 2001 From: Xavier Lamorlette Date: Tue, 11 Aug 2026 15:38:08 +0200 Subject: [PATCH 07/12] add minimal CLAUDE.md file, redirecting to AGENTS.md --- CLAUDE.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 000000000..c3969d899 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +Follow [AGENTS.md](AGENTS.md). From 4f57ee90cc0710e03725a9f4898298454174dee2 Mon Sep 17 00:00:00 2001 From: Xavier Lamorlette Date: Tue, 11 Aug 2026 15:56:28 +0200 Subject: [PATCH 08/12] add unit test for agent IPv6 host handling --- test/test_tracer_config.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_tracer_config.cpp b/test/test_tracer_config.cpp index c3672338f..e820fcc37 100644 --- a/test/test_tracer_config.cpp +++ b/test/test_tracer_config.cpp @@ -506,6 +506,7 @@ TRACER_CONFIG_TEST("TracerConfig::agent") { "dd-agent:8080"}, {"override port with default host", nullopt, "8080", nullopt, "http", "localhost:8080"}, + {"IPv6 host", "::1", nullopt, nullopt, "http", "[::1]:8126"}, // A bogus port number will cause an error in the TCPClient, not // during configuration. For the purposes of configuration, any // value is accepted. From 7d694cd319eaf6a91540c87763b9865f36851754 Mon Sep 17 00:00:00 2001 From: Xavier Lamorlette Date: Tue, 11 Aug 2026 16:05:46 +0200 Subject: [PATCH 09/12] Add support to IPv6 addresses in DD_AGENT_HOST --- src/datadog/datadog_agent_config.cpp | 9 +++++++++ test/test_tracer_config.cpp | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/datadog/datadog_agent_config.cpp b/src/datadog/datadog_agent_config.cpp index 76f8d4681..f57f7e1ec 100644 --- a/src/datadog/datadog_agent_config.cpp +++ b/src/datadog/datadog_agent_config.cpp @@ -23,7 +23,16 @@ Optional build_agent_url_from_environmment_variables() { Optional env_port = lookup(environment::DD_TRACE_AGENT_PORT); if (env_host || env_port) { std::string agent_url = "http://"; + const StringView host = env_host.value_or("localhost"); + const bool is_ipv6_without_brackets = + (host.find(':') != StringView::npos) && (host.front() != '['); + if (is_ipv6_without_brackets) { + agent_url += '['; + } append(agent_url, env_host.value_or("localhost")); + if (is_ipv6_without_brackets) { + agent_url += ']'; + } agent_url += ':'; append(agent_url, env_port.value_or("8126")); return agent_url; diff --git a/test/test_tracer_config.cpp b/test/test_tracer_config.cpp index e820fcc37..c8290e346 100644 --- a/test/test_tracer_config.cpp +++ b/test/test_tracer_config.cpp @@ -507,6 +507,8 @@ TRACER_CONFIG_TEST("TracerConfig::agent") { {"override port with default host", nullopt, "8080", nullopt, "http", "localhost:8080"}, {"IPv6 host", "::1", nullopt, nullopt, "http", "[::1]:8126"}, + {"IPv6 host with brackets", "[::1]", nullopt, nullopt, "http", + "[::1]:8126"}, // A bogus port number will cause an error in the TCPClient, not // during configuration. For the purposes of configuration, any // value is accepted. From 486ca92a8eff07718b5d00584e437b81403f2fc1 Mon Sep 17 00:00:00 2001 From: Xavier Lamorlette Date: Tue, 11 Aug 2026 17:15:27 +0200 Subject: [PATCH 10/12] Add a unit test for handling IPv6 url for agent --- src/datadog/datadog_agent_config.cpp | 4 ++-- test/test_tracer_config.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/datadog/datadog_agent_config.cpp b/src/datadog/datadog_agent_config.cpp index f57f7e1ec..4797e2ffc 100644 --- a/src/datadog/datadog_agent_config.cpp +++ b/src/datadog/datadog_agent_config.cpp @@ -14,7 +14,7 @@ namespace datadog::tracing { namespace { -Optional build_agent_url_from_environmment_variables() { +Optional build_agent_url_from_environment_variables() { if (Optional url_env = lookup(environment::DD_TRACE_AGENT_URL)) { return std::string{*url_env}; } @@ -62,7 +62,7 @@ Expected load_datadog_agent_env_config() { } if (Optional agent_url = - build_agent_url_from_environmment_variables()) { + build_agent_url_from_environment_variables()) { env_config.url = *std::move(agent_url); } diff --git a/test/test_tracer_config.cpp b/test/test_tracer_config.cpp index c8290e346..ab5853176 100644 --- a/test/test_tracer_config.cpp +++ b/test/test_tracer_config.cpp @@ -460,6 +460,7 @@ TRACER_CONFIG_TEST("TracerConfig::agent") { {"http://dd-agent:8126", nullopt, "http", "dd-agent:8126", ""}, {"http://dd-agent:8126/", nullopt, "http", "dd-agent:8126", "/"}, {"https://dd-agent:8126/", nullopt, "https", "dd-agent:8126", "/"}, + {"http://[::1]:8126/", nullopt, "http", "[::1]:8126", "/"}, {"unix:///var/run/datadog/trace-agent.sock", nullopt, "unix", "/var/run/datadog/trace-agent.sock"}, {"unix://var/run/datadog/trace-agent.sock", From c97160a2db4af6f2810180e8c8d60314f7cbb161 Mon Sep 17 00:00:00 2001 From: Xavier Lamorlette Date: Tue, 11 Aug 2026 17:46:25 +0200 Subject: [PATCH 11/12] clean include lines --- include/datadog/datadog_agent_config.h | 4 ---- src/datadog/datadog_agent_config.cpp | 5 ----- test/test_tracer_config.cpp | 15 --------------- 3 files changed, 24 deletions(-) diff --git a/include/datadog/datadog_agent_config.h b/include/datadog/datadog_agent_config.h index 1b179ecfc..a6d1483c0 100644 --- a/include/datadog/datadog_agent_config.h +++ b/include/datadog/datadog_agent_config.h @@ -11,11 +11,7 @@ // Typical usage of `DatadogAgentConfig` is implicit as part of `TracerConfig`. // See `tracer_config.h`. -#include #include -#include -#include -#include #include "clock.h" #include "config.h" diff --git a/src/datadog/datadog_agent_config.cpp b/src/datadog/datadog_agent_config.cpp index 4797e2ffc..64737d9f0 100644 --- a/src/datadog/datadog_agent_config.cpp +++ b/src/datadog/datadog_agent_config.cpp @@ -1,13 +1,8 @@ #include #include -#include -#include -#include - #include "default_http_client.h" #include "parse_util.h" -#include "platform_util.h" #include "threaded_event_scheduler.h" namespace datadog::tracing { diff --git a/test/test_tracer_config.cpp b/test/test_tracer_config.cpp index ab5853176..259bb9e34 100644 --- a/test/test_tracer_config.cpp +++ b/test/test_tracer_config.cpp @@ -1,23 +1,8 @@ -#include -#include -#include #include #include -#include -#include -#include -#include -#include -#include #include #include -#include -#include -#include -#include -#include -#include #include "common/environment.h" #include "mocks/collectors.h" From 5ee5b06bc2ccf735106d1f1e6e3b42de6933c1be Mon Sep 17 00:00:00 2001 From: Xavier Lamorlette Date: Tue, 11 Aug 2026 18:12:35 +0200 Subject: [PATCH 12/12] tiny code cleaning --- src/datadog/datadog_agent_config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datadog/datadog_agent_config.cpp b/src/datadog/datadog_agent_config.cpp index 64737d9f0..52a80eb98 100644 --- a/src/datadog/datadog_agent_config.cpp +++ b/src/datadog/datadog_agent_config.cpp @@ -24,7 +24,7 @@ Optional build_agent_url_from_environment_variables() { if (is_ipv6_without_brackets) { agent_url += '['; } - append(agent_url, env_host.value_or("localhost")); + append(agent_url, host); if (is_ipv6_without_brackets) { agent_url += ']'; }