|
Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
|
Logs, request IDs, tracing and metrics for running Orbit in production.
Register request_id() and tracing() before access_log(), so the log line carries their IDs.
ServerConfig::log_format (--log-format) selects the format:
text (default): [2026-10-04 12:00:00.123] [INFO ] [App.cpp:296] message key=value. Colors are used only when stdout is a terminal.json: one object per line, timestamps in UTC, ready for Loki, ELK, Datadog, CloudWatch and similar:Each line is written and flushed as it is logged, so logs appear immediately in docker logs, journald or a redirected file, and nothing is lost if the process crashes.
The level and format are process-wide. An App applies log_level and log_format only when they differ from the defaults (INFO, text), so creating an App never resets a level set earlier with orbit::utils::Logger::init() / set_format() or by another App. Several Apps in one process share one setting: the last one that sets it explicitly wins.
Log your own structured events with orbit::utils::Logger::log_fields(level, __FILE__, __LINE__, "message", {{"key", "value"}}). orbit::utils::Logger::set_sink() sends lines somewhere other than stdout (it is called under the logger's lock, so it must not log itself).
orbit::middleware::access_log() logs every request when its response is sent: method, path (with query), status, response bytes, duration, client IP (see trusted_proxies() behind a load balancer), user agent, and the request and trace IDs when those middlewares run. Streamed responses (send_headers / write_chunk) are logged when their headers are sent.
orbit::middleware::request_id() sets req.request_id and the X-Request-ID response header. A well-formed incoming ID (up to 128 characters of [A-Za-z0-9._:-], e.g. from a load balancer) is reused; anything else is replaced with a random 128-bit ID. Return it in error responses so a user's report can be matched to the logs.
orbit::middleware::tracing() implements W3C Trace Context: it continues the trace from an incoming traceparent header, or starts a new one, and sets req.trace_id and req.span_id. Each finished request is reported as a orbit::middleware::Span (trace and span IDs, parent span, name, start, duration, status) to on_span_end, where it can be handed to an OpenTelemetry exporter:
When calling other services, pass the context on so their spans join the trace:
orbit::middleware::Metrics::track() records, and app.enable_metrics() serves in Prometheus format:
| Metric | Type | Labels |
|---|---|---|
orbit_http_requests_total | counter | method, status |
orbit_http_request_duration_seconds | histogram (5 ms … 10 s buckets) | method |
orbit_http_requests_in_flight | gauge | |
orbit_http_request_bytes_total | counter | |
orbit_http_response_bytes_total | counter | method |
orbit_active_connections | gauge | type (tcp, quic) |
Paths are deliberately not a label: every distinct URL would become its own time series. Metrics are process-wide.