From 4031e77edd2abd694114be698312d086bce6b425 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Thu, 10 Sep 2026 01:30:43 +0200 Subject: More tracing stuff --- server/src/srv.cpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'server/src/srv.cpp') diff --git a/server/src/srv.cpp b/server/src/srv.cpp index b70f05c..f79da33 100644 --- a/server/src/srv.cpp +++ b/server/src/srv.cpp @@ -19,6 +19,7 @@ import :gpx; import :srv; namespace beast = boost::beast; +namespace chrono = std::chrono; namespace json = boost::json; namespace net = boost::asio; using tcp = boost::asio::ip::tcp; @@ -157,12 +158,22 @@ static_assert(bhttp::concepts::body_reader); auto handler::handle_process_gpx(l0_ctx ctx, http::readable_request r) -> net::awaitable { + auto l = + l_.sub("handle_process_gpx").with("trace_id", ctx.trace_id.as_string()); + auto gpx_file = gpx::file{}; try { + l.debug("Reading GPX request body"); + auto const before_read_gpx = chrono::steady_clock::now(); auto req = co_await http::read_request(ctx, std::move(r)); gpx_file = std::move(req->body().unwrap()); + l.debug( + "Read GPX request body in {}", + chrono::duration{ + chrono::steady_clock::now() - before_read_gpx + }); } catch (std::exception& ex) { @@ -178,7 +189,7 @@ auto handler::handle_process_gpx(l0_ctx ctx, http::readable_request r) // TODO: catch handler exceptions and return 500 when raised? // (keep-alive depends on whether whole request was read) - auto mres = inner_.process_gpx(std::move(gpx_file)); + auto mres = inner_.process_gpx(ctx.trace_id, std::move(gpx_file)); if (!mres) { auto tpl = problem::tpl{ @@ -212,7 +223,10 @@ auto handler::handle_sysinfo(l0_ctx ctx, http::readable_request r) co_return rsp; } -handler::handler(api::handler&& inner) : inner_{std::move(inner)} {} +handler::handler(log::logger const& l, api::handler&& inner) + : l_{l.sub("handler")}, inner_{std::move(inner)} +{ +} auto handler::make_routes() -> http::route_tree> { @@ -235,22 +249,21 @@ auto handler::make_routes() -> http::route_tree> auto server::make_global_middleware(config::http_server const& cfg) -> http::middleware_t { - return http::middleware_compose< - http::base_ctx, http::trace_id_ctx, - http::trace_id_ctx - >(http::trace_id_middleware, - http::cors_middleware>( - cfg.allow_origins)); + return http:: + middleware_compose( + http::trace_id_middleware, + http::cors_middleware(cfg.allow_origins)); } server::server( log::logger const& l, config::http_server const& cfg, locale::selector&& lsel, api::handler&& inner) - : handler_{std::move(inner)}, + : handler_{l, std::move(inner)}, srv_{ - l, http::router{ - std::move(lsel), make_global_middleware(cfg), handler_.make_routes() - } + l, + http::router{ + l, std::move(lsel), make_global_middleware(cfg), handler_.make_routes() + } } { } -- cgit v1.3