@@ -106,16 +106,16 @@ void RequestHandler::on_span_start(const httplib::Request& req,
106106
107107 if (auto parent_id =
108108 utils::get_if_exists<uint64_t >(request_json, " parent_id" )) {
109- auto parent_span_it = spans_ .find (*parent_id);
109+ auto parent_span_it = active_spans_ .find (*parent_id);
110110 auto parent_header_it = http_headers_.find (*parent_id);
111- if (parent_span_it != spans_ .cend ()) {
111+ if (parent_span_it != active_spans_ .cend ()) {
112112 auto span = parent_span_it->second .create_child (span_cfg);
113113 success (span, res);
114- spans_ .emplace (span.id (), std::move (span));
114+ active_spans_ .emplace (span.id (), std::move (span));
115115 } else if (parent_header_it == http_headers_.cend ()) {
116116 auto span = tracer_.extract_span (utils::HeaderReader (*parent_header_it), span_cfg);
117117 success (span, res);
118- spans_ .emplace (span.id (), std::move (span));
118+ active_spans_ .emplace (span.id (), std::move (span));
119119 } else {
120120 const auto msg = " on_span_start: span or http_headers not found for id " +
121121 std::to_string (*parent_id);
@@ -124,7 +124,7 @@ void RequestHandler::on_span_start(const httplib::Request& req,
124124 } else {
125125 auto span = tracer_.create_span (span_cfg);
126126 success (span, res);
127- spans_ .emplace (span.id (), std::move (span));
127+ active_spans_ .emplace (span.id (), std::move (span));
128128 }
129129}
130130
@@ -137,8 +137,8 @@ void RequestHandler::on_span_end(const httplib::Request& req,
137137 VALIDATION_ERROR (res, " on_span_end: missing `span_id` field." );
138138 }
139139
140- auto span_it = spans_ .find (*span_id);
141- if (span_it == spans_ .cend ()) {
140+ auto span_it = active_spans_ .find (*span_id);
141+ if (span_it == active_spans_ .cend ()) {
142142 const auto msg =
143143 " on_span_end: span not found for id " + std::to_string (*span_id);
144144 VALIDATION_ERROR (res, msg);
@@ -156,8 +156,8 @@ void RequestHandler::on_set_meta(const httplib::Request& req,
156156 VALIDATION_ERROR (res, " on_set_meta: missing `span_id` field." );
157157 }
158158
159- auto span_it = spans_ .find (*span_id);
160- if (span_it == spans_ .cend ()) {
159+ auto span_it = active_spans_ .find (*span_id);
160+ if (span_it == active_spans_ .cend ()) {
161161 const auto msg =
162162 " on_set_meta: span not found for id " + std::to_string (*span_id);
163163 VALIDATION_ERROR (res, msg);
@@ -179,8 +179,8 @@ void RequestHandler::on_set_metric(const httplib::Request& /* req */,
179179 VALIDATION_ERROR (res, " on_set_meta: missing `span_id` field." );
180180 }
181181
182- auto span_it = spans_ .find (*span_id);
183- if (span_it == spans_ .cend ()) {
182+ auto span_it = active_spans_ .find (*span_id);
183+ if (span_it == active_spans_ .cend ()) {
184184 const auto msg =
185185 " on_set_meta: span not found for id " + std::to_string (*span_id);
186186 VALIDATION_ERROR (res, msg);
@@ -202,8 +202,8 @@ void RequestHandler::on_inject_headers(const httplib::Request& req,
202202 VALIDATION_ERROR (res, " on_inject_headers: missing `span_id` field." );
203203 }
204204
205- auto span_it = spans_ .find (*span_id);
206- if (span_it == spans_ .cend ()) {
205+ auto span_it = active_spans_ .find (*span_id);
206+ if (span_it == active_spans_ .cend ()) {
207207 const auto msg =
208208 " on_inject_headers: span not found for id " + std::to_string (*span_id);
209209 VALIDATION_ERROR (res, msg);
@@ -231,6 +231,7 @@ void RequestHandler::on_extract_headers(const httplib::Request& req,
231231 }
232232
233233 datadog::tracing::SpanConfig span_cfg;
234+ // The span below will not be finished and flushed.
234235 auto span =
235236 tracer_.extract_span (utils::HeaderReader (*http_headers), span_cfg);
236237 if (auto error = span.if_error ()) {
@@ -248,7 +249,7 @@ void RequestHandler::on_extract_headers(const httplib::Request& req,
248249void RequestHandler::on_span_flush (const httplib::Request& /* req */ ,
249250 httplib::Response& res) {
250251 scheduler_->flush_telemetry ();
251- spans_ .clear ();
252+ active_spans_ .clear ();
252253 http_headers_.clear ();
253254 res.status = 200 ;
254255}
@@ -268,8 +269,8 @@ void RequestHandler::on_span_error(const httplib::Request& req,
268269 VALIDATION_ERROR (res, " on_span_error: missing `span_id` field." );
269270 }
270271
271- auto span_it = spans_ .find (*span_id);
272- if (span_it == spans_ .cend ()) {
272+ auto span_it = active_spans_ .find (*span_id);
273+ if (span_it == active_spans_ .cend ()) {
273274 const auto msg =
274275 " on_span_error: span not found for id " + std::to_string (*span_id);
275276 VALIDATION_ERROR (res, msg);
0 commit comments