sapient_telemetry/lib.rs
1//! SAPIENT telemetry — built-in observability, not bolted-on.
2//!
3//! Implements the `Telemetry` trait with:
4//! - `NoOpTelemetry`: zero-overhead default
5//! - `ConsoleTelemetry`: prints spans to stderr (useful in dev)
6//! - `OtelTelemetry` (feature "otel"): OTLP export
7//!
8//! All per-op instrumentation points are in `InstrumentedSession` in
9//! `sapient-runtime` — telemetry crate only provides the traits and impls.
10
11pub mod metrics;
12pub mod profiler;
13pub mod telemetry;
14
15pub use profiler::{ChromeTracer, Span};
16pub use telemetry::{ConsoleTelemetry, NoOpTelemetry, Telemetry, TelemetryConfig};
17
18/// Initialise a global `tracing` subscriber (JSON or pretty).
19///
20/// When `verbose` is false, tracing output is disabled so chat/pull stay clean.
21/// Set `RUST_LOG=info` to override.
22pub fn init_tracing(json: bool, verbose: bool) {
23 use std::io;
24 use tracing_subscriber::{fmt, EnvFilter};
25
26 let default = if verbose { "info" } else { "off" };
27 let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(default));
28
29 if json {
30 fmt().with_env_filter(filter).json().init();
31 } else if verbose {
32 fmt()
33 .with_env_filter(filter)
34 .with_target(true)
35 .with_file(false)
36 .with_line_number(false)
37 .init();
38 } else {
39 fmt().with_env_filter(filter).with_writer(io::sink).init();
40 }
41}