@@ -273,8 +273,12 @@ class Metrics extends Utility implements MetricsInterface {
273
273
* @param dimensions - An object with key-value pairs of dimensions
274
274
*/
275
275
public addDimensions ( dimensions : Dimensions ) : void {
276
+ const newDimensionKeys = Object . keys ( dimensions ) . filter (
277
+ ( key ) => ! this . defaultDimensions [ key ] && ! this . dimensions [ key ]
278
+ ) ;
279
+
276
280
if (
277
- Object . keys ( dimensions ) . length + this . getCurrentDimensionsCount ( ) >=
281
+ newDimensionKeys . length + this . getCurrentDimensionsCount ( ) >=
278
282
MAX_DIMENSION_COUNT
279
283
) {
280
284
throw new RangeError (
@@ -707,31 +711,28 @@ class Metrics extends Utility implements MetricsInterface {
707
711
708
712
const dimensionNames = [ ] ;
709
713
714
+ const allDimensionKeys = new Set ( [
715
+ ...Object . keys ( this . defaultDimensions ) ,
716
+ ...Object . keys ( this . dimensions ) ,
717
+ ] ) ;
718
+
710
719
if ( Object . keys ( this . dimensions ) . length > 0 ) {
711
- dimensionNames . push ( [
712
- ...new Set ( [
713
- ...Object . keys ( this . defaultDimensions ) ,
714
- ...Object . keys ( this . dimensions ) ,
715
- ] ) ,
716
- ] ) ;
720
+ dimensionNames . push ( [ ...allDimensionKeys ] ) ;
717
721
}
718
722
719
723
for ( const dimensionSet of this . dimensionSets ) {
720
- dimensionNames . push ( [
721
- ...new Set ( [
722
- ...Object . keys ( this . defaultDimensions ) ,
723
- ...Object . keys ( dimensionSet ) ,
724
- ] ) ,
724
+ const dimensionSetKeys = new Set ( [
725
+ ...Object . keys ( this . defaultDimensions ) ,
726
+ ...Object . keys ( dimensionSet ) ,
725
727
] ) ;
728
+ dimensionNames . push ( [ ...dimensionSetKeys ] ) ;
726
729
}
727
730
728
731
if (
729
732
dimensionNames . length === 0 &&
730
733
Object . keys ( this . defaultDimensions ) . length > 0
731
734
) {
732
- dimensionNames . push ( [
733
- ...new Set ( [ ...Object . keys ( this . defaultDimensions ) ] ) ,
734
- ] ) ;
735
+ dimensionNames . push ( [ ...Object . keys ( this . defaultDimensions ) ] ) ;
735
736
}
736
737
737
738
return {
@@ -745,11 +746,14 @@ class Metrics extends Utility implements MetricsInterface {
745
746
} ,
746
747
] ,
747
748
} ,
748
- ...this . defaultDimensions ,
749
- ...this . dimensions ,
750
- ...this . dimensionSets . reduce ( ( acc , dims ) => Object . assign ( acc , dims ) , { } ) ,
751
- ...metricValues ,
752
- ...this . metadata ,
749
+ ...Object . assign (
750
+ { } ,
751
+ this . defaultDimensions ,
752
+ this . dimensions ,
753
+ this . dimensionSets . reduce ( ( acc , dims ) => Object . assign ( acc , dims ) , { } ) ,
754
+ metricValues ,
755
+ this . metadata
756
+ ) ,
753
757
} ;
754
758
}
755
759
0 commit comments