Skip to content

Commit

Permalink
Fix missing StatsdClient tags for distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsig727 committed May 22, 2023
1 parent 466fecf commit 9b45956
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cadence/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,8 @@ where
{
fn distribution_with_tags<'a>(&'a self, key: &'a str, value: T) -> MetricBuilder<'_, '_, Distribution> {
match value.try_to_value() {
Ok(v) => MetricBuilder::from_fmt(MetricFormatter::distribution(&self.prefix, key, v), self),
Ok(v) => MetricBuilder::from_fmt(MetricFormatter::distribution(&self.prefix, key, v), self)
.with_tags(self.tags()),
Err(e) => MetricBuilder::from_error(e, self),
}
}
Expand Down Expand Up @@ -1430,6 +1431,23 @@ mod tests {
);
}

#[test]
fn test_statsd_client_distribution_with_default_tags() {
let client = StatsdClientBuilder::new("prefix", NopMetricSink)
.with_tag("foo", "bar")
.build();
let res = client
.distribution_with_tags("some.distr", 27)
.with_tag("host", "www03.example.com")
.with_tag_value("rc1")
.try_send();

assert_eq!(
"prefix.some.distr:27|d|#foo:bar,host:www03.example.com,rc1",
res.unwrap().as_metric_str()
);
}

#[test]
fn test_statsd_client_distribution_multiple_values_with_tags() {
let client = StatsdClient::from_sink("prefix", NopMetricSink);
Expand Down

0 comments on commit 9b45956

Please sign in to comment.