1
1
import type { Callback , Context , Handler } from 'aws-lambda' ;
2
2
import { Utility } from '@aws-lambda-powertools/commons' ;
3
- import type { MetricsInterface } from './MetricsInterface' ;
4
- import {
5
- type ConfigServiceInterface ,
6
- EnvironmentVariablesService ,
7
- } from './config' ;
3
+ import type { HandlerMethodDecorator } from '@aws-lambda-powertools/commons/types' ;
4
+ import { EnvironmentVariablesService } from './config/EnvironmentVariablesService.js' ;
8
5
import {
9
6
MAX_DIMENSION_COUNT ,
10
7
MAX_METRICS_SIZE ,
11
8
DEFAULT_NAMESPACE ,
12
9
COLD_START_METRIC ,
13
10
MAX_METRIC_VALUES_SIZE ,
14
- } from './constants' ;
11
+ MetricUnit as MetricUnits ,
12
+ MetricResolution as MetricResolutions ,
13
+ } from './constants.js' ;
15
14
import {
16
- MetricsOptions ,
17
- Dimensions ,
18
- EmfOutput ,
19
- HandlerMethodDecorator ,
20
- StoredMetrics ,
21
- ExtraOptions ,
22
- MetricUnit ,
23
- MetricUnits ,
24
- MetricResolution ,
25
- MetricDefinition ,
26
- } from './types' ;
15
+ type MetricsOptions ,
16
+ type Dimensions ,
17
+ type EmfOutput ,
18
+ type StoredMetrics ,
19
+ type ExtraOptions ,
20
+ type MetricDefinition ,
21
+ type ConfigServiceInterface ,
22
+ type MetricsInterface ,
23
+ type MetricUnit ,
24
+ type MetricResolution ,
25
+ } from './types/index.js ' ;
27
26
28
27
/**
29
28
* ## Intro
@@ -83,7 +82,7 @@ import {
83
82
* @metrics .logMetrics({ captureColdStartMetric: true, throwOnEmptyMetrics: true })
84
83
* public handler(_event: any, _context: any): Promise<void> {
85
84
* // ...
86
- * metrics.addMetric('test-metric', MetricUnits .Count, 10);
85
+ * metrics.addMetric('test-metric', MetricUnit .Count, 10);
87
86
* // ...
88
87
* }
89
88
* }
@@ -99,13 +98,13 @@ import {
99
98
* @example
100
99
*
101
100
* ```typescript
102
- * import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
101
+ * import { Metrics, MetricUnit } from '@aws-lambda-powertools/metrics';
103
102
*
104
103
* const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });
105
104
*
106
105
* export const handler = async (_event: any, _context: any): Promise<void> => {
107
106
* metrics.captureColdStartMetric();
108
- * metrics.addMetric('test-metric', MetricUnits .Count, 10);
107
+ * metrics.addMetric('test-metric', MetricUnit .Count, 10);
109
108
* metrics.publishStoredMetrics();
110
109
* };
111
110
* ```
@@ -188,15 +187,15 @@ class Metrics extends Utility implements MetricsInterface {
188
187
* or when calling {@link Metrics.publishStoredMetrics}.
189
188
*
190
189
* You can add a metric by specifying the metric name, unit, and value. For convenience,
191
- * we provide a set of constants for the most common units in {@link MetricUnits }.
190
+ * we provide a set of constants for the most common units in {@link MetricUnit }.
192
191
*
193
192
* @example
194
193
* ```typescript
195
- * import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
194
+ * import { Metrics, MetricUnit } from '@aws-lambda-powertools/metrics';
196
195
*
197
196
* const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });
198
197
*
199
- * metrics.addMetric('successfulBooking', MetricUnits .Count, 1);
198
+ * metrics.addMetric('successfulBooking', MetricUnit .Count, 1);
200
199
* ```
201
200
*
202
201
* Optionally, you can specify the metric resolution, which can be either `High` or `Standard`.
@@ -205,11 +204,11 @@ class Metrics extends Utility implements MetricsInterface {
205
204
*
206
205
* @example
207
206
* ```typescript
208
- * import { Metrics, MetricUnits , MetricResolution } from '@aws-lambda-powertools/metrics';
207
+ * import { Metrics, MetricUnit , MetricResolution } from '@aws-lambda-powertools/metrics';
209
208
*
210
209
* const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });
211
210
*
212
- * metrics.addMetric('successfulBooking', MetricUnits .Count, 1, MetricResolution.High);
211
+ * metrics.addMetric('successfulBooking', MetricUnit .Count, 1, MetricResolution.High);
213
212
* ```
214
213
*
215
214
* @param name - The metric name
@@ -221,7 +220,7 @@ class Metrics extends Utility implements MetricsInterface {
221
220
name : string ,
222
221
unit : MetricUnit ,
223
222
value : number ,
224
- resolution : MetricResolution = MetricResolution . Standard
223
+ resolution : MetricResolution = MetricResolutions . Standard
225
224
) : void {
226
225
this . storeMetric ( name , unit , value , resolution ) ;
227
226
if ( this . isSingleMetric ) this . publishStoredMetrics ( ) ;
@@ -369,12 +368,12 @@ class Metrics extends Utility implements MetricsInterface {
369
368
* @example
370
369
*
371
370
* ```typescript
372
- * import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
371
+ * import { Metrics, MetricUnit } from '@aws-lambda-powertools/metrics';
373
372
*
374
373
* const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' }); // Sets metric namespace, and service as a metric dimension
375
374
*
376
375
* export const handler = async (_event: any, _context: any): Promise<void> => {
377
- * metrics.addMetric('test-metric', MetricUnits .Count, 10);
376
+ * metrics.addMetric('test-metric', MetricUnit .Count, 10);
378
377
* metrics.publishStoredMetrics();
379
378
* };
380
379
* ```
@@ -413,7 +412,7 @@ class Metrics extends Utility implements MetricsInterface {
413
412
) . map ( ( metricDefinition ) => ( {
414
413
Name : metricDefinition . name ,
415
414
Unit : metricDefinition . unit ,
416
- ...( metricDefinition . resolution === MetricResolution . High
415
+ ...( metricDefinition . resolution === MetricResolutions . High
417
416
? { StorageResolution : metricDefinition . resolution }
418
417
: { } ) ,
419
418
} ) ) ;
@@ -499,7 +498,7 @@ class Metrics extends Utility implements MetricsInterface {
499
498
* ```typescript
500
499
* const singleMetric = metrics.singleMetric();
501
500
* singleMetric.addDimension('InnerDimension', 'true');
502
- * singleMetric.addMetric('single-metric', MetricUnits .Percent, 50);
501
+ * singleMetric.addMetric('single-metric', MetricUnit .Percent, 50);
503
502
* ```
504
503
*
505
504
* @returns the Metrics
@@ -706,4 +705,4 @@ class Metrics extends Utility implements MetricsInterface {
706
705
}
707
706
}
708
707
709
- export { Metrics , MetricUnits , MetricResolution } ;
708
+ export { Metrics } ;
0 commit comments