Skip to content

Commit 92e4ee3

Browse files
committed
Resolving merge conflicts
2 parents 1320cec + af1fe2b commit 92e4ee3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+26630
-20804
lines changed

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [0.2.0-beta.8](https://github.com/awslabs/aws-lambda-powertools-typescript/compare/v0.2.0-beta.7...v0.2.0-beta.8) (2021-12-28)
7+
8+
**Note:** Version bump only for package aws-lambda-powertools-typescript
9+
10+
11+
12+
13+
14+
# [0.2.0-beta.7](https://github.com/awslabs/aws-lambda-powertools-typescript/compare/v0.2.0-beta.6...v0.2.0-beta.7) (2021-12-27)
15+
16+
17+
### Features
18+
19+
* **metrics:** logMetrics middleware ([#338](https://github.com/awslabs/aws-lambda-powertools-typescript/issues/338)) ([f8cf705](https://github.com/awslabs/aws-lambda-powertools-typescript/commit/f8cf7055de78e4515ffbae5de5867649a38dc17d))
20+
21+
22+
23+
24+
625
# [0.2.0-beta.6](https://github.com/awslabs/aws-lambda-powertools-typescript/compare/v0.2.0-beta.5...v0.2.0-beta.6) (2021-12-23)
726

827
**Note:** Version bump only for package aws-lambda-powertools-typescript

LICENSE-THIRD-PARTY

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
hosted-git-info
2+
4.0.2 <https://github.com/npm/hosted-git-info>
3+
Copyright (c) 2015, Rebecca Turner
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
11+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15+
PERFORMANCE OF THIS SOFTWARE.
16+
17+
18+
******************************
19+
20+
lru-cache
21+
6.0.0 <https://github.com/isaacs/node-lru-cache>
22+
The ISC License
23+
24+
Copyright (c) Isaac Z. Schlueter and Contributors
25+
26+
Permission to use, copy, modify, and/or distribute this software for any
27+
purpose with or without fee is hereby granted, provided that the above
28+
copyright notice and this permission notice appear in all copies.
29+
30+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
31+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
32+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
33+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
34+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
35+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
36+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
37+
38+
39+
******************************
40+
41+
yallist
42+
4.0.0 <https://github.com/isaacs/yallist>
43+
The ISC License
44+
45+
Copyright (c) Isaac Z. Schlueter and Contributors
46+
47+
Permission to use, copy, modify, and/or distribute this software for any
48+
purpose with or without fee is hereby granted, provided that the above
49+
copyright notice and this permission notice appear in all copies.
50+
51+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
52+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
53+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
54+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
55+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
56+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
57+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

README.md

+40-19
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,55 @@
1-
# AWS Lambda Powertools (TypeScript)
2-
![Tests](https://github.com/awslabs/aws-lambda-powertools-typescript/workflows/Test/badge.svg?branch=main)
3-
## Testing
4-
The repo uses JEST tests, these can be run using
1+
# AWS Lambda Powertools TypeScript
52

6-
`npm run lerna-test`
3+
| ⚠️ **WARNING: Do not use this library in production** ⚠️ |
4+
|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
5+
| AWS Lambda Powertools for TypeScript is currently released as a beta developer preview and is intended strictly for feedback purposes only. <br/>This version is not stable, and significant breaking changes might incur as part of the upcoming [production-ready release](https://github.com/awslabs/aws-lambda-powertools-typescript/milestone/2). |_
76

8-
Which will also generate coverage reports, and fail if the coverage is below the threshold.
97

10-
## Code Styling and Linting
11-
### Linting
12-
Linting standards adhear to [tslint:recommended](https://github.com/palantir/tslint/blob/master/src/configs/recommended.ts).
8+
A suite of TypeScript utilities for AWS Lambda functions to ease adopting best practices such as tracing, structured logging, custom metrics, and more. (AWS Lambda Powertools [Python](https://github.com/awslabs/aws-lambda-powertools-python) and [Java](https://github.com/awslabs/aws-lambda-powertools-java) are also available).
139

14-
Please ensure you run `npm run lerna-lint` before comiting to check for styling errors
10+
**[📜 Documentation](https://awslabs.github.io/aws-lambda-powertools-typescript/)** | **[NPM](https://www.npmjs.com/org/aws-lambda-powertools)** | **[Roadmap](https://github.com/awslabs/aws-lambda-powertools-roadmap/projects/1)** | **[Examples](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/examples/cdk)**
1511

16-
### Formating
12+
> **An AWS Developer Acceleration (DevAx) initiative by Specialist Solution Architects | [email protected]**
1713
18-
The repo is setup using [Prettier](https://prettier.io/). This will automatically make syntactic changes to files to
19-
align them with the style guides. Please run this before creating a PR, and commit the changes.
14+
### Features
2015

21-
`npm run lerna-format`
16+
* **[Tracer](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer/)** - Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions
17+
* **[Logger](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger/)** - Structured logging made easier, and a middleware to enrich log items with key details of the Lambda context
18+
* **[Metrics](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics/)** - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)
19+
20+
21+
## Getting started
22+
23+
Find the complete project's [documentation here](https://awslabs.github.io/aws-lambda-powertools-typescript).
24+
25+
### Installation
26+
27+
The AWS Lambda Powertools TypeScript utilities follow a modular approach, similar to the official [AWS SDK v3 for JavaScript](https://github.com/aws/aws-sdk-js-v3).
28+
Each TypeScript utility is installed as standalone NPM package.
29+
30+
👉 [Installation guide for the **Tracer** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer#getting-started)
31+
32+
👉 [Installation guide for the **Logger** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/logger#getting-started)
33+
34+
👉 [Installation guide for the **Metrics** utility](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/metrics#getting-started)
35+
36+
### Examples
37+
38+
* [CDK](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/examples/cdk)
39+
* [Tracer](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/packages/tracing/examples)
40+
* [Logger](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/packages/logger/examples)
41+
* [Metrics](https://github.com/awslabs/aws-lambda-powertools-typescript/tree/main/packages/metrics/examples)
2242

2343
## Credits
2444

25-
* Structured logging initial implementation from [aws-lambda-logging](https://gitlab.com/hadrien/aws_lambda_logging)
26-
* Powertools idea [DAZN Powertools](https://github.com/getndazn/dazn-lambda-powertools/)
45+
* Credits for the Lambda Powertools idea go to [DAZN](https://github.com/getndazn) and their [DAZN Lambda Powertools](https://github.com/getndazn/dazn-lambda-powertools/).
46+
2747

28-
## Security
48+
## Connect
2949

30-
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
50+
* **AWS Developers Slack**: `#lambda-powertools`** - **[Invite, if you don't have an account](https://join.slack.com/t/awsdevelopers/shared_invite/zt-yryddays-C9fkWrmguDv0h2EEDzCqvw)**
51+
* **Email**: [email protected]
3152

3253
## License
3354

34-
This library is licensed under the MIT-0 License. See the [LICENSE](LICENSE) file.
55+
This library is licensed under the MIT-0 License. See the LICENSE file.

docs/core/logger.md

+54-29
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ title: Logger
33
description: Core utility
44
---
55

6+
!!! warning "Do not use this library in production"
7+
8+
AWS Lambda Powertools for TypeScript is currently released as a beta developer preview and is intended strictly for feedback purposes only.
9+
This version is not stable, and significant breaking changes might incur as part of the upcoming [production-ready release](https://github.com/awslabs/aws-lambda-powertools-typescript/milestone/2){target="_blank"}.
10+
11+
**Do not use this library for production workloads.**
12+
13+
614
Logger provides an opinionated logger with output structured as JSON.
715

816
## Key features
@@ -14,14 +22,31 @@ Logger provides an opinionated logger with output structured as JSON.
1422

1523
## Getting started
1624

17-
Logger requires two settings:
25+
### Installation
26+
27+
Install the library in your project:
28+
29+
```shell
30+
31+
npm install @aws-lambda-powertools/logger
32+
33+
```
34+
35+
### Utility settings
1836

19-
Setting | Description | Environment variable | Constructor parameter
20-
------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------- | -------------------------------------------------
21-
**Logging level** | Sets how verbose Logger should be (INFO, by default) | `LOG_LEVEL` | `logLevel`
37+
The library requires two settings. You can set them as environment variables, or pass them in the constructor.
38+
39+
These settings will be used across all logs emitted:
40+
41+
Setting | Description | Environment variable | Constructor parameter
42+
------------------------------------------------- |------------------------------------------------------------------------------------------------------------------| ------------------------------------------------- | -------------------------------------------------
43+
**Logging level** | Sets how verbose Logger should be (INFO, by default). Supported values are: `DEBUG`, `INFO`, `WARN`, `ERROR` | `LOG_LEVEL` | `logLevel`
2244
**Service name** | Sets the name of service of which the Lambda function is part of, that will be present across all log statements | `POWERTOOLS_SERVICE_NAME` | `serviceName`
2345

24-
> Example using AWS Serverless Application Model (SAM)
46+
47+
For a **complete list** of supported environment variables, refer to [this section](./../index.md#environment-variables).
48+
49+
#### Example using AWS Serverless Application Model (SAM)
2550

2651
=== "handler.ts"
2752

@@ -33,7 +58,7 @@ Setting | Description | Environment variable | Constructor parameter
3358

3459
// You can also pass the parameters in the constructor
3560
// const logger = new Logger({
36-
// logLevel: "INFO",
61+
// logLevel: "WARN",
3762
// serviceName: "shopping-cart-api"
3863
// });
3964
```
@@ -48,7 +73,7 @@ Setting | Description | Environment variable | Constructor parameter
4873
Runtime: nodejs14.x
4974
Environment:
5075
Variables:
51-
LOG_LEVEL: INFO
76+
LOG_LEVEL: WARN
5277
POWERTOOLS_SERVICE_NAME: shopping-cart-api
5378
```
5479

@@ -70,11 +95,21 @@ Key | Example | Note
7095

7196
You can enrich your structured logs with key Lambda context information in multiple ways.
7297

73-
Method 1, using a [Middy](https://github.com/middyjs/middy) middleware:
98+
This functionality will include the following keys in your structured logs:
99+
100+
Key | Example
101+
------------------------------------------------- | ---------------------------------------------------------------------------------
102+
**cold_start**: `bool` | `false`
103+
**function_name** `string` | `shopping-cart-api-lambda-prod-eu-central-1`
104+
**function_memory_size**: `number` | `128`
105+
**function_arn**: `string` | `arn:aws:lambda:eu-central-1:123456789012:function:shopping-cart-api-lambda-prod-eu-central-1`
106+
**function_request_id**: `string` | `c6af9ac6-7b61-11e6-9a41-93e812345678`
107+
108+
#### Method 1, using a [Middy](https://github.com/middyjs/middy) middleware:
74109

75110
=== "handler.ts"
76111

77-
```typescript hl_lines="1 9-10"
112+
```typescript hl_lines="1 9-11"
78113
import { Logger, injectLambdaContext } from "@aws-lambda-powertools/logger";
79114
import middy from '@middy/core';
80115

@@ -88,7 +123,7 @@ Method 1, using a [Middy](https://github.com/middyjs/middy) middleware:
88123
.use(injectLambdaContext(logger));
89124
```
90125

91-
Method 2, calling the `addContext` method:
126+
#### Method 2, calling the `addContext` method:
92127

93128
=== "handler.ts"
94129

@@ -97,7 +132,7 @@ Method 2, calling the `addContext` method:
97132

98133
const logger = new Logger();
99134

100-
const lambdaHandler = async () => {
135+
const lambdaHandler = async (_event, context) => {
101136

102137
logger.addContext(context);
103138
@@ -106,7 +141,7 @@ Method 2, calling the `addContext` method:
106141
};
107142
```
108143

109-
Method 3, using a class decorator:
144+
#### Method 3, using a class decorator:
110145

111146
=== "handler.ts"
112147

@@ -125,7 +160,7 @@ Method 3, using a class decorator:
125160
}
126161
```
127162

128-
In both case, the printed log will look like this:
163+
In each case, the printed log will look like this:
129164

130165
=== "Example CloudWatch Logs excerpt"
131166

@@ -144,16 +179,6 @@ In both case, the printed log will look like this:
144179
}
145180
```
146181

147-
When used, this will include the following keys:
148-
149-
Key | Example
150-
------------------------------------------------- | ---------------------------------------------------------------------------------
151-
**cold_start**: `bool` | `false`
152-
**function_name** `string` | `shopping-cart-api-lambda-prod-eu-central-1`
153-
**function_memory_size**: `int` | `128`
154-
**function_arn**: `string` | `arn:aws:lambda:eu-central-1:123456789012:function:shopping-cart-api-lambda-prod-eu-central-1`
155-
**function_request_id**: `string` | `c6af9ac6-7b61-11e6-9a41-93e812345678`
156-
157182
### Appending persistent additional log keys and values
158183

159184
You can append additional persistent keys and values in the logs generated during a Lambda invocation using either mechanism:
@@ -422,12 +447,12 @@ This number represents the probability that a Lambda invocation will print all t
422447
For example, by setting the "sample rate" to `0.5`, roughly 50% of your lambda invocations will print all the log items, including the `debug` ones.
423448

424449
!!! tip "When is this useful?"
425-
In production, to avoid log data pollution and reduce CloudWatch costs, developers are encouraged to use the logger with `logLevel` equal to `ERROR` or `WARN`.
426-
This means that only errors or warnings will be printed.
427-
428-
However, it might still be useful to print all the logs (including debug ones) of a very small percentage of invocations to have a better understanding of the behaviour of your code in production even when there are no errors.
429-
430-
Sampling decision happens at the Logger initialization. This means sampling may happen significantly more or less than depending on your traffic patterns, for example a steady low number of invocations and thus few cold starts.
450+
In production, to avoid log data pollution and reduce CloudWatch costs, developers are encouraged to use the logger with `logLevel` equal to `ERROR` or `WARN`.
451+
This means that only errors or warnings will be printed.
452+
453+
However, it might still be useful to print all the logs (including debug ones) of a very small percentage of invocations to have a better understanding of the behaviour of your code in production even when there are no errors.
454+
455+
Sampling decision happens at the Logger initialization. This means sampling may happen significantly more or less than depending on your traffic patterns, for example a steady low number of invocations and thus few cold starts.
431456

432457
=== "handler.ts"
433458

0 commit comments

Comments
 (0)