Skip to content

Commit

Permalink
Fix metrics attribute types
Browse files Browse the repository at this point in the history
Metrics attributes were being coerced to strings. This is now fixed.
In addition, the logic around types accepted as metrics attributes has been simplified. It will log and ignore values of the wrong type.

Fixes #3691
  • Loading branch information
bryn authored and garypen committed Sep 12, 2023
1 parent 4ebf850 commit 4109a2e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changesets/fix_bryn_fix_metrics_typing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Fix metrics attribute types ([Issue #3687](https://github.com/apollographql/router/issues/3687))

Metrics attributes were being coerced to strings. This is now fixed.
In addition, the logic around types accepted as metrics attributes has been simplified. It will log and ignore values of the wrong type.

By [@BrynCooke](https://github.com/BrynCooke) in https://github.com/apollographql/router/pull/3701
15 changes: 12 additions & 3 deletions apollo-router/src/plugins/telemetry/metrics/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ impl<'a> Visit for MetricVisitor<'a> {

fn record_i64(&mut self, field: &Field, value: i64) {
if let Some(metric_name) = field.name().strip_prefix(METRIC_PREFIX_MONOTONIC_COUNTER) {
tracing::error!(metric_name, "monotonic counter must be u64");
tracing::error!(
metric_name,
"monotonic counter must be u64, this metric will be ignored"
);
} else if let Some(metric_name) = field.name().strip_prefix(METRIC_PREFIX_COUNTER) {
self.metric = Some((metric_name, InstrumentType::UpDownCounterI64(value)));
} else if let Some(metric_name) = field.name().strip_prefix(METRIC_PREFIX_HISTOGRAM) {
Expand All @@ -201,11 +204,17 @@ impl<'a> Visit for MetricVisitor<'a> {
}

fn record_i128(&mut self, field: &Field, _value: i128) {
tracing::error!(name = field.name(), "metric attribute cannot be i128");
tracing::error!(
name = field.name(),
"metric attribute cannot be i128, this attribute will be ignored"
);
}

fn record_u128(&mut self, field: &Field, _value: u128) {
tracing::error!(name = field.name(), "metric attribute cannot be u128");
tracing::error!(
name = field.name(),
"metric attribute cannot be u128, this attribute will be ignored"
);
}

fn record_bool(&mut self, field: &Field, value: bool) {
Expand Down

0 comments on commit 4109a2e

Please sign in to comment.