@@ -114,10 +114,16 @@ void RequestHandler::on_span_start(const httplib::Request& req,
114114 auto span = parent_span_it->second .create_child (span_cfg);
115115 success (span, res);
116116 active_spans_.emplace (span.id (), std::move (span));
117- } else if (parent_header_it == http_headers_.cend ()) {
118- auto span = tracer_.extract_span (utils::HeaderReader (*parent_header_it), span_cfg);
119- success (span, res);
120- active_spans_.emplace (span.id (), std::move (span));
117+ } else if (parent_header_it != http_headers_.cend ()) {
118+ auto span = tracer_.extract_span (utils::HeaderReader (parent_header_it->second ), span_cfg);
119+ if (span) {
120+ success (*span, res);
121+ active_spans_.emplace (span->id (), std::move (*span));
122+ } else {
123+ const auto msg = " on_span_start: unable to create span from http_headers identified by parent_id " +
124+ std::to_string (*parent_id);
125+ VALIDATION_ERROR (res, msg);
126+ }
121127 } else {
122128 const auto msg = " on_span_start: span or http_headers not found for id " +
123129 std::to_string (*parent_id);
@@ -240,12 +246,14 @@ void RequestHandler::on_extract_headers(const httplib::Request& req,
240246 VALIDATION_ERROR (res, error->with_prefix (" on_extract_headers: " ).message );
241247 }
242248
249+ // clang-format off
243250 const auto response_body = nlohmann::json{
244- {" span_id" , span->parent_id ()},
251+ {" span_id" , span->parent_id (). value () },
245252 };
253+ // clang-format on
246254
247255 res.set_content (response_body.dump (), " application/json" );
248- http_headers_.emplace (span->parent_id (), std::move (*http_headers));
256+ http_headers_.emplace (span->parent_id (). value () , std::move (*http_headers));
249257}
250258
251259void RequestHandler::on_span_flush (const httplib::Request& /* req */ ,
0 commit comments