Expand description
§modo::tracing
Tracing initialisation and structured logging for modo applications.
Configures tracing_subscriber at application startup. Call init
once from main — typically before starting the HTTP server — and hold
the returned TracingGuard for the lifetime of the process.
§Provides
| Item | Description |
|---|---|
Config | Log level, output format, and optional Sentry settings |
init | Initialises the global tracing subscriber; returns TracingGuard |
TracingGuard | RAII guard that keeps the subscriber (and Sentry client) alive |
SentryConfig | Sentry DSN, environment, and sampling rates |
info!, debug!, warn!, error!, trace! | Re-exported tracing macros |
§Log format
The format is selected by Config::format:
| Value | Description |
|---|---|
"pretty" (default) | Human-readable multi-line output |
"json" | Machine-readable JSON, one object per line |
| anything else | Compact single-line output |
The active log level is read from the RUST_LOG environment variable
when present; otherwise Config::level is used.
§Sentry integration
Sentry support is always compiled in. Populate SentryConfig inside
Config::sentry with a non-empty DSN to enable error and performance
reporting at runtime. The Sentry SDK is initialised inside init and
flushed when the TracingGuard is shut down. When the DSN is empty
or the sentry section is omitted, Sentry is silently skipped.
§HTTP request spans
This module only handles subscriber setup. HTTP request/response
spans are produced by crate::middleware::tracing, which wires a
tower_http::trace::TraceLayer with a ModoMakeSpan that pre-declares
a tenant_id field (initially empty) so the tenant middleware can
later record it via span.record("tenant_id", ...). All tracing field
names use snake_case (user_id, session_id, job_id, etc.).
§Quick start
use modo::config::load;
use modo::Config;
use modo::runtime::Task;
#[tokio::main]
async fn main() -> modo::Result<()> {
let config: Config = load("config/").unwrap();
let guard = modo::tracing::init(&config.tracing)?;
// ... start server, then on shutdown:
guard.shutdown().await
}Macros§
- debug
- Constructs an event at the debug level.
- error
- Constructs an event at the error level.
- info
- Constructs an event at the info level.
- trace
- Constructs an event at the trace level.
- warn
- Constructs an event at the warn level.
Structs§
- Config
- Configuration for the tracing subscriber.
- Sentry
Config - Sentry error and performance reporting settings.
- Tracing
Guard - RAII guard that keeps the tracing subscriber and Sentry client alive.
Functions§
- init
- Initialise the global tracing subscriber.