Skip to main content

Crate obs_macros

Crate obs_macros 

Source
Expand description

Procedural macros for the obs SDK.

Phase-1 surface (impl-plan task 1.9):

  • Event (#[derive(Event)]) — emits EventSchema impl, EventSchemaErased impl, linkme::distributed_slice registration, typed builder, and the const-eval lint block (L001/L002/L003/L011).
  • emit — terse obs::emit!(MyEvent { … }) shorthand.
  • scope — placeholder (full impl in Phase 3 task 3.3).

See spec 12 § 1.2 (Rust-first authoring) and spec 13 § 2 (obs::scope!).

Macros§

context
obs::context!(name = value, ...) — like obs::scope! but without the per-scope tail buffer. Spec 13 § 2.2.
emit
Function-like emit macro: obs::emit!(MyEvent { field: value }) or obs::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 file obs-build emits into the user’s crate. Expands to four include! calls under OUT_DIR/obs/. Spec 12 § 3.1.
scope
obs::scope!(name = value, ...) — push an obs::scope! frame onto the active task’s scope stack. Returns a ScopeGuard that pops the frame on drop and flushes the tail-on-error buffer when >= ERROR was observed inside.

Attribute Macros§

instrument
#[obs::instrument] — wraps a function body in an obs::scope! and emits one ObsFnExecuted event on exit (default) or two (ObsFnEntered + ObsFnExecuted) when enter = true.
test
#[obs::test] — drop-in replacement for #[test] / #[tokio::test] that installs an InMemoryObserver on the current thread (sync) or current task (async) for the duration of the test. The body’s emits land in a thread-local / task-local handle that obs::test::assert_emitted! reads.

Derive Macros§

Event
Derive macro for the Rust-first authoring path.