pub fn new<F>(function: F) -> impl MetricValueProviderExpand description
A MetricValueProvider that calls function, standing in for a Java
lambda implementing MetricValueProvider: function is
value. A method Java adds later as an
overload of value gets its own factory, with_<parameter>.
§Arguments
function- computes the value from the config and the time in milliseconds
§Returns
The provider calling function.
use confluent_kafka::common::MetricValue;
use confluent_kafka::common::metrics::{metric_value_provider, Metrics};
let metrics = Metrics::new();
let name = metrics.metric_name("uptime-ms", "example");
let provider = metric_value_provider::new(|_config, now| MetricValue::Double(now as f64));
metrics.add_metric_with_metric_value_provider(name, Box::new(provider)).unwrap();