Skip to content

fix(metrics): Do not flush when no metrics were added to avoid printing root-level _aws dict #1891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2025

Conversation

phipag
Copy link
Contributor

@phipag phipag commented Jun 16, 2025

Issue #, if available: #1890

Description of changes:

Flushing without metrics has unexpected behavior in the aws-embedded-metrics library. It prints the root-level section of the _aws EMF dict to STDOUT which we don't want. We want to log a simple warning only.

Before:

{"Service":"payment","logStreamId":"$LATEST","functionVersion":"$LATEST","executionEnvironment":"AWS_Lambda_java11"}

After:

// No output

I added a unit test catching this bug.

Note: The PMD linting about Empty Catch Blocks is expected. We don't want to bubble up EMF exceptions to the consumer because we already do our own validation.

Checklist

Copy link

@phipag phipag merged commit 8a040ac into main Jun 16, 2025
15 checks passed
@phipag phipag deleted the phipag/issue1890 branch June 16, 2025 15:00
@github-project-automation github-project-automation bot moved this from Pending review to Coming soon in Powertools for AWS Lambda (Java) Jun 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working metrics size/S
Projects
Status: Coming soon
Development

Successfully merging this pull request may close these issues.

Bug: EMF Metrics Logger emits root dict without metrics when no metrics are added
2 participants