From 43f3d9c5c409a106fa9722a17d570306a72fa2c0 Mon Sep 17 00:00:00 2001 From: Benjamin De Bernardi Date: Mon, 5 Jan 2026 14:37:25 +0100 Subject: [PATCH 1/4] feat: add manual_keep and manual_drop endpoints for parametric test --- test/system-tests/main.cpp | 8 +++++ test/system-tests/request_handler.cpp | 52 ++++++++++++++++++++++++--- test/system-tests/request_handler.h | 2 ++ 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/test/system-tests/main.cpp b/test/system-tests/main.cpp index 59bb2e08..c7d5a007 100644 --- a/test/system-tests/main.cpp +++ b/test/system-tests/main.cpp @@ -120,6 +120,14 @@ int main(int argc, char* argv[]) { [&handler](const httplib::Request& req, httplib::Response& res) { handler.on_stats_flush(req, res); }); + svr.Post("/trace/span/manual_drop", + [&handler](const httplib::Request& req, httplib::Response& res) { + handler.on_set_metric(req, res); + }); + svr.Post("/trace/span/manual_keep", + [&handler](const httplib::Request& req, httplib::Response& res) { + handler.on_set_metric(req, res); + }); // Not implemented svr.Post("/trace/span/set_metric", diff --git a/test/system-tests/request_handler.cpp b/test/system-tests/request_handler.cpp index 3a161184..1413a7b3 100644 --- a/test/system-tests/request_handler.cpp +++ b/test/system-tests/request_handler.cpp @@ -216,19 +216,19 @@ void RequestHandler::on_set_meta(const httplib::Request& req, res.status = 200; } -void RequestHandler::on_set_metric(const httplib::Request& /* req */, +void RequestHandler::on_set_metric(const httplib::Request& req, httplib::Response& res) { - const auto request_json = nlohmann::json::parse(res.body); + const auto request_json = nlohmann::json::parse(req.body); auto span_id = utils::get_if_exists(request_json, "span_id"); if (!span_id) { - VALIDATION_ERROR(res, "on_set_meta: missing `span_id` field."); + VALIDATION_ERROR(res, "on_set_metric: missing `span_id` field."); } auto span_it = active_spans_.find(*span_id); if (span_it == active_spans_.cend()) { const auto msg = - "on_set_meta: span not found for id " + std::to_string(*span_id); + "on_set_metric: span not found for id " + std::to_string(*span_id); VALIDATION_ERROR(res, msg); } @@ -239,6 +239,50 @@ void RequestHandler::on_set_metric(const httplib::Request& /* req */, res.status = 200; } +void RequestHandler::on_manual_keep(const httplib::Request& req, + httplib::Response& res) { + const auto request_json = nlohmann::json::parse(req.body); + + auto span_id = utils::get_if_exists(request_json, "span_id"); + if (!span_id) { + VALIDATION_ERROR(res, "on_manual_keep: missing `span_id` field."); + } + + auto span_it = active_spans_.find(*span_id); + if (span_it == active_spans_.cend()) { + const auto msg = + "on_manual_keep: span not found for id " + std::to_string(*span_id); + VALIDATION_ERROR(res, msg); + } + + auto& span = span_it->second; + span.trace_segment().override_sampling_priority(datadog::tracing::SamplingPriority::USER_KEEP); + + res.status = 200; +} + +void RequestHandler::on_manual_drop(const httplib::Request& req, + httplib::Response& res) { + const auto request_json = nlohmann::json::parse(req.body); + + auto span_id = utils::get_if_exists(request_json, "span_id"); + if (!span_id) { + VALIDATION_ERROR(res, "on_manual_drop: missing `span_id` field."); + } + + auto span_it = active_spans_.find(*span_id); + if (span_it == active_spans_.cend()) { + const auto msg = + "on_manual_drop: span not found for id " + std::to_string(*span_id); + VALIDATION_ERROR(res, msg); + } + + auto& span = span_it->second; + span.trace_segment().override_sampling_priority(datadog::tracing::SamplingPriority::USER_DROP); + + res.status = 200; +} + void RequestHandler::on_inject_headers(const httplib::Request& req, httplib::Response& res) { const auto request_json = nlohmann::json::parse(req.body); diff --git a/test/system-tests/request_handler.h b/test/system-tests/request_handler.h index bda9cb37..09baf975 100644 --- a/test/system-tests/request_handler.h +++ b/test/system-tests/request_handler.h @@ -25,6 +25,8 @@ class RequestHandler final { void on_span_end(const httplib::Request& req, httplib::Response& res); void on_set_meta(const httplib::Request& req, httplib::Response& res); void on_set_metric(const httplib::Request& /* req */, httplib::Response& res); + void on_manual_keep(const httplib::Request& req, httplib::Response& res); + void on_manual_drop(const httplib::Request& req, httplib::Response& res); void on_inject_headers(const httplib::Request& req, httplib::Response& res); void on_extract_headers(const httplib::Request& req, httplib::Response& res); void on_span_flush(const httplib::Request& /* req */, httplib::Response& res); From 4b22cbba03a55d8aa04aebc1a00f8300769707ed Mon Sep 17 00:00:00 2001 From: Benjamin De Bernardi Date: Mon, 5 Jan 2026 15:15:55 +0100 Subject: [PATCH 2/4] chore: fmt --- test/system-tests/main.cpp | 12 ++++++------ test/system-tests/request_handler.cpp | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/test/system-tests/main.cpp b/test/system-tests/main.cpp index c7d5a007..de7d421e 100644 --- a/test/system-tests/main.cpp +++ b/test/system-tests/main.cpp @@ -121,13 +121,13 @@ int main(int argc, char* argv[]) { handler.on_stats_flush(req, res); }); svr.Post("/trace/span/manual_drop", - [&handler](const httplib::Request& req, httplib::Response& res) { - handler.on_set_metric(req, res); - }); + [&handler](const httplib::Request& req, httplib::Response& res) { + handler.on_manual_drop(req, res); + }); svr.Post("/trace/span/manual_keep", - [&handler](const httplib::Request& req, httplib::Response& res) { - handler.on_set_metric(req, res); - }); + [&handler](const httplib::Request& req, httplib::Response& res) { + handler.on_manual_keep(req, res); + }); // Not implemented svr.Post("/trace/span/set_metric", diff --git a/test/system-tests/request_handler.cpp b/test/system-tests/request_handler.cpp index 1413a7b3..71c84bcd 100644 --- a/test/system-tests/request_handler.cpp +++ b/test/system-tests/request_handler.cpp @@ -227,8 +227,8 @@ void RequestHandler::on_set_metric(const httplib::Request& req, auto span_it = active_spans_.find(*span_id); if (span_it == active_spans_.cend()) { - const auto msg = - "on_set_metric: span not found for id " + std::to_string(*span_id); + const auto msg = "on_set_metric: span not found for id " + + std::to_string(*span_id); VALIDATION_ERROR(res, msg); } @@ -250,19 +250,20 @@ void RequestHandler::on_manual_keep(const httplib::Request& req, auto span_it = active_spans_.find(*span_id); if (span_it == active_spans_.cend()) { - const auto msg = - "on_manual_keep: span not found for id " + std::to_string(*span_id); + const auto msg = "on_manual_keep: span not found for id " + + std::to_string(*span_id); VALIDATION_ERROR(res, msg); } auto& span = span_it->second; - span.trace_segment().override_sampling_priority(datadog::tracing::SamplingPriority::USER_KEEP); + span.trace_segment().override_sampling_priority( + datadog::tracing::SamplingPriority::USER_KEEP); res.status = 200; } void RequestHandler::on_manual_drop(const httplib::Request& req, - httplib::Response& res) { + httplib::Response& res) { const auto request_json = nlohmann::json::parse(req.body); auto span_id = utils::get_if_exists(request_json, "span_id"); @@ -272,13 +273,14 @@ void RequestHandler::on_manual_drop(const httplib::Request& req, auto span_it = active_spans_.find(*span_id); if (span_it == active_spans_.cend()) { - const auto msg = - "on_manual_drop: span not found for id " + std::to_string(*span_id); + const auto msg = "on_manual_drop: span not found for id " + + std::to_string(*span_id); VALIDATION_ERROR(res, msg); } auto& span = span_it->second; - span.trace_segment().override_sampling_priority(datadog::tracing::SamplingPriority::USER_DROP); + span.trace_segment().override_sampling_priority( + datadog::tracing::SamplingPriority::USER_DROP); res.status = 200; } From 08d2fd11eba2546a491982412111503708caf2c9 Mon Sep 17 00:00:00 2001 From: Benjamin De Bernardi Date: Mon, 5 Jan 2026 15:25:19 +0100 Subject: [PATCH 3/4] chore: fmt 2 --- test/system-tests/request_handler.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/system-tests/request_handler.cpp b/test/system-tests/request_handler.cpp index 71c84bcd..67a4fa11 100644 --- a/test/system-tests/request_handler.cpp +++ b/test/system-tests/request_handler.cpp @@ -227,8 +227,8 @@ void RequestHandler::on_set_metric(const httplib::Request& req, auto span_it = active_spans_.find(*span_id); if (span_it == active_spans_.cend()) { - const auto msg = "on_set_metric: span not found for id " + - std::to_string(*span_id); + const auto msg = + "on_set_metric: span not found for id " + std::to_string(*span_id); VALIDATION_ERROR(res, msg); } @@ -250,8 +250,8 @@ void RequestHandler::on_manual_keep(const httplib::Request& req, auto span_it = active_spans_.find(*span_id); if (span_it == active_spans_.cend()) { - const auto msg = "on_manual_keep: span not found for id " + - std::to_string(*span_id); + const auto msg = + "on_manual_keep: span not found for id " + std::to_string(*span_id); VALIDATION_ERROR(res, msg); } @@ -273,8 +273,8 @@ void RequestHandler::on_manual_drop(const httplib::Request& req, auto span_it = active_spans_.find(*span_id); if (span_it == active_spans_.cend()) { - const auto msg = "on_manual_drop: span not found for id " + - std::to_string(*span_id); + const auto msg = + "on_manual_drop: span not found for id " + std::to_string(*span_id); VALIDATION_ERROR(res, msg); } From 390f925d735727c42d688a58e9d5c2e094668427 Mon Sep 17 00:00:00 2001 From: Benjamin De Bernardi Date: Mon, 5 Jan 2026 19:27:00 +0100 Subject: [PATCH 4/4] fix: missing includes --- test/system-tests/request_handler.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/system-tests/request_handler.cpp b/test/system-tests/request_handler.cpp index 67a4fa11..0e318c38 100644 --- a/test/system-tests/request_handler.cpp +++ b/test/system-tests/request_handler.cpp @@ -1,7 +1,9 @@ #include "request_handler.h" #include +#include #include +#include #include #include