|
12 | 12 | #include "httplib.h" |
13 | 13 | #include "utils.h" |
14 | 14 |
|
| 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 | + |
15 | 31 | RequestHandler::RequestHandler( |
16 | 32 | datadog::tracing::FinalizedTracerConfig& tracerConfig, |
17 | 33 | std::shared_ptr<ManualScheduler> scheduler, |
@@ -47,17 +63,19 @@ void RequestHandler::on_trace_config(const httplib::Request& /* req */, |
47 | 63 | httplib::Response& res) { |
48 | 64 | auto tracer_cfg = nlohmann::json::parse(tracer_.config()); |
49 | 65 |
|
| 66 | + const std::string agent_url = get_agent_url_from_traces_url( |
| 67 | + tracer_cfg["collector"]["config"]["traces_url"]); |
| 68 | + |
50 | 69 | // 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 | + }; |
61 | 79 | // clang-format on |
62 | 80 |
|
63 | 81 | if (tracer_cfg.contains("trace_sampler")) { |
|
0 commit comments