feat: record timer with additional tags (#9529)

This commit is contained in:
jif-oai 2026-01-20 13:01:55 +00:00 committed by GitHub
parent 9ec20ba065
commit a3a97f3ea9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,7 +12,7 @@ pub struct Timer {
impl Drop for Timer {
fn drop(&mut self) {
if let Err(e) = self.record() {
if let Err(e) = self.record(&[]) {
tracing::error!("metrics client error: {}", e);
}
}
@ -31,12 +31,10 @@ impl Timer {
}
}
pub fn record(&self) -> Result<()> {
let tags = self
.tags
.iter()
.map(|(k, v)| (k.as_str(), v.as_str()))
.collect::<Vec<_>>();
pub fn record(&self, additional_tags: &[(&str, &str)]) -> Result<()> {
let mut tags = Vec::with_capacity(self.tags.len() + additional_tags.len());
tags.extend(additional_tags);
tags.extend(self.tags.iter().map(|(k, v)| (k.as_str(), v.as_str())));
self.client
.record_duration(&self.name, self.start_time.elapsed(), &tags)
}