Skip to main content

span_async_named_dyn

Macro span_async_named_dyn 

Source
macro_rules! span_async_named_dyn {
    ($name:expr, $async_block:expr) => { ... };
    ($name:expr, $async_block:expr, $on_end:expr) => { ... };
}
Expand description

Instruments an async block with a named span whose name is built at runtime. The future owns the name: pass a String or Arc<str> to keep the future 'static.

ยงExamples

use micromegas_tracing::prelude::*;

let id = 7;
let result = span_async_named_dyn!(format!("query {id}"), async {
    42
}).await;

A trailing closure receives the output and a &mut SpanProperties to set end properties on:

use micromegas_tracing::prelude::*;

let id = 7;
let n = span_async_named_dyn!(format!("query {id}"), async { 42 }, |n, span| {
    span.set_property("n", n);
}).await;