Skip to content

feat!: version 2, the ESM update #2117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 74 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
bc68af2
feat(logger): Support for external observability providers (#1511)
erikayao93 Jun 30, 2023
d7d3f19
chore(logger): PowertoolsLogFormatter docstring and variable naming u…
erikayao93 Jul 7, 2023
7e8cf2c
feat(logger): Support for external observability providers (#1511)
erikayao93 Jun 30, 2023
9368331
chore(logger): PowertoolsLogFormatter docstring and variable naming u…
erikayao93 Jul 7, 2023
a087819
chore(maintenance): bump dependencies & drop nodejs14x (#1687)
dreamorosi Sep 16, 2023
2ed10ed
chore: update release script to mark all utilities as alpha
dreamorosi Sep 18, 2023
a0122e3
chore: restore version to ease conflicts
dreamorosi Sep 27, 2023
e423e8b
chore: release version change
dreamorosi Sep 27, 2023
72ec0b6
chore: release version change
dreamorosi Sep 27, 2023
5c8b2b1
chore(maintenance): remove `createLogger` and `createTracer` helpers …
dreamorosi Oct 2, 2023
8629016
feat(logger): add esmodule support (#1734)
antstanley Oct 11, 2023
3977c60
feat(commons): add esmodule support (#1735)
dreamorosi Oct 11, 2023
3ba9d43
feat(parameters): add esmodule support (#1736)
dreamorosi Oct 12, 2023
4ee57bd
feat(batch): add esmodule support (#1737)
dreamorosi Oct 12, 2023
2ff1026
feat(internal): add esmodule support (#1738)
dreamorosi Oct 12, 2023
57e7b67
feat(metrics): add esmodule support (#1739)
dreamorosi Oct 12, 2023
793ef7f
feat(tracer): add esmodule support (#1741)
dreamorosi Oct 12, 2023
7331038
feat(idempotency): add esmodule support (#1743)
dreamorosi Oct 12, 2023
ae75a4a
chore(metrics): fix import
dreamorosi Oct 14, 2023
a0a973b
chore(ci): v2 release line
dreamorosi Oct 14, 2023
3bf0b01
chore(ci): fix alpha versioning pre-release
dreamorosi Oct 15, 2023
6788a84
docs(maintenance): add processes tab (#1747)
dreamorosi Oct 18, 2023
2c9433b
chore(docs): add invisible unicode char to decorator docs (#1755)
dreamorosi Oct 18, 2023
a31c44c
chore: remove extra comma
dreamorosi Oct 18, 2023
cd226ae
chore(docs): upgrade doc intro
dreamorosi Oct 19, 2023
7f0becd
feat(logger): align sampling debug logs feature implementation with t…
shdq Oct 19, 2023
b4568f9
chore(logger): refactor types and interfaces (#1758)
dreamorosi Oct 20, 2023
138162d
chore(maintenance): bump Middy v4 & run tests (#1760)
dreamorosi Oct 20, 2023
37e13bd
chore(parameters): fix esm bundling
dreamorosi Oct 21, 2023
902a07c
chore(parameters): change declare client param
dreamorosi Oct 21, 2023
da3a1c4
chore(layers) widen version check in e2e
dreamorosi Oct 21, 2023
ab01025
chore(maintenance): enable `isolatedModules` and isolate cache (#1765)
dreamorosi Oct 23, 2023
33d837e
fix: idempotency types
dreamorosi Oct 30, 2023
5f41c07
build(maintenance): bump aws sdk dev dependencies
dreamorosi Oct 31, 2023
cf229ab
chore(parameters): add export types
dreamorosi Oct 31, 2023
bec45c5
chore(logger): set default UTC timezone (#1775)
dreamorosi Nov 3, 2023
748d3c9
fix(metrics): deduplicate dimensions when serialising (#1780)
am29d Nov 2, 2023
948543d
chore(release): v1.14.2 [skip ci]
github-actions[bot] Nov 3, 2023
f0dd4c0
feat(metrics): log directly to stdout (#1786)
dreamorosi Nov 10, 2023
3453106
feat(maintenance): add support for nodejs20.x runtime (#1790)
dreamorosi Nov 14, 2023
e8c8e28
chore(commons): simplify config service interface
dreamorosi Nov 20, 2023
0ed2ed1
chore(release): v1.15.0 [skip ci]
github-actions[bot] Nov 14, 2023
74e94d4
feat(logger): add support for `AWS_LAMBDA_LOG_LEVEL` and `POWERTOOLS_…
dreamorosi Nov 16, 2023
dba2923
chore(release): v1.16.0 [skip ci]
github-actions[bot] Nov 16, 2023
c06d4b6
chore(maintenance): drop support for Node.js 14 (#1802)
dreamorosi Nov 24, 2023
24b8e08
chore: package lock
dreamorosi Nov 24, 2023
4ba4cd0
chore(docs): update docs url in comments & readme files (#1728)
dreamorosi Oct 9, 2023
ea55aa9
chore(ci): update v2 release workflow (#1745)
dreamorosi Oct 14, 2023
01cfa22
docs(maintenance): add processes tab (#1747)
dreamorosi Oct 18, 2023
875df2c
chore(maintenance): add --require-hashes flag to pip installs (#1827)
dreamorosi Dec 20, 2023
af5f262
bump version to 9.5.2, rerun pip-compile with correct deps (#1830)
am29d Dec 21, 2023
802abee
chore(ci): Dependabot fine tuning (#1862)
am29d Jan 9, 2024
0f81306
chore(deps-dev): bump @aws-sdk/client-cloudwatch from 3.438.0 to 3.48…
dependabot[bot] Jan 9, 2024
51bc6f4
chore(deps-dev): bump @types/node from 20.11.0 to 20.11.2 (#1912)
dependabot[bot] Jan 15, 2024
c5d2721
chore(deps): fix dependencies and dependabot config (#1917)
dreamorosi Jan 16, 2024
c92b2d1
chore(deps-dev): bump @typescript-eslint/parser from 6.19.0 to 6.19.1…
dependabot[bot] Jan 25, 2024
3b99b97
chore(deps-dev): bump @typescript-eslint/eslint-plugin (#1948)
dependabot[bot] Jan 25, 2024
05d03a4
chore(ci): refactor workflows to scope permissions (#1978)
dreamorosi Jan 26, 2024
85eb1ac
chore(maintenance): rebase conflicts
dreamorosi Jan 27, 2024
d51b9c7
chore(maintenance): rebase conflicts
dreamorosi Jan 27, 2024
ad1d98d
chore: rebase conflicts
dreamorosi Feb 20, 2024
c9ae783
chore: remove v2 specific release
dreamorosi Feb 20, 2024
4085298
chore: release patch script
dreamorosi Feb 20, 2024
b5bc335
docs: update docs & snippets
dreamorosi Feb 20, 2024
409fec2
chore: address SonarCloud findings
dreamorosi Feb 20, 2024
3f972eb
chore: address SonarCloud findings
dreamorosi Feb 20, 2024
5b5c7a2
chore: address SonarCloud findings
dreamorosi Feb 20, 2024
0df2691
tests: coverage
dreamorosi Feb 20, 2024
3f7fa9b
chore: add layers v2
dreamorosi Feb 21, 2024
61ce4cb
chore: bump ua version
dreamorosi Feb 21, 2024
93dc33f
docs: add install steps to batch
dreamorosi Feb 21, 2024
e6afb55
chore: fix install command
dreamorosi Feb 22, 2024
acb17b5
chore: remove unused dependency
dreamorosi Feb 22, 2024
0c01873
Update examples/cdk/package.json
dreamorosi Feb 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 6 additions & 3 deletions .github/actions/cached-node-modules/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ inputs:
nodeVersion: # id of input
description: 'Node.js version to use in the cache key'
default: '20'
build:
description: 'Whether to build the packages or not'
default: 'true'
outputs:
cache-hit:
description: "Whether the cache was hit or not"
Expand All @@ -17,7 +20,7 @@ runs:
shell: bash
- name: Cache node modules
id: cache-node-modules
uses: actions/cache@69d9d449aced6a2ede0bc19182fadc3a0a42d2b0 # v3.2.6
uses: actions/cache@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
with:
path: '**/node_modules'
# Use the combo between node version, name, and SHA-256 hash of the lock file as cache key so that
Expand All @@ -29,8 +32,8 @@ runs:
run: npm ci
shell: bash
- name: Build packages
# Regardless of whether the cache was hit or not, we need to build the packages.
#
# Regardless of whether the cache was hit or not, we need to build the packages, unless the caller says otherwise
if: inputs.build == 'true'
# We build the shared package first, then the others in parallel to speed up the process
# even though we could just run `npm run build` in the root folder and build them in
# sequence, but still in the correct order.
Expand Down
2 changes: 2 additions & 0 deletions .github/scripts/release_patch_package_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const betaPackages = [];
types,
files,
private,
type,
} = pkgJson;

let version = originalVersion;
Expand Down Expand Up @@ -71,6 +72,7 @@ const betaPackages = [];
main,
types,
files,
type,
};

// Not all utilities have these fields, so only add them if they exist to avoid
Expand Down
81 changes: 0 additions & 81 deletions .github/workflows/make-v2-release.yml

This file was deleted.

8 changes: 6 additions & 2 deletions .github/workflows/make-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ jobs:
uses: ./.github/actions/cached-node-modules
- name: Version
id: bump-version
run: npx lerna version --conventional-commits --no-git-tag-version --no-push --no-commit-hooks --yes
- name: Update user agent version
run: |
npx lerna version --conventional-commits --no-git-tag-version --no-push --no-commit-hooks --yes
git add .
VERSION=$(cat lerna.json | jq .version -r)
echo -e "// this file is auto generated, do not modify\nexport const VERSION = '$VERSION';" > packages/commons/src/version.ts
- name: Stage changes
run: git add .
- name: Set release version
id: set-release-version
run: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ tmp

# TS build files
tsconfig.tsbuildinfo
.tsbuildinfo
.tsbuildinfo
2 changes: 1 addition & 1 deletion MAINTAINERS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
> [!IMPORTANT]
> Maintainers' playbook moved: https://docs.powertools.aws.dev/lambda/typescript/latest/maintainers/
> Maintainers' playbook moved: https://docs.powertools.aws.dev/lambda/typescript/latest/maintainers/
47 changes: 21 additions & 26 deletions docs/core/logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ The library has three optional settings, which can be set via environment variab

These settings will be used across all logs emitted:

| Setting | Description | Environment variable | Default Value | Allowed Values | Example Value | Constructor parameter |
| ---------------------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------- | ------------------- | ------------------------------------------------------ | ------------------- | --------------------- |
| **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` | `service_undefined` | Any string | `serverlessAirline` | `serviceName` |
| **Logging level** | Sets how verbose Logger should be, from the most verbose to the least verbose (no logs) | `POWERTOOLS_LOG_LEVEL` | `INFO` | `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, `SILENT` | `ERROR` | `logLevel` |
| **Sample rate** | Probability that a Lambda invocation will print all the log items regardless of the log level setting | `POWERTOOLS_LOGGER_SAMPLE_RATE` | `0` | `0.0` to `1.0` | `0.1` | `sampleRateValue` |
| Setting | Description | Environment variable | Default Value | Allowed Values | Example Value | Constructor parameter |
| ----------------- | ---------------------------------------------------------------------------------------------------------------- | ------------------------------- | ------------------- | ------------------------------------------------------ | ------------------- | --------------------- |
| **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` | `service_undefined` | Any string | `serverlessAirline` | `serviceName` |
| **Logging level** | Sets how verbose Logger should be, from the most verbose to the least verbose (no logs) | `POWERTOOLS_LOG_LEVEL` | `INFO` | `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, `SILENT` | `ERROR` | `logLevel` |
| **Sample rate** | Probability that a Lambda invocation will print all the log items regardless of the log level setting | `POWERTOOLS_LOGGER_SAMPLE_RATE` | `0` | `0.0` to `1.0` | `0.1` | `sampleRateValue` |

See all environment variables in the [Environment variables](../index.md/#environment-variables) section.
Check API docs to learn more about [Logger constructor options](https://docs.powertools.aws.dev/lambda/typescript/latest/api/types/_aws_lambda_powertools_logger.types.ConstructorOptions.html){target="_blank"}.
Expand Down Expand Up @@ -110,10 +110,10 @@ This functionality will include the following keys in your structured logs:
=== "Middy Middleware"

!!! tip "A note about Middy"
Currently we support only Middy `v3.x` that you can install it by running `npm i @middy/core@~3`.
We guarantee support only for Middy.js `v4.x`, that you can install it by running `npm i @middy/core@~4`.
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.

```typescript hl_lines="1 13"
```typescript hl_lines="2 14"
--8<-- "docs/snippets/logger/middy.ts"
```

Expand All @@ -131,7 +131,7 @@ This functionality will include the following keys in your structured logs:

=== "Manual"

```typescript hl_lines="6"
```typescript hl_lines="10"
--8<-- "docs/snippets/logger/manual.ts"
```

Expand Down Expand Up @@ -163,7 +163,7 @@ When debugging in non-production environments, you can instruct Logger to log th

=== "Middy Middleware"

```typescript hl_lines="10"
```typescript hl_lines="15"
--8<-- "docs/snippets/logger/eventMiddy.ts"
```

Expand Down Expand Up @@ -236,7 +236,7 @@ If you want to make sure that persistent attributes added **inside the handler f

=== "Middy Middleware"

```typescript hl_lines="30"
```typescript hl_lines="31"
--8<-- "docs/snippets/logger/clearStateMiddy.ts"
```

Expand Down Expand Up @@ -509,23 +509,21 @@ The `createChild` method allows you to create a child instance of the Logger, wh
}
```

### Sampling logs
### Sampling debug logs

Use sampling when you want to print all the log items generated in your code, based on a **percentage of your concurrent/cold start invocations**.
Use sampling when you want to dynamically change your log level to **DEBUG** based on a **percentage of your concurrent/cold start invocations**.

You can do that by setting a "sample rate", a float value ranging from `0.0` (0%) to `1` (100%), by using a `POWERTOOLS_LOGGER_SAMPLE_RATE` env var or passing the `sampleRateValue` parameter in the Logger constructor.
This number represents the probability that a Lambda invocation will print all the log items regardless of the log level setting.

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.
You can use values ranging from `0` to `1` (100%) when setting the `sampleRateValue` constructor option or `POWERTOOLS_LOGGER_SAMPLE_RATE` env var.

!!! tip "When is this useful?"
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`.
This means that only errors or warnings will be printed.
Let's imagine a sudden spike increase in concurrency triggered a transient issue downstream. When looking into the logs you might not have enough information, and while you can adjust log levels it might not happen again.

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.

**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.
If you want to reset the sampling decision and refresh it for each invocation, you can call the `logger.refreshSampleRateCalculation()` method at the beginning or end of your handler.
This feature takes into account transient issues where additional debugging information can be useful.

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.

!!! note
Open a [feature request](https://github.com/aws-powertools/powertools-lambda-typescript/issues/new?assignees=&labels=type%2Ffeature-request%2Ctriage&projects=aws-powertools%2F7&template=feature_request.yml&title=Feature+request%3A+TITLE) if you want Logger to calculate sampling for every invocation

=== "handler.ts"

Expand Down Expand Up @@ -639,7 +637,7 @@ You can customize the structure (keys and values) of your log items by passing a

=== "handler.ts"

```typescript hl_lines="2 5"
```typescript hl_lines="2 6"
--8<-- "docs/snippets/logger/bringYourOwnFormatterHandler.ts"
```

Expand Down Expand Up @@ -700,9 +698,6 @@ This is a Jest sample that provides the minimum information necessary for Logger
--8<-- "docs/snippets/logger/unitTesting.ts"
```

!!! tip
If you don't want to declare your own dummy Lambda Context, you can use [`ContextExamples.helloworldContext`](https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/commons/src/samples/resources/contexts/hello-world.ts#L3-L16) from [`@aws-lambda-powertools/commons`](https://www.npmjs.com/package/@aws-lambda-powertools/commons).

### Suppress logs with Jest

When unit testing your code with [Jest](https://jestjs.io) you can use the `POWERTOOLS_DEV` environment variable in conjunction with the Jest `--silent` CLI option to suppress logs from Logger.
Expand Down
8 changes: 4 additions & 4 deletions docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ npm install @aws-lambda-powertools/metrics

!!! warning "Caution"

Using the Lambda [Advanced Logging Controls](...docs link) feature requires you to update your version of Powertools for AWS Lambda (TypeScript) to at least v1.15.0 to ensure metrics are reported correctly to Amazon CloudWatch Metrics.
Using the Lambda [Advanced Logging Controls](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-advanced) feature requires you to update your version of Powertools for AWS Lambda (TypeScript) to at least v1.15.0 to ensure metrics are reported correctly to Amazon CloudWatch Metrics.

### Usage

Expand Down Expand Up @@ -253,7 +253,7 @@ See below an example of how to automatically flush metrics with the Middy-compat

=== "handler.ts"

```typescript hl_lines="20"
```typescript hl_lines="2 17"
--8<-- "docs/snippets/metrics/middy.ts"
```

Expand Down Expand Up @@ -368,7 +368,7 @@ You can optionally capture cold start metrics with the `logMetrics` middleware o

=== "Middy Middleware"

```typescript hl_lines="21"
```typescript hl_lines="18"
--8<-- "docs/snippets/metrics/captureColdStartMetricMiddy.ts"
```

Expand Down Expand Up @@ -398,7 +398,7 @@ You can add high-cardinality data as part of your Metrics log with the `addMetad

=== "handler.ts"

```typescript hl_lines="18"
```typescript hl_lines="15"
--8<-- "docs/snippets/metrics/addMetadata.ts"
```

Expand Down
8 changes: 4 additions & 4 deletions docs/core/tracer.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ You can quickly start by importing the `Tracer` class, initialize it outside the
=== "Middy Middleware"

!!! tip "A note about Middy"
Currently we support only Middy `v3.x` that you can install it by running `npm i @middy/core@~3`.
We guarantee support only for Middy.js `v4.x`, that you can install it by running `npm i @middy/core@~4`.
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.

```typescript hl_lines="1 14 16"
```typescript hl_lines="2 15 17"
--8<-- "docs/snippets/tracer/middy.ts"
```

Expand Down Expand Up @@ -197,7 +197,7 @@ You can patch all AWS SDK v2 clients by calling the `captureAWS` method:

=== "index.ts"

```typescript hl_lines="6"
```typescript hl_lines="7"
--8<-- "docs/snippets/tracer/captureAWSAll.ts"
```

Expand Down Expand Up @@ -284,7 +284,7 @@ Alternatively, use the `captureResponse: false` option in both `tracer.captureLa

=== "middy.ts"

```typescript hl_lines="17"
```typescript hl_lines="18"
--8<-- "docs/snippets/tracer/disableCaptureResponseMiddy.ts"
```

Expand Down
Loading