Skip to content

Commit

Permalink
feat: adopted Utility class
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamorosi committed Feb 10, 2022
1 parent 313596c commit e0119ba
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/metrics/src/Metrics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Callback, Context } from 'aws-lambda';
import { Utility } from '@aws-lambda-powertools/commons';
import { MetricsInterface } from '.';
import { ConfigServiceInterface, EnvironmentVariablesService } from './config';
import {
Expand Down Expand Up @@ -79,20 +80,21 @@ const DEFAULT_NAMESPACE = 'default_namespace';
* };
* ```
*/
class Metrics implements MetricsInterface {
class Metrics extends Utility implements MetricsInterface {
private customConfigService?: ConfigServiceInterface;
private defaultDimensions: Dimensions = {};
private dimensions: Dimensions = {};
private envVarsService?: EnvironmentVariablesService;
private functionName?: string;
private isColdStart: boolean = true;
private isSingleMetric: boolean = false;
private metadata: { [key: string]: string } = {};
private namespace?: string;
private shouldThrowOnEmptyMetrics: boolean = false;
private storedMetrics: StoredMetrics = {};

public constructor(options: MetricsOptions = {}) {
super();

this.dimensions = {};
this.setOptions(options);
}
Expand Down Expand Up @@ -172,8 +174,7 @@ class Metrics implements MetricsInterface {
* ```
*/
public captureColdStartMetric(): void {
if (!this.isColdStart) return;
this.isColdStart = false;
if (!this.isColdStart()) return;
const singleMetric = this.singleMetric();

if (this.dimensions.service) {
Expand Down

0 comments on commit e0119ba

Please sign in to comment.