solstice-ci/crates/common/src/telemetry.rs
Till Wegmueller 7fc4e8edb7
Introduce logs-service for structured job logs management; bump version to 0.1.13
- Add `logs-service` crate as a separate microservice to handle job log storage, retrieval, and categorization.
- Update orchestrator to redirect log endpoints to the new service with optional permanent redirects using `LOGS_BASE_URL`.
- Enhance log persistence by introducing structured fields such as category, level, and error flags.
- Implement migration to add new columns and indexes for job logs.
- Add ANSI escape sequence stripping and structured logging for cleaner log storage.
- Improve SSH log handling with interleaved stdout/stderr processing and pty request support.
- Revise Docker files and compose setup to include logs-service, with support for PostgreSQL and secure connections.

Signed-off-by: Till Wegmueller <toasterson@gmail.com>
2025-11-18 11:48:09 +01:00

29 lines
986 B
Rust

use tracing_subscriber::{EnvFilter, fmt, layer::SubscriberExt, util::SubscriberInitExt};
/// Guard that keeps non-blocking writer alive and allows flushing on drop
pub struct TelemetryGuard {
// Drop to flush writer.
_guard: Option<tracing_appender::non_blocking::WorkerGuard>,
}
/// Initialize tracing. Console-only for now; OTEL can be wired later.
pub fn init_tracing(_service_name: &str) -> miette::Result<TelemetryGuard> {
let (nb_writer, guard) = tracing_appender::non_blocking(std::io::stderr());
let fmt_layer = fmt::layer()
.with_target(false)
.with_writer(nb_writer)
// Force-disable ANSI to keep logs plain for serial capture and gRPC forwarding
.with_ansi(false);
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
tracing_subscriber::registry()
.with(filter)
.with(fmt_layer)
.init();
Ok(TelemetryGuard {
_guard: Some(guard),
})
}