Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lerna-lint
npm run test
42 changes: 21 additions & 21 deletions packages/metrics/src/Metrics.ts
Original file line number Diff line number Diff line change
@@ -281,27 +281,6 @@ class Metrics implements MetricsInterface {
this.storedMetrics = {};
}

/**
* Throw an Error if the metrics buffer is empty.
*
* @example
*
* ```typescript
* import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
* import { Context } from 'aws-lambda';
*
* const metrics = new Metrics({namespace:"serverlessAirline", serviceName:"orders"});
*
* export const handler = async (event: any, context: Context) => {
* metrics.throwOnEmptyMetrics();
* metrics.publishStoredMetrics(); // will throw since no metrics added.
* }
* ```
*/
public throwOnEmptyMetrics(): void {
this.shouldThrowOnEmptyMetrics = true;
}

/**
* Function to create the right object compliant with Cloudwatch EMF (Event Metric Format).
* @see https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format_Specification.html for more details
@@ -386,6 +365,27 @@ class Metrics implements MetricsInterface {
});
}

/**
* Throw an Error if the metrics buffer is empty.
*
* @example
*
* ```typescript
* import { Metrics, MetricUnits } from '@aws-lambda-powertools/metrics';
* import { Context } from 'aws-lambda';
*
* const metrics = new Metrics({namespace:"serverlessAirline", serviceName:"orders"});
*
* export const handler = async (event: any, context: Context) => {
* metrics.throwOnEmptyMetrics();
* metrics.publishStoredMetrics(); // will throw since no metrics added.
* }
* ```
*/
public throwOnEmptyMetrics(): void {
this.shouldThrowOnEmptyMetrics = true;
}

private getCurrentDimensionsCount(): number {
return Object.keys(this.dimensions).length + Object.keys(this.defaultDimensions).length;
}