Skip to content

Add propertiesSupplier support to EmfMetricLoggingPublisher#6735

Open
humanzz wants to merge 1 commit intoaws:masterfrom
humanzz:emf-props-supplier
Open

Add propertiesSupplier support to EmfMetricLoggingPublisher#6735
humanzz wants to merge 1 commit intoaws:masterfrom
humanzz:emf-props-supplier

Conversation

@humanzz
Copy link

@humanzz humanzz commented Feb 13, 2026

Closes #6595

Enable EmfMetricLoggingPublisher to accept an optional Supplier<Map<String, String>> for enriching EMF records with custom properties at publish time.

Motivation and Context

Users of EmfMetricLoggingPublisher have no way to add custom metadata (e.g. Lambda request IDs, trace IDs) to EMF records. The aws-embedded-metrics-java library supports this via putProperty(), but the SDK's built-in publisher does not. This change adds a propertiesSupplier to the builder, evaluated on each publish() call, allowing dynamic enrichment of EMF output with searchable properties in CloudWatch Logs Insights.

Modifications

  • Add propertiesSupplier field and builder method to EmfMetricLoggingPublisher.Builder
  • Add propertiesSupplier field, accessor, and builder setter to EmfMetricConfiguration, defaulting to empty map when null
  • Add resolveProperties() to MetricEmfConverter which invokes the supplier from config once per convert call, handling null returns and exceptions gracefully
  • Add writeCustomProperties() to MetricEmfConverter which writes properties first in the EMF JSON so _aws, dimensions, and metrics overwrite any key collisions

Testing

Added 7 tests to MetricEmfConverterTest:

  • Custom properties appear in EMF output
  • No supplier configured produces identical output to current behavior
  • Empty properties map produces no extra keys
  • Property key matching _aws is overwritten by the real _aws object
  • Property key matching a dimension name is overwritten by the real dimension value
  • Property key matching a metric name is overwritten by the real metric value
  • Batched EMF records (220 metrics, 3 batches) all contain custom properties

Added 3 tests to EmfMetricLoggingPublisherTest:

  • Supplier throwing exception logs warning and publishes without custom properties
  • Supplier returning null publishes without custom properties
  • Stateful supplier returns different maps on successive publish calls

All 26 tests pass. mvn clean install -pl :emf-metric-logging-publisher succeeds (compile, checkstyle, tests, javadoc, API compatibility).

Screenshots (if appropriate)

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

Enable `EmfMetricLoggingPublisher` to accept an optional `Supplier<Map<String, String>>` for enriching EMF records with custom properties at publish time

- Add `propertiesSupplier` field and builder method to `EmfMetricLoggingPublisher.Builder`
- Add `propertiesSupplier` field, accessor, and builder setter to `EmfMetricConfiguration`, defaulting to empty map when null
- Add `resolveProperties()` to `MetricEmfConverter` which invokes the supplier from config once per convert call, handling null returns and exceptions gracefully
- Add `writeCustomProperties()` to `MetricEmfConverter` which writes properties first in the EMF JSON so `_aws`, dimensions, and metrics overwrite any key collisions

Closes aws#6595
@humanzz humanzz requested a review from a team as a code owner February 13, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable setting properties to enrich the emf records emitted by EmfMetricLoggingPublisher

1 participant