#[measured_async_function]
Expand description
A procedural macro attribute that measures the execution time of an async function.
This macro wraps an async function to record its execution duration as a histogram metric.
The duration is recorded using the FunctionDurationSeconds
metric with a “function” label
containing either the function name or a custom name if provided.
§Arguments
attr
- Optional custom name for the metric labelitem
- The async function to be measured
§Examples
Basic usage with default function name as label:
ⓘ
use metrics_macros::measured_async_function;
#[measured_async_function]
async fn process_data() {
// Function implementation
}
Using a custom name for the metric label:
ⓘ
use metrics_macros::measured_async_function;
#[measured_async_function("custom_process_name")]
async fn process_data() {
// Function implementation
}
The macro will record timing metrics that can be queried like:
function_duration_seconds{function="process_data"}
or
function_duration_seconds{function="custom_process_name"}