Expand description
§telemetry-safe
telemetry-safe is the main facade crate for defining which values are allowed
to flow into telemetry.
It re-exports:
ToTelemetrytelemetry(&value)telemetry_debug(&value)#[derive(ToTelemetry)]
Use this crate when you want compile-time enforcement that only explicitly approved representations can be emitted through logging, tracing, metrics, or other observability paths.
§Why this crate exists
Plain tracing, logging, or metrics code makes it easy to accidentally send
PII through Debug, Display, or default instrumentation behavior.
telemetry-safe takes an opt-in, type-driven approach instead:
- values must implement
ToTelemetrybefore they can be emitted - raw
String/&strare not blanket-approved - unsafe paths fail at compile time rather than depending on review discipline
§Basic example
use telemetry_safe::{telemetry, ToTelemetry};
use std::fmt::{self, Formatter};
#[derive(ToTelemetry)]
struct UserId(u64);
struct OutcomeLabel(&'static str);
impl ToTelemetry for OutcomeLabel {
fn fmt_telemetry(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str(self.0)
}
}
#[derive(ToTelemetry)]
struct LoginAttempt {
user_id: UserId,
outcome: OutcomeLabel,
#[telemetry(skip)]
email: String,
}
let attempt = LoginAttempt {
user_id: UserId(42),
outcome: OutcomeLabel("accepted"),
email: "user@example.com".to_owned(),
};
assert_eq!(
telemetry(&attempt).to_string(),
"LoginAttempt { user_id: UserId(42), outcome: accepted }",
);§Related crates
telemetry-safe-core- the minimal backend-agnostic core
telemetry-safe-tracingtracingintegration, including#[safe_instrument]
For the full project overview and workspace-level documentation, see the repository README at https://github.com/milabo/telemetry-safe-rs.
Modules§
- prelude
- Re-exports the small surface most applications need at call sites.
Structs§
- Telemetry
Debug - Wraps a value so derive output can feed
debug_*builders without exposingDebug. - Telemetry
Display - Wraps a value so telemetry-safe formatting can be used where
Displayis expected.
Traits§
- ToTelemetry
- Formats a value only through an explicitly approved telemetry representation.
Functions§
- telemetry
- Exposes a telemetry-safe value as
Display. - telemetry_
debug - Exposes a telemetry-safe value as
Debug.