Skip to content

Commit 60ca3a4

Browse files
committed
fix(metrics) use same naming for serviceName
1 parent 83bf7f4 commit 60ca3a4

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

Diff for: packages/metrics/src/Metrics.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const DEFAULT_NAMESPACE = 'default_namespace';
4242
* import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
4343
* import { Callback, Context } from 'aws-lambda';
4444
*
45-
* const metrics = new Metrics({namespace:"MyService", service:"withDecorator"});
45+
* const metrics = new Metrics({namespace:"MyService", serviceName:"withDecorator"});
4646
*
4747
* export class MyFunctionWithDecorator {
4848
*
@@ -69,7 +69,7 @@ const DEFAULT_NAMESPACE = 'default_namespace';
6969
* ```typescript
7070
* import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
7171
*
72-
* const metrics = new Metrics({namespace: "MyService", service: "MyFunction"});
72+
* const metrics = new Metrics({namespace: "MyService", serviceName: "MyFunction"});
7373
*
7474
* export const handler = async (_event: any, _context: any) => {
7575
* metrics.captureColdStart();
@@ -163,7 +163,7 @@ class Metrics implements MetricsInterface {
163163
* import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
164164
* import { Context } from 'aws-lambda';
165165
*
166-
* const metrics = new Metrics({namespace:"serverlessAirline", service:"orders"});
166+
* const metrics = new Metrics({namespace:"serverlessAirline", serviceName:"orders"});
167167
*
168168
* export const handler = async (event: any, context: Context) => {
169169
* metrics.captureColdStartMetric();
@@ -209,7 +209,7 @@ class Metrics implements MetricsInterface {
209209
* import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
210210
* import { Callback, Context } from 'aws-lambda';
211211
*
212-
* const metrics = new Metrics({namespace:"CDKExample", service:"withDecorator"});
212+
* const metrics = new Metrics({namespace:"CDKExample", serviceName:"withDecorator"});
213213
*
214214
* export class MyFunctionWithDecorator {
215215
*
@@ -260,7 +260,7 @@ class Metrics implements MetricsInterface {
260260
* ```typescript
261261
* import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
262262
*
263-
* const metrics = new Metrics({namespace: "CDKExample", service: "MyFunction"}); // Sets metric namespace, and service as a metric dimension
263+
* const metrics = new Metrics({namespace: "CDKExample", serviceName: "MyFunction"}); // Sets metric namespace, and service as a metric dimension
264264
*
265265
* export const handler = async (_event: any, _context: any) => {
266266
* metrics.addMetric('test-metric', MetricUnits.Count, 10);
@@ -283,7 +283,7 @@ class Metrics implements MetricsInterface {
283283
* import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
284284
* import { Context } from 'aws-lambda';
285285
*
286-
* const metrics = new Metrics({namespace:"serverlessAirline", service:"orders"});
286+
* const metrics = new Metrics({namespace:"serverlessAirline", serviceName:"orders"});
287287
*
288288
* export const handler = async (event: any, context: Context) => {
289289
* metrics.raiseOnEmptyMetrics();
@@ -373,7 +373,7 @@ class Metrics implements MetricsInterface {
373373
public singleMetric(): Metrics {
374374
return new Metrics({
375375
namespace: this.namespace,
376-
service: this.dimensions.service,
376+
serviceName: this.dimensions.service,
377377
defaultDimensions: this.defaultDimensions,
378378
singleMetric: true,
379379
});
@@ -420,12 +420,12 @@ class Metrics implements MetricsInterface {
420420
}
421421

422422
private setOptions(options: MetricsOptions): Metrics {
423-
const { customConfigService, namespace, service, singleMetric, defaultDimensions } = options;
423+
const { customConfigService, namespace, serviceName, singleMetric, defaultDimensions } = options;
424424

425425
this.setEnvVarsService();
426426
this.setCustomConfigService(customConfigService);
427427
this.setNamespace(namespace);
428-
this.setService(service);
428+
this.setService(serviceName);
429429
this.setDefaultDimensions(defaultDimensions);
430430
this.isSingleMetric = singleMetric || false;
431431

Diff for: packages/metrics/src/types/Metrics.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Dimensions = { [key: string]: string };
88
type MetricsOptions = {
99
customConfigService?: ConfigServiceInterface
1010
namespace?: string
11-
service?: string
11+
serviceName?: string
1212
singleMetric?: boolean
1313
defaultDimensions?: Dimensions
1414
};

Diff for: packages/metrics/tests/e2e/standardFunctions.test.MyFunction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const singleMetricName = process.env.EXPECTED_SINGLE_METRIC_NAME ?? 'MySingleMet
1313
const singleMetricUnit = (process.env.EXPECTED_SINGLE_METRIC_UNIT as MetricUnits) ?? MetricUnits.Percent;
1414
const singleMetricValue = process.env.EXPECTED_SINGLE_METRIC_VALUE ?? '2';
1515

16-
const metrics = new Metrics({ namespace: namespace, service: serviceName });
16+
const metrics = new Metrics({ namespace: namespace, serviceName: serviceName });
1717

1818
export const handler = async (_event: unknown, _context: Context): Promise<void> => {
1919
metrics.captureColdStartMetric();

Diff for: packages/metrics/tests/unit/Metrics.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('Class: Metrics', () => {
4848
test('should log service dimension correctly when passed', () => {
4949
const serviceName = 'testing_name';
5050

51-
const metrics = new Metrics({ namespace: 'test', service: serviceName });
51+
const metrics = new Metrics({ namespace: 'test', serviceName: serviceName });
5252
metrics.addMetric('test_name', MetricUnits.Seconds, 14);
5353
const loggedData = metrics.serializeMetrics();
5454

@@ -286,7 +286,7 @@ describe('Class: Metrics', () => {
286286

287287
test('Cold should have service and function name if present', async () => {
288288
const serviceName = 'test-service';
289-
const metrics = new Metrics({ namespace: 'test', service: serviceName });
289+
const metrics = new Metrics({ namespace: 'test', serviceName: serviceName });
290290

291291
class LambdaFunction implements LambdaInterface {
292292
@metrics.logMetrics({ captureColdStartMetric: true })
@@ -316,7 +316,7 @@ describe('Class: Metrics', () => {
316316

317317
test('Cold should still log, without a function name', async () => {
318318
const serviceName = 'test-service';
319-
const metrics = new Metrics({ namespace: 'test', service: serviceName });
319+
const metrics = new Metrics({ namespace: 'test', serviceName: serviceName });
320320
const newDummyContext = JSON.parse(JSON.stringify(dummyContext));
321321
delete newDummyContext.functionName;
322322
class LambdaFunction implements LambdaInterface {

Diff for: packages/metrics/tests/unit/middleware/middy.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('Middy middleware', () => {
4545

4646
test('when a metrics instance receive multiple metrics with the same name, it prints multiple values in an array format', async () => {
4747
// Prepare
48-
const metrics = new Metrics({ namespace:'serverlessAirline', service:'orders' });
48+
const metrics = new Metrics({ namespace:'serverlessAirline', serviceName:'orders' });
4949

5050
const lambdaHandler = (): void => {
5151
metrics.addMetric('successfulBooking', MetricUnits.Count, 2);
@@ -80,7 +80,7 @@ describe('Middy middleware', () => {
8080
test('when a metrics instance is passed WITH custom options, it prints the metrics in the stdout', async () => {
8181

8282
// Prepare
83-
const metrics = new Metrics({ namespace:'serverlessAirline', service:'orders' });
83+
const metrics = new Metrics({ namespace:'serverlessAirline', serviceName:'orders' });
8484

8585
const lambdaHandler = (): void => {
8686
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
@@ -135,7 +135,7 @@ describe('Middy middleware', () => {
135135
test('when a metrics instance is passed WITHOUT custom options, it prints the metrics in the stdout', async () => {
136136

137137
// Prepare
138-
const metrics = new Metrics({ namespace:'serverlessAirline', service:'orders' });
138+
const metrics = new Metrics({ namespace:'serverlessAirline', serviceName:'orders' });
139139

140140
const lambdaHandler = (): void => {
141141
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);
@@ -167,7 +167,7 @@ describe('Middy middleware', () => {
167167
test('when an array of Metrics instances is passed, it prints the metrics in the stdout', async () => {
168168

169169
// Prepare
170-
const metrics = new Metrics({ namespace:'serverlessAirline', service:'orders' });
170+
const metrics = new Metrics({ namespace:'serverlessAirline', serviceName:'orders' });
171171

172172
const lambdaHandler = (): void => {
173173
metrics.addMetric('successfulBooking', MetricUnits.Count, 1);

0 commit comments

Comments
 (0)