Skip to main content

rpi_telemetry/
lib.rs

1//! Mirrors `packages/telemetry/src`. Minimal span/event contracts with a noop
2//! default implementation.
3//!
4//! Real providers and the agent loop call into [`TelemetryContext`] at request
5//! boundaries. The default [`NoopTelemetryContext`] does nothing. Consumers stay
6//! monomorphic by holding a `&dyn TelemetryContext` defaulting to
7//! [`NOOP_TELEMETRY_CONTEXT`].
8//!
9//! Telemetry in the TS source is a thin span/attribute layer used opportunistically;
10//! we port only the surface downstream crates actually touch.
11
12#![forbid(unsafe_code)]
13
14pub mod context;
15pub mod noop;
16pub mod production;
17pub mod types;
18
19#[cfg(any(test, feature = "testing"))]
20pub mod testing;
21
22pub use context::{SpanGuard, TelemetryContext};
23pub use noop::{NoopTelemetryContext, NOOP_TELEMETRY_CONTEXT};
24pub use production::ProductionTelemetryContext;
25pub use types::{AttributeValue, SpanAttributes, SpanOptions, SpanStatus};
26
27/// Error returned by span operations.
28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29pub enum TelemetryError {
30    /// The operation running under the span was cancelled (abort/timeout).
31    Cancelled,
32}
33
34impl std::fmt::Display for TelemetryError {
35    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36        match self {
37            TelemetryError::Cancelled => write!(f, "operation cancelled"),
38        }
39    }
40}
41
42impl std::error::Error for TelemetryError {}