Skip to content

Commit 4fcbf3c

Browse files
committed
fix(metrics): Do not flush when no metrics were added to avoid printing root-level _aws dict.
1 parent 0b27594 commit 4fcbf3c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/internal/EmfMetricsLogger.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ public void flush() {
164164
} else {
165165
LOGGER.warn("No metrics were emitted");
166166
}
167+
} else {
168+
emfLogger.flush();
167169
}
168-
emfLogger.flush();
169170
}
170171

171172
@Override

powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/internal/EmfMetricsLoggerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ void shouldLogWarningOnEmptyMetrics() throws Exception {
348348
// Read the log file and check for the warning
349349
String logContent = new String(Files.readAllBytes(logFile.toPath()), StandardCharsets.UTF_8);
350350
assertThat(logContent).contains("No metrics were emitted");
351+
// No EMF output should be generated
352+
assertThat(outputStreamCaptor.toString().trim()).isEmpty();
351353
}
352354

353355
@Test

0 commit comments

Comments
 (0)