Skip to main content

Module observer

Module observer 

Source
Expand description

Three-tier observer resolution + the Observer trait.

Spec 11 § 3:

  • Per-task OBSERVER_TASK (highest priority; via Future::with_observer adapter, lands in spec 13 § 3 / Phase 3 task 3.3).
  • Per-thread OBSERVER_THREADwith_observer_thread_local, with_test_observer, #[obs::test].
  • Global OBSERVER_GLOBALinstall_observer.

The hot path checks OVERRIDE_COUNT == 0 first so a process that never installs an override pays one atomic load and one ArcSwap::load_full. The CAN_ENTER cell prevents re-entry when a sink synthesises an event.

Structs§

InMemoryHandle
Stable handle to an InMemorySink. Clone-safe; share across threads.
InMemoryObserver
Test-grade observer: every envelope is delivered to an InMemorySink. Spec 61 § 2.4 example.
NoopObserver
The default observer: drops every envelope.
StandardObserver
Production-ready observer with reloadable config and per-tier worker pool.
StandardObserverBuilder
Builder for StandardObserver.
ThreadObserverGuard
RAII guard returned by with_observer_thread_local.
WeakObserver
Weak handle for code that needs to refer to the observer without extending its lifetime — chiefly sinks that internally hold callbacks back into the observer (e.g. the future ObsToTracingSink re-emitting through the registered tracing dispatcher).
WorkerCounters
Per-tier counters surfaced as ObsSinkDropped self-events.

Enums§

BuildError
Errors returned by StandardObserverBuilder::build.

Traits§

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

Functions§

enter_emit_envelope
Dispatch one envelope through the observer with the re-entry guard held. Spec 11 § 3.1 “Re-entry and the CAN_ENTER cell”.
install_observer
Install the global observer. Called once at process start.
install_observer_arc
Install a pre-arc’d observer. Convenience for tests and patterns that already have an Arc<dyn Observer> (e.g. multi-tenant registries).
observer
Resolve the active observer.
observer_weak
Weak handle to whatever observer() would return right now.
with_observer_task
Async sibling of with_test_observer: install the observer in the per-task slot for the duration of fut. This is the version the #[obs::test] async expansion uses so that an emit on a migrated-tokio-worker-thread still resolves to the test observer (the per-thread slot would not be set on the destination worker).
with_observer_task_sync
Synchronous sibling of with_observer_task used by Instrumented<F>::poll so a single poll can bind / unbind the per-task observer without requiring an await. Spec 13 § 3.
with_observer_thread_local
Sync RAII guard. Sets the per-thread observer override; restores the previous value on drop. Do not hold across .await — see the warning in spec 11 § 3.1; use Future::with_observer (Phase 3 task 3.3) for async.
with_test_observer
Test-flavored helper. Installs the observer per-thread for the duration of f; restores on closure exit. Used by #[obs::test] (Phase 2 task 2.6) and by users that want to assert what was emitted from a synchronous block.