feat: record timer with additional tags (#9529)
This commit is contained in:
parent
9ec20ba065
commit
a3a97f3ea9
1 changed files with 5 additions and 7 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue