Skip to content

Commit

Permalink
resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamorosi committed Jan 7, 2022
2 parents 7902db5 + 471eaca commit bdced91
Show file tree
Hide file tree
Showing 17 changed files with 5,961 additions and 4,668 deletions.
8 changes: 4 additions & 4 deletions docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ You can flush metrics automatically using one of the following methods:
* [Middy-compatible](https://github.com/middyjs/middy){target=_blank} middleware
* class decorator

Using the Middy middleware or decorator will **automatically validate, serialize, and flush** all your metrics. During metrics validation, if no metrics are provided then a warning will be logged, but no exception will be raised.
Using the Middy middleware or decorator will **automatically validate, serialize, and flush** all your metrics. During metrics validation, if no metrics are provided then a warning will be logged, but no exception will be thrown.
If you do not use the middleware or decorator, you have to flush your metrics manually.


!!! warning "Metric validation"
If metrics are provided, and any of the following criteria are not met, a **`RangeError`** exception will be raised:
If metrics are provided, and any of the following criteria are not met, a **`RangeError`** exception will be thrown:

* Maximum of 9 dimensions
* Namespace is set only once (or none)
Expand Down Expand Up @@ -433,7 +433,7 @@ The `logMetrics` decorator of the metrics utility can be used when your Lambda h

#### Throwing a RangeError when no metrics are emitted

If you want to ensure that at least one metric is emitted before you flush them, you can use the `raiseOnEmptyMetrics` parameter and pass it to the middleware or decorator:
If you want to ensure that at least one metric is emitted before you flush them, you can use the `throwOnEmptyMetrics` parameter and pass it to the middleware or decorator:

```typescript hl_lines="11"
import { Metrics, MetricUnits, logMetrics } from '@aws-lambda-powertools/metrics';
Expand All @@ -446,7 +446,7 @@ If you want to ensure that at least one metric is emitted before you flush them,
}

export const handler = middy(lambdaHandler)
.use(logMetrics(metrics, { raiseOnEmptyMetrics: true }));
.use(logMetrics(metrics, { throwOnEmptyMetrics: true }));
```

### Capturing a cold start invocation as metric
Expand Down
2 changes: 1 addition & 1 deletion examples/cdk/lib/example-function.MyFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const handler = async (_event: unknown, context: Context): Promise<void>

// ### Experiment metrics
metrics.captureColdStartMetric();
metrics.raiseOnEmptyMetrics();
metrics.throwOnEmptyMetrics();
metrics.setDefaultDimensions({ environment: 'example', type: 'standardFunction' });
metrics.addMetric('test-metric', MetricUnits.Count, 10);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class MyFunctionWithDecorator {
@logger.injectLambdaContext()
@metrics.logMetrics({
captureColdStartMetric: true,
raiseOnEmptyMetrics: true,
throwOnEmptyMetrics: true,
defaultDimensions: { environment: 'example', type: 'withDecorator' },
})
public handler(_event: unknown, _context: Context, _callback: Callback<unknown>): void | Promise<unknown> {
Expand Down
Loading

0 comments on commit bdced91

Please sign in to comment.