Expand description
Three-tier observer resolution + the Observer trait.
Spec 11 § 3:
- Per-task
OBSERVER_TASK(highest priority; viaFuture::with_observeradapter, lands in spec 13 § 3 / Phase 3 task 3.3). - Per-thread
OBSERVER_THREAD—with_observer_thread_local,with_test_observer,#[obs::test]. - Global
OBSERVER_GLOBAL—install_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§
- InMemory
Handle - Stable handle to an
InMemorySink. Clone-safe; share across threads. - InMemory
Observer - Test-grade observer: every envelope is delivered to an
InMemorySink. Spec 61 § 2.4 example. - Noop
Observer - The default observer: drops every envelope.
- Standard
Observer - Production-ready observer with reloadable config and per-tier worker pool.
- Standard
Observer Builder - Builder for
StandardObserver. - Thread
Observer Guard - RAII guard returned by
with_observer_thread_local. - Weak
Observer - 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
ObsToTracingSinkre-emitting through the registered tracing dispatcher). - Worker
Counters - Per-tier counters surfaced as
ObsSinkDroppedself-events.
Enums§
- Build
Error - 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,StandardObservercovering 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 offut. 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_taskused byInstrumented<F>::pollso a single poll can bind / unbind the per-task observer without requiring anawait. 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; useFuture::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.