11#include " request_handler.h"
22
33#include < datadog/optional.h>
4+ #include < datadog/sampling_priority.h>
45#include < datadog/span_config.h>
6+ #include < datadog/trace_segment.h>
57#include < datadog/tracer.h>
68#include < datadog/tracer_config.h>
79
@@ -216,19 +218,19 @@ void RequestHandler::on_set_meta(const httplib::Request& req,
216218 res.status = 200 ;
217219}
218220
219- void RequestHandler::on_set_metric (const httplib::Request& /* req */ ,
221+ void RequestHandler::on_set_metric (const httplib::Request& req,
220222 httplib::Response& res) {
221- const auto request_json = nlohmann::json::parse (res .body );
223+ const auto request_json = nlohmann::json::parse (req .body );
222224
223225 auto span_id = utils::get_if_exists<uint64_t >(request_json, " span_id" );
224226 if (!span_id) {
225- VALIDATION_ERROR (res, " on_set_meta : missing `span_id` field." );
227+ VALIDATION_ERROR (res, " on_set_metric : missing `span_id` field." );
226228 }
227229
228230 auto span_it = active_spans_.find (*span_id);
229231 if (span_it == active_spans_.cend ()) {
230232 const auto msg =
231- " on_set_meta : span not found for id " + std::to_string (*span_id);
233+ " on_set_metric : span not found for id " + std::to_string (*span_id);
232234 VALIDATION_ERROR (res, msg);
233235 }
234236
@@ -239,6 +241,52 @@ void RequestHandler::on_set_metric(const httplib::Request& /* req */,
239241 res.status = 200 ;
240242}
241243
244+ void RequestHandler::on_manual_keep (const httplib::Request& req,
245+ httplib::Response& res) {
246+ const auto request_json = nlohmann::json::parse (req.body );
247+
248+ auto span_id = utils::get_if_exists<uint64_t >(request_json, " span_id" );
249+ if (!span_id) {
250+ VALIDATION_ERROR (res, " on_manual_keep: missing `span_id` field." );
251+ }
252+
253+ auto span_it = active_spans_.find (*span_id);
254+ if (span_it == active_spans_.cend ()) {
255+ const auto msg =
256+ " on_manual_keep: span not found for id " + std::to_string (*span_id);
257+ VALIDATION_ERROR (res, msg);
258+ }
259+
260+ auto & span = span_it->second ;
261+ span.trace_segment ().override_sampling_priority (
262+ datadog::tracing::SamplingPriority::USER_KEEP );
263+
264+ res.status = 200 ;
265+ }
266+
267+ void RequestHandler::on_manual_drop (const httplib::Request& req,
268+ httplib::Response& res) {
269+ const auto request_json = nlohmann::json::parse (req.body );
270+
271+ auto span_id = utils::get_if_exists<uint64_t >(request_json, " span_id" );
272+ if (!span_id) {
273+ VALIDATION_ERROR (res, " on_manual_drop: missing `span_id` field." );
274+ }
275+
276+ auto span_it = active_spans_.find (*span_id);
277+ if (span_it == active_spans_.cend ()) {
278+ const auto msg =
279+ " on_manual_drop: span not found for id " + std::to_string (*span_id);
280+ VALIDATION_ERROR (res, msg);
281+ }
282+
283+ auto & span = span_it->second ;
284+ span.trace_segment ().override_sampling_priority (
285+ datadog::tracing::SamplingPriority::USER_DROP );
286+
287+ res.status = 200 ;
288+ }
289+
242290void RequestHandler::on_inject_headers (const httplib::Request& req,
243291 httplib::Response& res) {
244292 const auto request_json = nlohmann::json::parse (req.body );
0 commit comments