Skip to content

Commit 93ed055

Browse files
Get dd_trace_agent_url from Tracer configuration for meaningful System Tests (#325)
1 parent 5a576f7 commit 93ed055

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

test/system-tests/request_handler.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
#include "httplib.h"
1313
#include "utils.h"
1414

15+
namespace {
16+
17+
std::string get_agent_url_from_traces_url(std::string traces_url) {
18+
// Strip the API path from the traces URL to get the agent URL
19+
// This API path is defined in src/datadog/datadog_agent.cpp.
20+
constexpr std::string_view traces_api_path = "/v0.4/traces";
21+
if (traces_url.size() >= traces_api_path.size() &&
22+
traces_url.compare(traces_url.size() - traces_api_path.size(),
23+
traces_api_path.size(), traces_api_path) == 0) {
24+
traces_url.resize(traces_url.size() - traces_api_path.size());
25+
}
26+
return traces_url;
27+
}
28+
29+
} // namespace
30+
1531
RequestHandler::RequestHandler(
1632
datadog::tracing::FinalizedTracerConfig& tracerConfig,
1733
std::shared_ptr<ManualScheduler> scheduler,
@@ -47,17 +63,19 @@ void RequestHandler::on_trace_config(const httplib::Request& /* req */,
4763
httplib::Response& res) {
4864
auto tracer_cfg = nlohmann::json::parse(tracer_.config());
4965

66+
const std::string agent_url = get_agent_url_from_traces_url(
67+
tracer_cfg["collector"]["config"]["traces_url"]);
68+
5069
// clang-format off
51-
auto response_body = nlohmann::json{
52-
{ "config", {
53-
{ "dd_service", tracer_cfg["defaults"]["service"]},
54-
{ "dd_env", tracer_cfg["defaults"]["environment"]},
55-
{ "dd_version", tracer_cfg["environment_variables"]["version"]},
56-
{ "dd_trace_enabled", tracer_cfg["environment_variables"]["report_traces"]},
57-
{ "dd_trace_agent_url", tracer_cfg["environment_variables"]["DD_TRACE_AGENT_URL"]}
58-
}
59-
}
60-
};
70+
auto response_body = nlohmann::json{
71+
{"config", {
72+
{"dd_service", tracer_cfg["defaults"]["service"]},
73+
{"dd_env", tracer_cfg["defaults"]["environment"]},
74+
{"dd_version", tracer_cfg["defaults"]["version"]},
75+
{"dd_trace_enabled", tracer_cfg["report_traces"]},
76+
{"dd_trace_agent_url", agent_url}
77+
}}
78+
};
6179
// clang-format on
6280

6381
if (tracer_cfg.contains("trace_sampler")) {

0 commit comments

Comments
 (0)