From d1abd7fe7e849b0545df997a7361155129c1a01d Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Tue, 8 Nov 2022 15:28:10 +0100 Subject: [PATCH 1/3] fix: store service name in defaultDimensions --- packages/metrics/src/Metrics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/metrics/src/Metrics.ts b/packages/metrics/src/Metrics.ts index 48ba88cd78..3011dc92d5 100644 --- a/packages/metrics/src/Metrics.ts +++ b/packages/metrics/src/Metrics.ts @@ -455,7 +455,7 @@ class Metrics extends Utility implements MetricsInterface { this.getCustomConfigService()?.getServiceName() || this.getEnvVarsService().getServiceName()) as string; if (targetService.length > 0) { - this.addDimension('service', targetService); + this.setDefaultDimensions({ service: targetService }); } } From 5f9ffc1cc0789907dc839f64f182ed9a12e59d98 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Tue, 8 Nov 2022 15:45:23 +0100 Subject: [PATCH 2/3] fix: changed behavior also in singleMetric --- packages/metrics/src/Metrics.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/metrics/src/Metrics.ts b/packages/metrics/src/Metrics.ts index 3011dc92d5..17f6f946bd 100644 --- a/packages/metrics/src/Metrics.ts +++ b/packages/metrics/src/Metrics.ts @@ -177,8 +177,8 @@ class Metrics extends Utility implements MetricsInterface { if (!this.isColdStart()) return; const singleMetric = this.singleMetric(); - if (this.dimensions.service) { - singleMetric.addDimension('service', this.dimensions.service); + if (this.defaultDimensions.service) { + singleMetric.setDefaultDimensions({ service: this.defaultDimensions.service }); } if (this.functionName != null) { singleMetric.addDimension('function_name', this.functionName); From ef49171481fd4645704e20ae25361a56b2e985d6 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Tue, 8 Nov 2022 15:45:38 +0100 Subject: [PATCH 3/3] chore: unit test --- packages/metrics/tests/unit/middleware/middy.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/metrics/tests/unit/middleware/middy.test.ts b/packages/metrics/tests/unit/middleware/middy.test.ts index a31cb20d5e..ced312f1e3 100644 --- a/packages/metrics/tests/unit/middleware/middy.test.ts +++ b/packages/metrics/tests/unit/middleware/middy.test.ts @@ -247,14 +247,14 @@ describe('Middy middleware', () => { CloudWatchMetrics: [ { Namespace: 'serverlessAirline', - Dimensions: [[ 'environment', 'aws_region', 'service', 'function_name' ]], + Dimensions: [[ 'service', 'environment', 'aws_region', 'function_name' ]], Metrics: [{ Name: 'ColdStart', Unit: 'Count' }], }, ], }, + service: 'orders', environment: 'prod', aws_region: 'eu-west-1', - service: 'orders', function_name: 'foo-bar-function', ColdStart: 1, }) @@ -267,14 +267,14 @@ describe('Middy middleware', () => { CloudWatchMetrics: [ { Namespace: 'serverlessAirline', - Dimensions: [[ 'environment', 'aws_region', 'service' ]], + Dimensions: [[ 'service', 'environment', 'aws_region' ]], Metrics: [{ Name: 'successfulBooking', Unit: 'Count' }], }, ], }, + service: 'orders', environment: 'prod', aws_region: 'eu-west-1', - service: 'orders', successfulBooking: 1, }) );