Skip to main content

Observer

Trait Observer 

Source
pub trait Observer:
    Send
    + Sync
    + 'static {
    // Required method
    fn emit_envelope(&self, env: ObsEnvelope);

    // Provided methods
    fn enabled(&self, callsite: &ObsCallsite) -> bool { ... }
    fn generation(&self) -> u32 { ... }
    fn reload_filter(&self) { ... }
    fn flush(&self) -> Pin<Box<dyn Future<Output = ()> + Send + '_>> { ... }
    fn shutdown(&self) -> Pin<Box<dyn Future<Output = ()> + Send + '_>> { ... }
    fn shutdown_blocking(&self, timeout: Duration) { ... }
    fn callsites(&self) -> Option<Arc<ObsCallsiteRegistry>> { ... }
    fn schema_registry(&self) -> Option<Arc<SchemaRegistry>> { ... }
    fn resource_attrs(&self) -> Arc<ResourceAttrs> { ... }
}
Expand description

The global observer trait. Sealed in spirit (downstream crates implement it freely, but the SDK ships NoopObserver, InMemoryObserver, StandardObserver covering 99% of cases).

&self everywhere so the same observer reference is reused across every emit; no locks taken on the hot path.

Required Methods§

Source

fn emit_envelope(&self, env: ObsEnvelope)

Hot-path emit. Never blocks. Never panics. Spec 11 § 3.

Provided Methods§

Source

fn enabled(&self, callsite: &ObsCallsite) -> bool

Cheap callsite filter check; called only when the cached Interest is Sometimes. Default impl returns true (allows every callsite that survived enabled_static).

Source

fn generation(&self) -> u32

Monotonic generation counter; bumped on every filter / config change so callsite caches re-validate. Spec 11 § 3.2.

Source

fn reload_filter(&self)

Force every callsite’s interest cache back to Unknown. Default impl is a no-op for observers that don’t filter.

Source

fn flush(&self) -> Pin<Box<dyn Future<Output = ()> + Send + '_>>

Flush all sinks; await in-flight batches. Default no-op.

Source

fn shutdown(&self) -> Pin<Box<dyn Future<Output = ()> + Send + '_>>

Shutdown all sinks and join workers. Idempotent.

Source

fn shutdown_blocking(&self, timeout: Duration)

Synchronous shutdown for use in panic hooks and Drop impls where awaiting is not possible. Best-effort within timeout. Spec 11 § 3, § 6.1.

Source

fn callsites(&self) -> Option<Arc<ObsCallsiteRegistry>>

Access this observer’s per-process callsite registry, when it has one. The bridge (Direction A) writes the registry on first sight; ObsToTracingSink reads it to reconstitute tracing::Metadata for interned envelopes. Spec 31 § 3.2.

Source

fn schema_registry(&self) -> Option<Arc<SchemaRegistry>>

Access this observer’s schema registry, when it has one. Sinks hold their own Arc<SchemaRegistry> from construction; this hook lets the bridge fall back to the global observer’s registry without depending on StandardObserver.

Source

fn resource_attrs(&self) -> Arc<ResourceAttrs>

Snapshot of the workspace-shared ResourceAttrs (OTel semantic-convention keys). Sinks call this at flush time so a single config-watcher reload re-projects every sink. Default returns the empty / observer-less attribute set; concrete observers (StandardObserver) override. Spec 20 § 2.1 / spec 94 § 2.7 / P1-E.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§