Spaces:
Sleeping
Sleeping
Dmitry Beresnev commited on
Commit ·
7caa6ba
1
Parent(s): 677456b
Log detailed error bodies for UI failures
Browse files- cpp/runtime_components.cpp +4 -0
- cpp/server.cpp +22 -2
cpp/runtime_components.cpp
CHANGED
|
@@ -288,7 +288,11 @@ void Scheduler::worker_loop() {
|
|
| 288 |
}
|
| 289 |
registry_.complete(ctx, RequestState::DONE, {status, body});
|
| 290 |
} catch (const std::exception &e) {
|
|
|
|
| 291 |
registry_.complete(ctx, RequestState::FAILED, {500, json({{"error", e.what()}}).dump()});
|
|
|
|
|
|
|
|
|
|
| 292 |
}
|
| 293 |
}
|
| 294 |
}
|
|
|
|
| 288 |
}
|
| 289 |
registry_.complete(ctx, RequestState::DONE, {status, body});
|
| 290 |
} catch (const std::exception &e) {
|
| 291 |
+
log_line("request_id=" + ctx->request_id + " scheduler_exception=" + std::string(e.what()));
|
| 292 |
registry_.complete(ctx, RequestState::FAILED, {500, json({{"error", e.what()}}).dump()});
|
| 293 |
+
} catch (...) {
|
| 294 |
+
log_line("request_id=" + ctx->request_id + " scheduler_exception=unknown");
|
| 295 |
+
registry_.complete(ctx, RequestState::FAILED, {500, json({{"error", "Unknown exception"}}).dump()});
|
| 296 |
}
|
| 297 |
}
|
| 298 |
}
|
cpp/server.cpp
CHANGED
|
@@ -212,8 +212,13 @@ http::response<http::string_body> handle_request(
|
|
| 212 |
auto elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
| 213 |
std::chrono::steady_clock::now() - start).count();
|
| 214 |
metrics.observe_request_latency_ms(elapsed_ms);
|
| 215 |
-
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
return res;
|
| 218 |
};
|
| 219 |
|
|
@@ -442,6 +447,10 @@ http::response<http::string_body> handle_request(
|
|
| 442 |
" final_state=" + state_to_string(final_state) +
|
| 443 |
" upstream_status=" + std::to_string(result.status) +
|
| 444 |
" elapsed_ms=" + std::to_string(elapsed_ms));
|
|
|
|
|
|
|
|
|
|
|
|
|
| 445 |
return res;
|
| 446 |
}
|
| 447 |
|
|
@@ -468,12 +477,20 @@ http::response<http::string_body> handle_request(
|
|
| 468 |
" proxied_get model=" + worker->model +
|
| 469 |
" upstream_status=" + std::to_string(upstream.status) +
|
| 470 |
" elapsed_ms=" + std::to_string(elapsed_ms));
|
|
|
|
|
|
|
|
|
|
|
|
|
| 471 |
return res;
|
| 472 |
}
|
| 473 |
|
| 474 |
return json_response(http::status::not_found, {{"error", "Not found"}});
|
| 475 |
} catch (const std::exception &e) {
|
|
|
|
| 476 |
return json_response(http::status::internal_server_error, {{"error", e.what()}});
|
|
|
|
|
|
|
|
|
|
| 477 |
}
|
| 478 |
}
|
| 479 |
|
|
@@ -494,6 +511,9 @@ void do_session(
|
|
| 494 |
http::write(socket, res);
|
| 495 |
beast::error_code ec;
|
| 496 |
socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec);
|
|
|
|
|
|
|
| 497 |
} catch (...) {
|
|
|
|
| 498 |
}
|
| 499 |
}
|
|
|
|
| 212 |
auto elapsed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(
|
| 213 |
std::chrono::steady_clock::now() - start).count();
|
| 214 |
metrics.observe_request_latency_ms(elapsed_ms);
|
| 215 |
+
std::string log_message = "request_id=" + request_id +
|
| 216 |
+
" status=" + std::to_string(res.result_int()) +
|
| 217 |
+
" elapsed_ms=" + std::to_string(elapsed_ms);
|
| 218 |
+
if (res.result_int() >= 400) {
|
| 219 |
+
log_message += " error_body=" + truncate_body(res.body());
|
| 220 |
+
}
|
| 221 |
+
log_line(log_message);
|
| 222 |
return res;
|
| 223 |
};
|
| 224 |
|
|
|
|
| 447 |
" final_state=" + state_to_string(final_state) +
|
| 448 |
" upstream_status=" + std::to_string(result.status) +
|
| 449 |
" elapsed_ms=" + std::to_string(elapsed_ms));
|
| 450 |
+
if (result.status >= 400) {
|
| 451 |
+
log_line("request_id=" + request_id +
|
| 452 |
+
" upstream_error_body=" + truncate_body(result.body));
|
| 453 |
+
}
|
| 454 |
return res;
|
| 455 |
}
|
| 456 |
|
|
|
|
| 477 |
" proxied_get model=" + worker->model +
|
| 478 |
" upstream_status=" + std::to_string(upstream.status) +
|
| 479 |
" elapsed_ms=" + std::to_string(elapsed_ms));
|
| 480 |
+
if (upstream.status >= 400) {
|
| 481 |
+
log_line("request_id=" + request_id +
|
| 482 |
+
" proxied_get_error_body=" + truncate_body(upstream.body));
|
| 483 |
+
}
|
| 484 |
return res;
|
| 485 |
}
|
| 486 |
|
| 487 |
return json_response(http::status::not_found, {{"error", "Not found"}});
|
| 488 |
} catch (const std::exception &e) {
|
| 489 |
+
log_line("request_id=" + request_id + " exception=" + std::string(e.what()));
|
| 490 |
return json_response(http::status::internal_server_error, {{"error", e.what()}});
|
| 491 |
+
} catch (...) {
|
| 492 |
+
log_line("request_id=" + request_id + " exception=unknown");
|
| 493 |
+
return json_response(http::status::internal_server_error, {{"error", "Unknown exception"}});
|
| 494 |
}
|
| 495 |
}
|
| 496 |
|
|
|
|
| 511 |
http::write(socket, res);
|
| 512 |
beast::error_code ec;
|
| 513 |
socket.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec);
|
| 514 |
+
} catch (const std::exception &e) {
|
| 515 |
+
log_line("session_exception=" + std::string(e.what()));
|
| 516 |
} catch (...) {
|
| 517 |
+
log_line("session_exception=unknown");
|
| 518 |
}
|
| 519 |
}
|