1
1
import type { Callback , Context , Handler } from 'aws-lambda' ;
2
2
import { Console } from 'node:console' ;
3
3
import { Utility } from '@aws-lambda-powertools/commons' ;
4
- import type { MetricsInterface } from './MetricsInterface' ;
5
- import {
6
- type ConfigServiceInterface ,
7
- EnvironmentVariablesService ,
8
- } from './config' ;
4
+ import type { HandlerMethodDecorator } from '@aws-lambda-powertools/commons/types' ;
5
+ import { EnvironmentVariablesService } from './config/EnvironmentVariablesService.js' ;
9
6
import {
10
7
MAX_DIMENSION_COUNT ,
11
8
MAX_METRICS_SIZE ,
12
9
DEFAULT_NAMESPACE ,
13
10
COLD_START_METRIC ,
14
11
MAX_METRIC_VALUES_SIZE ,
15
- } from './constants' ;
12
+ MetricUnit as MetricUnits ,
13
+ MetricResolution as MetricResolutions ,
14
+ } from './constants.js' ;
16
15
import {
17
- MetricsOptions ,
18
- Dimensions ,
19
- EmfOutput ,
20
- HandlerMethodDecorator ,
21
- StoredMetrics ,
22
- ExtraOptions ,
23
- MetricUnit ,
24
- MetricUnits ,
25
- MetricResolution ,
26
- MetricDefinition ,
27
- } from './types' ;
16
+ type MetricsOptions ,
17
+ type Dimensions ,
18
+ type EmfOutput ,
19
+ type StoredMetrics ,
20
+ type ExtraOptions ,
21
+ type MetricDefinition ,
22
+ type ConfigServiceInterface ,
23
+ type MetricsInterface ,
24
+ type MetricUnit ,
25
+ type MetricResolution ,
26
+ } from './types/index.js ' ;
28
27
29
28
/**
30
29
* ## Intro
@@ -82,7 +81,7 @@ import {
82
81
* @metrics .logMetrics({ captureColdStartMetric: true, throwOnEmptyMetrics: true })
83
82
* public handler(_event: unknown, _context: unknown): Promise<void> {
84
83
* // ...
85
- * metrics.addMetric('test-metric', MetricUnits .Count, 10);
84
+ * metrics.addMetric('test-metric', MetricUnit .Count, 10);
86
85
* // ...
87
86
* }
88
87
* }
@@ -98,13 +97,13 @@ import {
98
97
* @example
99
98
*
100
99
* ```typescript
101
- * import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
100
+ * import { Metrics, MetricUnit } from '@aws-lambda-powertools/metrics';
102
101
*
103
102
* const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });
104
103
*
105
104
* export const handler = async (_event: unknown, __context: unknown): Promise<void> => {
106
105
* metrics.captureColdStartMetric();
107
- * metrics.addMetric('test-metric', MetricUnits .Count, 10);
106
+ * metrics.addMetric('test-metric', MetricUnit .Count, 10);
108
107
* metrics.publishStoredMetrics();
109
108
* };
110
109
* ```
@@ -199,15 +198,15 @@ class Metrics extends Utility implements MetricsInterface {
199
198
* or when calling {@link Metrics.publishStoredMetrics}.
200
199
*
201
200
* You can add a metric by specifying the metric name, unit, and value. For convenience,
202
- * we provide a set of constants for the most common units in {@link MetricUnits }.
201
+ * we provide a set of constants for the most common units in {@link MetricUnit }.
203
202
*
204
203
* @example
205
204
* ```typescript
206
- * import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
205
+ * import { Metrics, MetricUnit } from '@aws-lambda-powertools/metrics';
207
206
*
208
207
* const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });
209
208
*
210
- * metrics.addMetric('successfulBooking', MetricUnits .Count, 1);
209
+ * metrics.addMetric('successfulBooking', MetricUnit .Count, 1);
211
210
* ```
212
211
*
213
212
* Optionally, you can specify the metric resolution, which can be either `High` or `Standard`.
@@ -216,11 +215,11 @@ class Metrics extends Utility implements MetricsInterface {
216
215
*
217
216
* @example
218
217
* ```typescript
219
- * import { Metrics, MetricUnits , MetricResolution } from '@aws-lambda-powertools/metrics';
218
+ * import { Metrics, MetricUnit , MetricResolution } from '@aws-lambda-powertools/metrics';
220
219
*
221
220
* const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });
222
221
*
223
- * metrics.addMetric('successfulBooking', MetricUnits .Count, 1, MetricResolution.High);
222
+ * metrics.addMetric('successfulBooking', MetricUnit .Count, 1, MetricResolution.High);
224
223
* ```
225
224
*
226
225
* @param name - The metric name
@@ -232,7 +231,7 @@ class Metrics extends Utility implements MetricsInterface {
232
231
name : string ,
233
232
unit : MetricUnit ,
234
233
value : number ,
235
- resolution : MetricResolution = MetricResolution . Standard
234
+ resolution : MetricResolution = MetricResolutions . Standard
236
235
) : void {
237
236
this . storeMetric ( name , unit , value , resolution ) ;
238
237
if ( this . isSingleMetric ) this . publishStoredMetrics ( ) ;
@@ -380,7 +379,7 @@ class Metrics extends Utility implements MetricsInterface {
380
379
* @example
381
380
*
382
381
* ```typescript
383
- * import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
382
+ * import { Metrics, MetricUnit } from '@aws-lambda-powertools/metrics';
384
383
*
385
384
* const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' }); // Sets metric namespace, and service as a metric dimension
386
385
*
@@ -424,7 +423,7 @@ class Metrics extends Utility implements MetricsInterface {
424
423
) . map ( ( metricDefinition ) => ( {
425
424
Name : metricDefinition . name ,
426
425
Unit : metricDefinition . unit ,
427
- ...( metricDefinition . resolution === MetricResolution . High
426
+ ...( metricDefinition . resolution === MetricResolutions . High
428
427
? { StorageResolution : metricDefinition . resolution }
429
428
: { } ) ,
430
429
} ) ) ;
@@ -512,7 +511,7 @@ class Metrics extends Utility implements MetricsInterface {
512
511
* ```typescript
513
512
* const singleMetric = metrics.singleMetric();
514
513
* singleMetric.addDimension('InnerDimension', 'true');
515
- * singleMetric.addMetric('single-metric', MetricUnits .Percent, 50);
514
+ * singleMetric.addMetric('single-metric', MetricUnit .Percent, 50);
516
515
* ```
517
516
*
518
517
* @returns the Metrics
@@ -738,4 +737,4 @@ class Metrics extends Utility implements MetricsInterface {
738
737
}
739
738
}
740
739
741
- export { Metrics , MetricUnits , MetricResolution } ;
740
+ export { Metrics } ;
0 commit comments