You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/metrics/README.md
+139-42
Original file line number
Diff line number
Diff line change
@@ -4,69 +4,167 @@ Powertools for AWS Lambda (TypeScript) is a developer toolkit to implement Serve
4
4
5
5
You can use the library in both TypeScript and JavaScript code bases.
6
6
7
-
> Also available in [Python](https://github.com/aws-powertools/powertools-lambda-python), [Java](https://github.com/aws-powertools/powertools-lambda-java), and [.NET](https://github.com/aws-powertools/powertools-lambda-dotnet).
-[Capturing cold start as a metric](#capturing-cold-start-as-a-metric)
12
+
-[Adding metadata](#adding-metadata)
18
13
-[Contribute](#contribute)
19
14
-[Roadmap](#roadmap)
20
15
-[Connect](#connect)
21
16
-[How to support Powertools for AWS Lambda (TypeScript)?](#how-to-support-powertools-for-aws-lambda-typescript)
22
17
-[Becoming a reference customer](#becoming-a-reference-customer)
23
18
-[Sharing your work](#sharing-your-work)
24
19
-[Using Lambda Layer](#using-lambda-layer)
25
-
-[Credits](#credits)
26
20
-[License](#license)
27
21
28
-
## Features
22
+
## Intro
23
+
24
+
## Usage
25
+
26
+
To get started, install the library by running:
27
+
28
+
```sh
29
+
npm i @aws-lambda-powertools/metrics
30
+
```
31
+
32
+
### Basic usage
29
33
30
-
-**[Tracer](https://docs.powertools.aws.dev/lambda/typescript/latest/core/tracer/)** - Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions
31
-
-**[Logger](https://docs.powertools.aws.dev/lambda/typescript/latest/core/logger/)** - Structured logging made easier, and a middleware to enrich log items with key details of the Lambda context
32
-
-**[Metrics](https://docs.powertools.aws.dev/lambda/typescript/latest/core/metrics/)** - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)
33
-
-**[Parameters](https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/parameters/)** - High-level functions to retrieve one or more parameters from AWS SSM, Secrets Manager, AppConfig, and DynamoDB
34
+
The library provides a utility function to emit metrics to CloudWatch using [Embedded Metric Format (EMF)](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html).
As you finish adding all your metrics, you need to serialize and "flush them" by calling publishStoredMetrics(). This will print the metrics to standard output.
55
+
56
+
You can flush metrics automatically using one of the following methods:
40
57
41
-
The Powertools for AWS Lambda (TypeScript) utilities follow a modular approach, similar to the official [AWS SDK v3 for JavaScript](https://github.com/aws/aws-sdk-js-v3).
42
-
Each TypeScript utility is installed as standalone NPM package.
58
+
- manually by calling `publishStoredMetrics()` at the end of your Lambda function
43
59
44
-
Install all three core utilities at once with this single command:
You can find examples of how to use Powertools for AWS Lambda (TypeScript) in the [examples](https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/examples/app) directory. The application is a simple REST API that can be deployed via either AWS CDK or AWS SAM.
The [Serverless TypeScript Demo](https://github.com/aws-samples/serverless-typescript-demo) shows how to use Powertools for AWS Lambda (TypeScript).
67
-
You can find instructions on how to deploy and load test this application in the [repository](https://github.com/aws-samples/serverless-typescript-demo).
The [AWS Lambda performance tuning](https://github.com/aws-samples/optimizations-for-lambda-functions) repository also uses Powertools for AWS Lambda (TypeScript) as well as demonstrating other performance tuning techniques for Lambda functions written in TypeScript.
121
+
Using the Middy middleware or decorator will automatically validate, serialize, and flush all your metrics.
122
+
123
+
### Capturing cold start as a metric
124
+
125
+
You can optionally capture cold start metrics with the logMetrics middleware or decorator via the captureColdStartMetric param.
You can add high-cardinality data as part of your Metrics log with the `addMetadata` method. This is useful when you want to search highly contextual information along with your metrics in your logs.
@@ -86,7 +184,10 @@ Help us prioritize upcoming functionalities or utilities by [upvoting existing R
86
184
87
185
### Becoming a reference customer
88
186
89
-
Knowing which companies are using this library is important to help prioritize the project internally. If your company is using Powertools for AWS Lambda (TypeScript), you can request to have your name and logo added to the README file by raising a [Support Powertools for AWS Lambda (TypeScript) (become a reference)](https://github.com/aws-powertools/powertools-lambda-typescript/issues/new?assignees=&labels=customer-reference&template=support_powertools.yml&title=%5BSupport+Lambda+Powertools%5D%3A+%3Cyour+organization+name%3E) issue.
187
+
Knowing which companies are using this library is important to help prioritize the project internally. If your company
188
+
is using Powertools for AWS Lambda (TypeScript), you can request to have your name and logo added to the README file by
189
+
raising a [Support Powertools for AWS Lambda (TypeScript) (become a reference)](https://s12d.com/become-reference-pt-ts)
190
+
issue.
90
191
91
192
The following companies, among others, use Powertools:
92
193
@@ -112,11 +213,7 @@ Share what you did with Powertools for AWS Lambda (TypeScript) 💞💞. Blog po
112
213
113
214
### Using Lambda Layer
114
215
115
-
This helps us understand who uses Powertools for AWS Lambda (TypeScript) in a non-intrusive way, and helps us gain future investments for other Powertools for AWS Lambda languages. When [using Layers](#lambda-layers), you can add Powertools for AWS Lambda (TypeScript) as a dev dependency (or as part of your virtual env) to not impact the development process.
116
-
117
-
## Credits
118
-
119
-
Credits for the Powertools for AWS Lambda (TypeScript) idea go to [DAZN](https://github.com/getndazn) and their [DAZN Lambda Powertools](https://github.com/getndazn/dazn-lambda-powertools/).
216
+
This helps us understand who uses Powertools for AWS Lambda (TypeScript) in a non-intrusive way, and helps us gain future investments for other Powertools for AWS Lambda languages. When [using Layers](https://docs.powertools.aws.dev/lambda/typescript/latest/#lambda-layer), you can add Powertools as a dev dependency to not impact the development process.
0 commit comments