|
1 | 1 | import { Callback, Context } from 'aws-lambda'; |
| 2 | +import { Utility } from '@aws-lambda-powertools/commons'; |
2 | 3 | import { MetricsInterface } from '.'; |
3 | 4 | import { ConfigServiceInterface, EnvironmentVariablesService } from './config'; |
4 | 5 | import { |
@@ -79,20 +80,21 @@ const DEFAULT_NAMESPACE = 'default_namespace'; |
79 | 80 | * }; |
80 | 81 | * ``` |
81 | 82 | */ |
82 | | -class Metrics implements MetricsInterface { |
| 83 | +class Metrics extends Utility implements MetricsInterface { |
83 | 84 | private customConfigService?: ConfigServiceInterface; |
84 | 85 | private defaultDimensions: Dimensions = {}; |
85 | 86 | private dimensions: Dimensions = {}; |
86 | 87 | private envVarsService?: EnvironmentVariablesService; |
87 | 88 | private functionName?: string; |
88 | | - private isColdStart: boolean = true; |
89 | 89 | private isSingleMetric: boolean = false; |
90 | 90 | private metadata: { [key: string]: string } = {}; |
91 | 91 | private namespace?: string; |
92 | 92 | private shouldThrowOnEmptyMetrics: boolean = false; |
93 | 93 | private storedMetrics: StoredMetrics = {}; |
94 | 94 |
|
95 | 95 | public constructor(options: MetricsOptions = {}) { |
| 96 | + super(); |
| 97 | + |
96 | 98 | this.dimensions = {}; |
97 | 99 | this.setOptions(options); |
98 | 100 | } |
@@ -172,8 +174,7 @@ class Metrics implements MetricsInterface { |
172 | 174 | * ``` |
173 | 175 | */ |
174 | 176 | public captureColdStartMetric(): void { |
175 | | - if (!this.isColdStart) return; |
176 | | - this.isColdStart = false; |
| 177 | + if (!this.isColdStart()) return; |
177 | 178 | const singleMetric = this.singleMetric(); |
178 | 179 |
|
179 | 180 | if (this.dimensions.service) { |
|
0 commit comments