File tree Expand file tree Collapse file tree 2 files changed +5
-3
lines changed
main/java/software/amazon/lambda/powertools/metrics/internal
test/java/software/amazon/lambda/powertools/metrics/internal Expand file tree Collapse file tree 2 files changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -81,8 +81,6 @@ public void addDimension(software.amazon.lambda.powertools.metrics.model.Dimensi
8181 dimensionSet .getDimensions ().forEach ((key , val ) -> {
8282 try {
8383 emfDimensionSet .addDimension (key , val );
84- // Update our local copy of default dimensions
85- defaultDimensions .put (key , val );
8684 } catch (Exception e ) {
8785 // Ignore dimension errors
8886 }
@@ -234,7 +232,9 @@ public void flushMetrics(Consumer<Metrics> metricsConsumer) {
234232 if (namespace != null ) {
235233 metrics .setNamespace (this .namespace );
236234 }
237- defaultDimensions .forEach (metrics ::addDimension );
235+ if (!defaultDimensions .isEmpty ()) {
236+ metrics .setDefaultDimensions (software .amazon .lambda .powertools .metrics .model .DimensionSet .of (defaultDimensions ));
237+ }
238238 metadata .forEach (metrics ::addMetadata );
239239
240240 metricsConsumer .accept (metrics );
Original file line number Diff line number Diff line change @@ -451,6 +451,7 @@ void shouldFlushMetrics() throws Exception {
451451 // Given
452452 metrics .setNamespace ("MainNamespace" );
453453 metrics .setDefaultDimensions (DimensionSet .of ("CustomDim" , "CustomValue" ));
454+ metrics .addDimension (DimensionSet .of ("CustomDim2" , "CustomValue2" ));
454455 metrics .addMetadata ("CustomMetadata" , "MetadataValue" );
455456
456457 // When
@@ -469,6 +470,7 @@ void shouldFlushMetrics() throws Exception {
469470 assertThat (rootNode .get ("metric-two" ).asDouble ()).isEqualTo (100 );
470471 assertThat (rootNode .has ("CustomDim" )).isTrue ();
471472 assertThat (rootNode .get ("CustomDim" ).asText ()).isEqualTo ("CustomValue" );
473+ assertThat (rootNode .get ("CustomDim2" )).isNull ();
472474 assertThat (rootNode .get ("_aws" ).get ("CloudWatchMetrics" ).get (0 ).get ("Namespace" ).asText ())
473475 .isEqualTo ("MainNamespace" );
474476 assertThat (rootNode .get ("_aws" ).has ("CustomMetadata" )).isTrue ();
You can’t perform that action at this time.
0 commit comments