Skip to content

Commit 5cb0160

Browse files
authored
docs(maintenance): update Middy sections (#1524)
* fix: add back code copy button * chore: clarify instrument clients * docs: update middy info
1 parent 4c9f3eb commit 5cb0160

File tree

9 files changed

+33
-18
lines changed

9 files changed

+33
-18
lines changed

docs/core/logger.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,19 @@ This functionality will include the following keys in your structured logs:
108108

109109
=== "Middy Middleware"
110110

111-
!!! tip "Using Middy for the first time?"
112-
You can install Middy by running `npm i @middy/core`.
113-
Learn more about [its usage and lifecycle in the official Middy documentation](https://middy.js.org/docs/intro/getting-started){target="_blank"}.
111+
!!! tip "A note about Middy"
112+
Currently we support only Middy `v3.x` that you can install it by running `npm i @middy/core@~3`.
113+
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"}.
114114

115115
```typescript hl_lines="1 13"
116116
--8<-- "docs/snippets/logger/middy.ts"
117117
```
118118

119119
=== "Decorator"
120120

121+
!!! info
122+
Decorators can only be attached to a class declaration, method, accessor, property, or parameter. Therefore, if you prefer to write your handler as a standard function rather than a Class method, use the middleware or the manual instrumentation instead. See the [official TypeScript documentation](https://www.typescriptlang.org/docs/handbook/decorators.html) for more details.
123+
121124
```typescript hl_lines="8"
122125
--8<-- "docs/snippets/logger/decorator.ts"
123126
```

docs/core/metrics.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ You can add default dimensions to your metrics by passing them as parameters in
195195

196196
=== "Middy middleware"
197197

198-
!!! tip "Using Middy for the first time?"
199-
You can install Middy by running `npm i @middy/core`.
200-
Learn more about [its usage and lifecycle in the official Middy documentation](https://middy.js.org/docs/intro/getting-started){target="_blank"}.
198+
!!! tip "A note about Middy"
199+
Currently we support only Middy `v3.x` that you can install it by running `npm i @middy/core@~3`.
200+
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"}.
201201

202202
```typescript hl_lines="24-26"
203203
--8<-- "docs/snippets/metrics/defaultDimensionsMiddy.ts"
@@ -211,6 +211,9 @@ You can add default dimensions to your metrics by passing them as parameters in
211211

212212
=== "with logMetrics decorator"
213213

214+
!!! info
215+
Decorators can only be attached to a class declaration, method, accessor, property, or parameter. Therefore, if you prefer to write your handler as a standard function rather than a Class method, use the middleware or the manual instrumentation instead. See the [official TypeScript documentation](https://www.typescriptlang.org/docs/handbook/decorators.html) for more details.
216+
214217
```typescript hl_lines="12"
215218
--8<-- "docs/snippets/metrics/defaultDimensionsDecorator.ts"
216219
```

docs/core/tracer.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,18 @@ You can quickly start by importing the `Tracer` class, initialize it outside the
8585

8686
=== "Middy Middleware"
8787

88-
!!! tip "Using Middy for the first time?"
89-
You can install Middy by running `npm i @middy/core`.
90-
Learn more about [its usage and lifecycle in the official Middy documentation](https://middy.js.org/docs/intro/getting-started){target="_blank"}.
88+
!!! tip "A note about Middy"
89+
Currently we support only Middy `v3.x` that you can install it by running `npm i @middy/core@~3`.
90+
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"}.
9191

9292
```typescript hl_lines="1 14 16"
9393
--8<-- "docs/snippets/tracer/middy.ts"
9494
```
9595

96-
1. Using Middy for the first time? You can install Middy by running `npm i @middy/core`.
97-
Learn more about [its usage and lifecycle in the official Middy documentation](https://github.com/middyjs/middy#usage){target="_blank"}.
98-
9996
=== "Decorator"
10097

10198
!!! info
102-
Decorators can only be attached to a class declaration, method, accessor, property, or parameter. Therefore, if you prefer to write your handler as a standard function rather than a Class method, use the middleware or the manual instrumentations instead.
103-
See the [official TypeScript documentation](https://www.typescriptlang.org/docs/handbook/decorators.html) for more details.
99+
Decorators can only be attached to a class declaration, method, accessor, property, or parameter. Therefore, if you prefer to write your handler as a standard function rather than a Class method, use the middleware or the manual instrumentation instead. See the [official TypeScript documentation](https://www.typescriptlang.org/docs/handbook/decorators.html) for more details.
104100

105101
```typescript hl_lines="8"
106102
--8<-- "docs/snippets/tracer/decorator.ts"

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ You can include Powertools for AWS Lambda (TypeScript) Lambda Layer using [AWS L
262262

263263
You can instrument your code with Powertools for AWS Lambda (TypeScript) in three different ways:
264264

265-
* **Middy** middleware. It is the best choice if your existing code base relies on the [Middy](https://middy.js.org/docs/) middleware engine. Powertools for AWS Lambda (TypeScript) offers compatible Middy middleware to make this integration seamless.
265+
* **Middy** middleware. It is the best choice if your existing code base relies on the [Middy 3.x](https://middy.js.org/docs/) middleware engine. Powertools for AWS Lambda (TypeScript) offers compatible Middy middleware to make this integration seamless.
266266
* **Method decorator**. Use [TypeScript method decorators](https://www.typescriptlang.org/docs/handbook/decorators.html#method-decorators) if you prefer writing your business logic using [TypeScript Classes](https://www.typescriptlang.org/docs/handbook/classes.html). If you aren’t using Classes, this requires the most significant refactoring.
267267
* **Manually**. It provides the most granular control. It’s the most verbose approach, with the added benefit of no additional dependency and no refactoring to TypeScript Classes.
268268

docs/snippets/tracer/captureAWS.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ import { S3 } from 'aws-sdk';
22
import { Tracer } from '@aws-lambda-powertools/tracer';
33

44
const tracer = new Tracer({ serviceName: 'serverlessAirline' });
5-
tracer.captureAWSClient(new S3());
5+
// Instrument the AWS SDK client
6+
const client = tracer.captureAWSClient(new S3());
7+
8+
export default client;

docs/snippets/tracer/captureAWSAll.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ import { Tracer } from '@aws-lambda-powertools/tracer';
22
import AWS from 'aws-sdk';
33

44
const tracer = new Tracer({ serviceName: 'serverlessAirline' });
5+
6+
// Instrument all AWS SDK clients created from this point onwards
57
tracer.captureAWS(AWS);
8+
9+
// Create a new client which will be automatically instrumented
10+
const client = new AWS.SecretsManager();
11+
export default client;

docs/snippets/tracer/captureAWSv3.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ import { SecretsManagerClient } from '@aws-sdk/client-secrets-manager';
22
import { Tracer } from '@aws-lambda-powertools/tracer';
33

44
const tracer = new Tracer({ serviceName: 'serverlessAirline' });
5-
tracer.captureAWSv3Client(new SecretsManagerClient({}));
5+
// Instrument the AWS SDK client
6+
const client = tracer.captureAWSv3Client(new SecretsManagerClient({}));
7+
8+
export default client;

docs/snippets/tracer/middy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Tracer, captureLambdaHandler } from '@aws-lambda-powertools/tracer';
2-
import middy from '@middy/core'; // (1)
2+
import middy from '@middy/core';
33

44
const tracer = new Tracer({ serviceName: 'serverlessAirline' });
55

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ theme:
4343
- navigation.indexes
4444
- navigation.tracking
4545
- content.code.annotate
46+
- content.code.copy
4647
- toc.follow
4748
- toc.integrate
4849
- announce.dismiss

0 commit comments

Comments
 (0)