Skip to content

Commit fd3a6f0

Browse files
committed
chore: fixed links
1 parent 5742243 commit fd3a6f0

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

packages/metrics/README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ To get started, install the library by running:
2828
npm i @aws-lambda-powertools/metrics
2929
```
3030

31-
After initializing the Metrics class, you can add metrics using the [Metrics.addMetric](`addMetric()`) method. The metrics are stored in a buffer and are flushed when calling [Metrics.publishStoredMetrics](`publishStoredMetrics()`). Each metric can have dimensions and metadata added to it.
31+
After initializing the Metrics class, you can add metrics using the [https://docs.powertools.aws.dev/lambda/typescript/latest/core/metrics/#creating-metrics](`addMetric()`) method. The metrics are stored in a buffer and are flushed when calling [https://docs.powertools.aws.dev/lambda/typescript/latest/core/metrics/#flushing-metrics](`publishStoredMetrics()`).
32+
33+
Each metric can also have dimensions and metadata added to it.
3234

3335
```ts
3436
import { Metrics, MetricUnit } from '@aws-lambda-powertools/metrics';
@@ -48,13 +50,30 @@ export const handler = async (event: { requestId: string }) => {
4850

4951
### Flushing metrics
5052

51-
As you finish adding all your metrics, you need to serialize and "flush them" by calling [publishStoredMetrics()](`publishStoredMetrics()`), which will emit the metrics to stdout in the Embedded Metric Format (EMF). The metrics are then picked up by the Lambda runtime and sent to CloudWatch.
53+
As you finish adding all your metrics, you need to serialize and "flush them" by calling `publishStoredMetrics()`, which will emit the metrics to stdout in the Embedded Metric Format (EMF). The metrics are then picked up by the Lambda runtime and sent to CloudWatch.
5254

53-
When you
55+
The `publishStoredMetrics()` method is synchronous and will block the event loop until the metrics are flushed. If you want Metrics to flush automatically at the end of your Lambda function, you can use the `@logMetrics()` decorator or the `logMetrics()` middleware.
5456

5557
### Capturing cold start as a metric
5658

57-
You can flush metrics automatically using one of the following methods:
59+
With Metrics, you can capture cold start as a metric by calling the `captureColdStartMetric()` method. This method will add a metric with the name `ColdStart` and the value `1` to the metrics buffer.
60+
61+
This metric is flushed automatically as soon as the method is called, to ensure that the cold start is captured regardless of whether the metrics are flushed manually or automatically.
62+
63+
```ts
64+
import { Metrics, MetricUnit } from '@aws-lambda-powertools/metrics';
65+
66+
const metrics = new Metrics({
67+
namespace: 'serverlessAirline',
68+
serviceName: 'orders',
69+
});
70+
71+
export const handler = async (event: { requestId: string }) => {
72+
metrics.captureColdStartMetric();
73+
};
74+
```
75+
76+
Note that we don't emit a `ColdStart` metric with value `0` when the function is warm, as this would result in a high volume of metrics being emitted to CloudWatch, so you'll need to rely on the absence of the `ColdStart` metric to determine if the function is warm.
5877

5978
### Class method decorator
6079

0 commit comments

Comments
 (0)