Expand description
Façade crate — re-exports the everyday obs API.
Most downstream apps depend only on obs-kit. Spec 61 § 2.11 +
boundary-review § 3.6 (init_for_service).
Phase 3 (obs-migration spec § 5):
- Re-exports
obs-core’ssinkandwiresub-modules by path so consumers implementing customSinks or walking the envelope codec don’t need a directobs-coredep. - Module aliases for every feature-gated sub-crate:
obs_kit::{live_tail, prom, sink_batch, otel, tracing_bridge}. self_event/SelfEventBuildercollapse the hand-builtObsEnvelope { tier, sev, sampling_reason, ts_ns, .. }pattern into one helper.protois the explicit “here be dragons” escape hatch for the rare call sites (partitioner, live-tail serializer) that need typed direct-field access on the wire envelope.
Re-exports§
Modules§
- observer
- Three-tier observer resolution + the
Observertrait. - proto
- Proto-type escape hatch for the rare call sites that need direct
access to the wire envelope’s typed enum fields — partitioners
dispatching on
proto::Severity/proto::SamplingReason, live-tail serializers that render the proto name, sink framework tests that assert onproto::EnumValuevariants. Phase 3 spec § 5.1 + § 6.4. - sink
- Wire codec and sink trait sub-modules. Consumers implementing a
custom
Sinkor reading/writing envelopes on the wire previously had to depend onobs-coredirectly; obs-kit re-exports these soobs-kit = "0.2"is the only runtime dep needed. Spec § 5.1. Sinks consumeScrubbedEnvelopeand ship it to a destination (stdout, NDJSON file, OTLP, ClickHouse, etc.). - wire
- Wire codec and sink trait sub-modules. Consumers implementing a
custom
Sinkor reading/writing envelopes on the wire previously had to depend onobs-coredirectly; obs-kit re-exports these soobs-kit = "0.2"is the only runtime dep needed. Spec § 5.1. Wire-format helpers for obs.
Macros§
- context
obs::context!(name = value, ...)— likeobs::scope!but without the per-scope tail buffer. Spec 13 § 2.2.- emit
- Function-like emit macro:
obs::emit!(MyEvent { field: value })orobs::emit!(WARN, MyEvent { field: value })to escalate. - forensic
obs::forensic!(site = "...", message = "...", { "k" => v, ... })— emergency escape hatch. Always emits, regardless of sampling. Spec 13 § 8.- include_
schemas obs::include_schemas!("myapp.v1")— wire up every fileobs-buildemits into the user’s crate. Expands to fourinclude!calls underOUT_DIR/obs/. Spec 12 § 3.1.- scope
obs::scope!(name = value, ...)— push anobs::scope!frame onto the active task’s scope stack. Returns aScopeGuardthat pops the frame on drop and flushes the tail-on-error buffer when>= ERRORwas observed inside.
Structs§
- Events
Config - The complete config tree. Every field is optional so a config file
can be a single line if the user only cares to override
filter. - FanOut
Sink - Multiplex a single tier’s output across N sinks.
- Field
Capture - Visitor used by tracing’s
Event::record(visitor)to extract typed values into a thread-local scratch space; reused across emissions (zero per-event allocation in the steady state). Spec 12 § 3.6. - Field
Meta - Compile-time field metadata emitted by codegen alongside each
EventSchemaimpl. Mirrors the proto-sideobs.v1.FieldMeta. - Filter
- Parsed
obs::Filter. Statics are checked first against the callsite; dynamics are bucketed byfull_nameand consulted at emit time againstenv.labels. - 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. - InMemory
Sink - Test sink: collects envelopes into a bounded ring buffer.
- Init
Builder - Builder returned by
init_for_service. Configure the service, preset, and any per-tier sink overrides; finish withSelf::install. - Init
Guard - RAII guard returned by
InitBuilder::install. On drop, calls the global observer’sshutdown_blockingwith the configured budget so in-flight envelopes have a bounded window to flush. - Instrumented
- Future adapter that re-enters an
obs::scope!frame and anArc<dyn Observer>override on every poll. Constructed viaInstrument::instrument/WithObserver::with_observer. - Level
Split Writer - Composes two writers — INFO+ goes through
low, WARN+ throughhigh. The conventional shape for cargo binaries. - Ndjson
File Sink - File sink that writes envelopes as JSON lines to the underlying
MakeWriter. Buffers aMutex<ErasedWriter>per batch to avoid re-opening files for every event. - NonBlocking
Writer - Wraps a
MakeWriterwith a background thread + boundedmpsc::SyncSenderchannel. Overflow drops the line and increments the dropped counter. Spec 20 § 3.5. - Noop
Observer - The default observer: drops every envelope.
- Noop
Sink - A sink that drops every envelope.
- ObsBatch
- ObsCallsite
- Static metadata for a single emit site. Constructed by codegen via
the
const fnconstructor — no heap allocation, no first-emit cost. - ObsEnvelope
- ObsFn
Entered - ObsFn
Executed - ObsForensic
Event - ObsTrace
Ctx - Parsed W3C trace context.
- Rolling
File Writer - Rolling file writer with size + time policies. Spec 20 § 3.4.
- Rolling
File Writer Builder - Builder for
RollingFileWriter. - Sampling
Config - Sampling config (spec 15 § 2 + spec 13 § 6).
- Scope
Frame - One frame on the per-task / per-thread scope stack.
- Scope
Frame Builder - Programmatic builder for pushing an
obs::scope!-shaped frame. - Scope
Guard - RAII guard returned by
obs::scope!andobs::context!. Dropping pops the frame; forScopekind frames where any>= ERRORenvelope was observed, the tail buffer is flushed back through the active observer withsampling_reason = TAIL_ERROR. - Scrubbed
Envelope - Read-only view of an envelope whose payload has already been run through the per-tier scrubber. Constructed by the worker; consumed by sinks.
- Self
Event Builder - Fluent builder for runtime-style self-events.
- SpanCtx
- Read-only view of the active scope/span context that
register_typed-style closures receive. Spec 12 § 3.6. - Span
Frame - One frame of the bridge-visible span ancestry. Borrowed; never owns span data. Spec 12 § 3.6.
- Span
Trace - Captured
obs::scope!ancestry. Liketracing-error::SpanTrace. - Standard
Observer - Production-ready observer with reloadable config and per-tier worker pool.
- Standard
Observer Builder - Builder for
StandardObserver. - Stderr
Writer - Writes to stderr.
- Stdout
Sink - Stdout / writer-backed sink.
- Stdout
Writer - Writes to stdout.
- TeeWriter
- Tee writer — writes to both branches.
- W3cPropagator
- W3C
traceparentheader propagator. - Worker
Counters - Per-tier counters surfaced as
ObsSinkDroppedself-events. - Worker
Guard - Returned alongside
NonBlockingWriter; flushes + joins the bg thread on drop.
Enums§
- Cardinality
- Classification
- Field
Kind - Field
Role - Codegen-derived classification of a field. Decoupled from the
FieldKindenum so codegen can stamp this from the descriptor without re-parsing. - Formatter
Style - Output style for
StdoutSink. See spec 20 § 3.6. - Init
Error - Errors from
InitBuilder::install. - Metric
Kind - Rolling
Policy - Rolling policy. Spec 20 § 3.4.
- Sampling
Reason - Scope
Field - A field declared on
obs::scope!/obs::context!. Field types match the envelope projection contract: trace ids land on the typed envelope slots, labels go intoenv.labels. Spec 13 § 2.1. - Scope
Kind - Whether a frame carries a tail-on-error buffer (
Scope) or is a pure broadcast frame (Context). Spec 13 § 2.2. - Service
Preset - Built-in service presets.
- Severity
- Tier
Constants§
- DEBUG
DEBUGseverity shortcut forobs::emit!.- ENVELOPE_
FORMAT_ VER - Wire-format version of the
ObsEnvelope/ObsBatchshape. - ERROR
ERRORseverity shortcut forobs::emit!.- FATAL
FATALseverity shortcut forobs::emit!.- INFO
INFOseverity shortcut forobs::emit!.- TRACE
- Severity ident shortcuts for use with
obs::emit!. The macro form accepts eitherSeverity::Warnor the bareWARNident. - WARN
WARNseverity shortcut forobs::emit!.
Traits§
- Buildable
To - Marker trait implemented by
typed-builder’s “all-required-fields-set” builder state. The codegen emits a blanket impl over the parameter shapetyped-builderproduces, so.emit()only compiles when every required setter has been called. Spec 12 § 3.6. - Emit
- Blanket trait giving every
EventSchemaan.emit()/.emit_at(sev)shortcut. - Enum
Count - Compile-time variant count for any enum used as a
LABELfield. Generated by#[derive(EnumLabel)]and consulted by lint L005 so we do not depend on nightly’svariant_count. Spec 12 § 3.6. - Event
Schema - Trait implemented by every
Obs*event type. - Instrument
- Public extension trait —
.instrument(scope!(...))on every future owned by user code. - Make
Writer - A factory that yields one
io::Writeper batch. Cheap to call. Spec 20 § 3.3. - Metric
Emitter - Implemented by metric sinks (OTLP metrics, Prometheus exporters).
Generated
EventSchema::project_metricscalls one method perMEASUREMENTfield. Spec 12 § 3.6. - Observer
- The global observer trait. Sealed in spirit (downstream crates
implement it freely, but the SDK ships
NoopObserver,InMemoryObserver,StandardObservercovering 99% of cases). - Sink
- A delivery destination. Called from per-tier worker tasks, never on the emit thread.
- With
Observer - Public extension trait —
.with_observer(o)on a future binds an observer override that follows the future across thread migration (per-task tier; spec 11 § 3.1).
Functions§
- extract_
w3c - Free-function form of
W3cPropagator::extract. Spec 93 P1-5 requires this name inobs_core::propagator. - fresh_
span_ id - Generate a fresh 8-byte span id rendered as 16 lowercase hex characters.
- fresh_
trace_ id - Generate a fresh 16-byte trace id rendered as 32 lowercase hex characters. Uses BLAKE3 over a CSPRNG-friendly seed (spec 71 randomness rule).
- init_
for_ service - Entry point.
serviceandversionbecome theservice.name/service.versionresource attributes on every envelope. - inject_
w3c - Free-function form of
W3cPropagator::inject. - install_
observer - Install the global observer. Called once at process start.
- install_
panic_ hook - Install the obs panic hook. Idempotent — calling more than once is a no-op.
- now_ns
- Wall-clock timestamp in nanoseconds since the Unix epoch, saturated
at
u64::MAX. - observer
- Resolve the active observer.
- observer_
weak - Weak handle to whatever
observer()would return right now. - self_
event - Build a labels-only self-event envelope with
sampling_reason = SAMPLING_REASON_RUNTIMEand the current wall-clockts_ns. - status_
class - Map an HTTP status code to one of
1xx..5xx,err. Spec 40 § 2. - 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.
Attribute Macros§
- instrument
#[obs::instrument]— wraps a function body in anobs::scope!and emits oneObsFnExecutedevent on exit (default) or two (ObsFnEntered+ObsFnExecuted) whenenter = true.
Derive Macros§
- Event
- Derive macro for the Rust-first authoring path.