@@ -221,35 +221,30 @@ void RequestHandler::on_inject_headers(const httplib::Request& req,
221221 res.set_content (response_json.dump (), " application/json" );
222222}
223223
224-
225224void RequestHandler::on_extract_headers (const httplib::Request& req,
226- httplib::Response& res) {
225+ httplib::Response& res) {
227226 const auto request_json = nlohmann::json::parse (req.body );
228- auto http_headers = utils::get_if_exists<nlohmann::json::array_t >(request_json, " http_headers" );
227+ auto http_headers = utils::get_if_exists<nlohmann::json::array_t >(
228+ request_json, " http_headers" );
229229 if (!http_headers) {
230230 VALIDATION_ERROR (res, " on_extract_headers: missing `http_headers` field." );
231231 }
232232
233233 datadog::tracing::SpanConfig span_cfg;
234- auto span = tracer_.extract_span (
235- utils::HeaderReader (*http_headers), span_cfg);
236-
237- auto success = [](const datadog::tracing::Span& span,
238- httplib::Response& res) {
239- // clang-format off
240- const auto response_body = nlohmann::json{
241- { " span_id" , span.id () }
242- };
243- // clang-format on
234+ auto span =
235+ tracer_.extract_span (utils::HeaderReader (*http_headers), span_cfg);
236+ if (auto error = span.if_error ()) {
237+ VALIDATION_ERROR (res, error->with_prefix (" on_extract_headers: " ).message );
238+ }
244239
245- res.set_content (response_body.dump (), " application/json" );
240+ const auto response_body = nlohmann::json{
241+ {" span_id" , span->id ()},
246242 };
247243
248- success (span, res );
249- spans_.emplace (span. id (), std::move (span));
244+ res. set_content (response_body. dump (), " application/json " );
245+ spans_.emplace (span-> id (), std::move (* span));
250246}
251247
252-
253248void RequestHandler::on_span_flush (const httplib::Request& /* req */ ,
254249 httplib::Response& res) {
255250 scheduler_->flush_telemetry ();
0 commit comments