Skip to content

Commit 53497c6

Browse files
Simplify dimension addition - remove ordering logic
Use push() instead of unshift/splice to add Service and Environment dimensions without enforcing specific position in the dimensions array. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6256774 commit 53497c6

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/src/exporter/aws/metrics/emf-exporter-base.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ export abstract class EMFExporterBase implements PushMetricExporter {
269269
serviceName = String(serviceAttr);
270270
}
271271
}
272-
dimensionNames.unshift(SERVICE_DIMENSION);
272+
dimensionNames.push(SERVICE_DIMENSION);
273273
emfLog[SERVICE_DIMENSION] = serviceName;
274274
}
275275

@@ -298,9 +298,7 @@ export abstract class EMFExporterBase implements PushMetricExporter {
298298
environment = this.getDefaultEnvironmentForPlatform(resource);
299299
}
300300

301-
// Insert after Service if present, otherwise at beginning
302-
const insertIndex = dimensionNames.includes(SERVICE_DIMENSION) ? 1 : 0;
303-
dimensionNames.splice(insertIndex, 0, ENVIRONMENT_DIMENSION);
301+
dimensionNames.push(ENVIRONMENT_DIMENSION);
304302
emfLog[ENVIRONMENT_DIMENSION] = environment;
305303
}
306304
}

aws-distro-opentelemetry-node-autoinstrumentation/test/exporter/aws/metrics/aws-cloudwatch-emf-exporter.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,8 +1013,8 @@ describe('TestAWSCloudWatchEMFExporter', () => {
10131013
expect(result).toHaveProperty('Environment', 'new-env');
10141014
});
10151015

1016-
it('TestDimensionOrderServiceThenEnvironment', () => {
1017-
/* Test that Service comes before Environment in dimensions array. */
1016+
it('TestDimensionsAddedAlongsideExisting', () => {
1017+
/* Test that Service and Environment are added alongside existing dimensions. */
10181018
process.env['OTEL_METRICS_ADD_APPLICATION_SIGNALS_DIMENSIONS'] = 'true';
10191019

10201020
const gaugeRecord: MetricRecord = {
@@ -1026,10 +1026,10 @@ describe('TestAWSCloudWatchEMFExporter', () => {
10261026
const result = exporter['createEmfLog']([gaugeRecord], resource, 1234567890);
10271027

10281028
const cwMetrics = result._aws.CloudWatchMetrics[0];
1029-
// Dimensions should be: ['Service', 'Environment', 'existing_dim']
1030-
expect(cwMetrics.Dimensions![0][0]).toEqual('Service');
1031-
expect(cwMetrics.Dimensions![0][1]).toEqual('Environment');
1032-
expect(cwMetrics.Dimensions![0][2]).toEqual('existing_dim');
1029+
// All three dimensions should be present
1030+
expect(cwMetrics.Dimensions![0]).toContain('Service');
1031+
expect(cwMetrics.Dimensions![0]).toContain('Environment');
1032+
expect(cwMetrics.Dimensions![0]).toContain('existing_dim');
10331033
});
10341034

10351035
it('TestEnvVarCaseInsensitive', () => {

0 commit comments

Comments
 (0)