Writing an emitter

You can write a simple emitter using emitter::from_fn, but advanced cases need to implement the Emitter trait.

For a complete implementation, see the source for emit_file.

Dependencies

If you're writing a library with an emitter, you can depend on emit without default features:

[dependencies.emit]
version = "0.11.0-alpha.21"
# Always disable default features
default-features = false
# Add any features you need
features = ["implicit_internal_rt"]

Internal diagnostics

If your emitter is complex enough to need its own diagnostics, you can add the implicit_internal_rt feature of emit and use it when calling emit! or #[span]:

#![allow(unused)]
fn main() {
extern crate emit;
let err = "";
emit::warn!(rt: emit::runtime::internal(), "failed to emit an event: {err}");
}

Your emitter must not write diagnostics to the default runtime. If you disabled default features when adding emit to your Cargo.toml then this will be verified for you at compile-time.

Metrics

A standard pattern for emitters is to expose a function called metric_source that exposes a Source with any metrics for your emitter. See this example from emit_file.

Background processing

Emitters should minimize their impact in calling code but offloading expensive processing to a background thread. You can use emit_batcher to implement a batching, retrying, asynchronous emitter.