cloud_sdk/diagnostics/observer.rs
1use super::DiagnosticEvent;
2
3/// Caller-owned opt-in sink for payload-free lifecycle events.
4///
5/// Core never logs and never retains the observer or its errors. The shared
6/// receiver permits reentrant use and concurrent observation when the caller's
7/// implementation supplies the necessary interior synchronization. Returned
8/// errors are ignored; panics follow ordinary Rust panic behavior while the
9/// workspace lease retains cleanup ownership during unwinding.
10pub trait DiagnosticObserver {
11 /// Caller-specific observation failure.
12 type Error;
13
14 /// Observes one copy-only event. Returned errors never alter SDK execution.
15 fn observe(&self, event: DiagnosticEvent) -> Result<(), Self::Error>;
16}
17
18/// Disabled observer used by ordinary client methods.
19#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
20pub struct NoopDiagnosticObserver;
21
22impl DiagnosticObserver for NoopDiagnosticObserver {
23 type Error = core::convert::Infallible;
24
25 fn observe(&self, _event: DiagnosticEvent) -> Result<(), Self::Error> {
26 Ok(())
27 }
28}
29
30pub(crate) fn notify<O>(observer: &O, event: DiagnosticEvent)
31where
32 O: DiagnosticObserver + ?Sized,
33{
34 let _ignored = observer.observe(event);
35}