emit

Attribute Macro span

Source
#[span]
Expand description

Wrap an operation in a span.

§Syntax

(control_param),* tpl, (property),*

where

  • control_param: A Rust field-value with a pre-determined identifier (see below).
  • tpl: A template string literal.
  • property: A Rust field-value for a property to capture.

§Control parameters

This macro accepts the following optional control parameters:

nametypedescription
rtimpl emit::runtime::RuntimeThe runtime to emit the event through.
mdlimpl Into<emit::Path>The module the event belongs to. If unspecified the current module path is used.
whenimpl emit::FilterA filter to use instead of the one configured on the runtime.
guard-An identifier to bind an emit::Span to in the body of the span for manual completion.
ok_lvlstr or emit::LevelAssume the instrumented block returns a Result. Assign the event the given level when the result is Ok.
err_lvlstr or emit::LevelAssume the instrumented block returns a Result. Assign the event the given level when the result is Err and attach the error as the err property.
panic_lvlstr or emit::LevelDetect whether the function panics and use the given level if it does.
errimpl Fn(&E) -> TAssume the instrumented block returns a Result. Map the Err variant into a new type U that is str, &(dyn Error + 'static), or impl Error + 'static
setupimpl Fn() -> TInvoke the expression before creating the span, binding the result to a value that’s dropped at the end of the annotated function.

§Template

The template for the event. See the tpl macro for syntax.

§Properties

Properties that appear within the template or after it are added to the emitted event. The identifier of the property is its key. Property capturing can be adjusted through the as_* attribute macros.