Expand description
§solti-observe
Observability primitives for the solti task execution system.
This crate wires tracing into solti, covering three concerns:
- Logger initialization -
init_loggerinstalls a global tracing subscriber configured viaLoggerConfig(format, level filter, timezone, color). - Event logging -
TracingEventSubscriber(featuresubscriber) maps everytaskvisorsupervision event to a structured tracing call at the appropriate severity level. - Timezone sync -
timezone_sync(featuretimezone-sync) is a periodic task that re-detects the local UTC offset so log timestamps stay correct across DST transitions.
§Architecture
main()
├─ init_local_offset() // before tokio runtime
└─ tokio::Runtime::new()
└─ async_main()
├─ init_logger(&cfg) // installs global tracing subscriber
│ ├─ Text → fmt::Layer (colored, RFC 3339 timestamps)
│ ├─ Json → fmt::Layer::json()
│ └─ Journald → tracing_journald::layer() (Linux only)
│
├─ TracingEventSubscriber // feature: subscriber
│ └─ on_event() → trace!/debug!/info!/warn!/error!
│
└─ timezone_sync() // feature: timezone-sync
└─ periodic re-detection of local UTC offset§Public API
| Item | Feature | Description |
|---|---|---|
LoggerConfig | - | Logger configuration (format, level, timezone, color) |
init_logger | - | Install global tracing subscriber |
init_local_offset | - | Detect local UTC offset (call before tokio runtime) |
LoggerFormat | - | Output format: Text / Json / Journald |
LoggerLevel | - | Validated EnvFilter expression wrapper |
LoggerTimeZone | - | Timestamp timezone: Utc / Local |
LoggerError | - | Error type for logger initialization |
TracingEventSubscriber | subscriber | Logs taskvisor events via tracing |
timezone_sync | timezone-sync | Periodic task that re-detects the local UTC offset |
§Feature flags
| Flag | Default | Dependencies | Effect |
|---|---|---|---|
subscriber | off | taskvisor, async-trait | Enables TracingEventSubscriber |
timezone-sync | off | taskvisor, tokio-util, solti-model | Enables timezone_sync periodic task |
§Quick start
use solti_observe::{LoggerConfig, LoggerLevel, init_local_offset, init_logger};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1) Must be called before spawning threads (tokio runtime).
init_local_offset();
tokio::runtime::Runtime::new()?.block_on(async {
// 2) Initialize logger
let cfg = LoggerConfig {
level: LoggerLevel::new("info")?,
..Default::default()
};
init_logger(&cfg)?;
tracing::info!("ready");
Ok(())
})
}§Local timezone support
On most Unix platforms, detecting the local UTC offset requires reading /etc/localtime,
which is unsafe in multi-threaded processes.
To workaround this:
- Call
init_local_offsetinmain()beforetokio::runtime::Runtime::new(). - Optionally submit the
timezone_synctask to periodically re-detect the offset (handles DST transitions in long-running daemons).
If init_local_offset is not called, timestamps fall back to UTC with a warning printed to stderr on first use.
§Also
tracingthe underlying structured logging framework.taskvisor::Subscribetrait thatTracingEventSubscriberimplements.solti-prometheusis a complementary metrics subscriber for the same event stream.- See
examples/http-serverfor a complete integration example.
Structs§
- Logger
Config - Logger configuration passed to
crate::init_logger. - Logger
Level - Validated wrapper around a
tracing_subscriber::EnvFilterexpression. - Tracing
Event Subscriber - Taskvisor event subscriber that logs every event via
tracing.
Enums§
- Logger
Error - Logger
Format - Output format for the logger.
- Logger
Time Zone - Timezone configuration for log timestamps.
Traits§
- View
- Helper trait for extracting event fields with sensible defaults.
Functions§
- init_
local_ offset - Detects the local UTC offset and caches it for timestamp formatting.
- init_
logger - Initializes the global tracing subscriber based on the given
LoggerConfig. - log_
event - Logs a single event at the appropriate tracing level with structured fields.
- timezone_
sync - Builds the timezone sync task and its supervision specification.