-
|
I want to be able to pass some configuration which can be used in Is there a way to do this? I couldn't work it out. How can the host or the queue size or the prefix be passed in rather than hardcoded in the below example? impl MakeDefaultHandle for Recorder {
// We don't need to return anything meaningful from here (unlike PrometheusHandle)
// Let's just return an empty tuple.
type Out = ();
fn make_default_handle() -> Self::Out {
// The regular setup for StatsD..
let recorder = StatsdBuilder::from("127.0.0.1", 8125)
.with_queue_size(5000)
.with_buffer_size(1024)
.build(Some("prefix"))
.expect("Could not create StatsdRecorder");
metrics::set_boxed_recorder(Box::new(recorder)).unwrap();
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
You can use use std::sync::OnceLock;
static HOST: OnceLock<String> = OnceLock::new();
struct Recorder;
impl MakeDefaultHandle for Recorder {
type Out = ();
fn make_default_handle() -> Self::Out {
let recorder = StatsdBuilder::from(
HOST.get_or_init(|| std::env::var("STATSD_HOST").expect("to be set")),
8125,
)
.with_queue_size(5000)
.with_buffer_size(1024)
.build(Some("prefix"))
.expect("Could not create StatsdRecorder");
metrics::set_global_recorder(recorder).unwrap();
}
}EDIT: Honestly, to me this part seems a bit awkward or convoluted to use, since the expected solution would be just adding fields to the |
Beta Was this translation helpful? Give feedback.
-
|
This is now possible, because |
Beta Was this translation helpful? Give feedback.
This is now possible, because
make_default_handletakes self as argument, and also there'sGenericMetricLayer::pair_from.