Skip to content

fix(metrics): detect key collisions between dimensions, metrics, and metadata#5240

Open
Zelys-DFKH wants to merge 1 commit into
aws-powertools:mainfrom
Zelys-DFKH:fix/metrics-key-collision-detection
Open

fix(metrics): detect key collisions between dimensions, metrics, and metadata#5240
Zelys-DFKH wants to merge 1 commit into
aws-powertools:mainfrom
Zelys-DFKH:fix/metrics-key-collision-detection

Conversation

@Zelys-DFKH
Copy link
Copy Markdown
Contributor

Summary

Changes

Closes #5208. In serializeMetrics(), EMF output is assembled by spreading default dimensions, dimensions, dimension sets, metric values, and metadata in that order. When keys match across those layers, later values win silently. Two of those collisions break the EMF schema:

  • A metric name matching a dimension key replaces the string value with a number, so CloudWatch drops the dimension.
  • A metadata key matching a metric name replaces the number with a string, so CloudWatch fails to parse the metric.

What changed

  • Metrics.ts: Added a guard in storeMetric() that throws when the metric name matches any current dimension key (flat dimensions, default dimensions, or dimension sets), and a guard in addMetadata() that throws when the metadata key matches any current metric name. Both error messages include the key name.
  • dimensions.test.ts: Four new tests covering a regular dimension conflict, a default dimension conflict, a dimension-set conflict (via addDimensions), and the built-in service dimension.
  • metadata.test.ts: One new test covering a metadata-metric name conflict.

Issue number: Closes #5208


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M PR between 30-99 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: No collision detection between dimension keys, metric names, and metadata keys in EMF output

1 participant