Skip to content

Commit fab6110

Browse files
authored
docs(maintenance): add clarification about async decorators (#1778)
* docs(maintenance): add clarification about async decorators * docs(maintenance): add clarification about async decorators
1 parent 2d9f8b6 commit fab6110

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

Diff for: docs/core/logger.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ This functionality will include the following keys in your structured logs:
118118

119119
=== "Decorator"
120120

121-
!!! info
122-
Powertools decorators can only be attached to class methods and follow the experimetal decorators proposal implementation found in TypeScript 4.x. As such, you need to enable the `experimentalDecorators` compiler option in your `tsconfig.json` file to use them.
121+
!!! note
122+
The class method decorators in this project follow the experimental implementation enabled via the [`experimentalDecorators` compiler option](https://www.typescriptlang.org/tsconfig#experimentalDecorators) in TypeScript. Additionally, they are implemented in a way that fits asynchronous methods. When decorating a synchronous method, the decorator replaces its implementation with an asynchronous one causing the caller to have to `await` the now decorated method.
123+
If this is not the desired behavior, you can call the `logger.injectLambdaContext()` method directly in your handler.
123124

124125
```typescript hl_lines="8"
125126
--8<-- "docs/snippets/logger/decorator.ts"

Diff for: docs/core/metrics.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -211,8 +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-
Powertools decorators can only be attached to class methods and follow the experimetal decorators proposal implementation found in TypeScript 4.x. As such, you need to enable the `experimentalDecorators` compiler option in your `tsconfig.json` file to use them.
214+
!!! note
215+
The class method decorators in this project follow the experimental implementation enabled via the [`experimentalDecorators` compiler option](https://www.typescriptlang.org/tsconfig#experimentalDecorators) in TypeScript. Additionally, they are implemented in a way that fits asynchronous methods. When decorating a synchronous method, the decorator replaces its implementation with an asynchronous one causing the caller to have to `await` the now decorated method.
216+
If this is not the desired behavior, you can use the `logMetrics` middleware instead.
216217

217218
```typescript hl_lines="12"
218219
--8<-- "docs/snippets/metrics/defaultDimensionsDecorator.ts"
@@ -276,9 +277,9 @@ See below an example of how to automatically flush metrics with the Middy-compat
276277

277278
#### Using the class decorator
278279

279-
!!! info
280-
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, check the [middleware](#using-a-middleware) or [manual](#manually) method sections instead.
281-
See the [official TypeScript documentation](https://www.typescriptlang.org/docs/handbook/decorators.html) for more details.
280+
!!! note
281+
The class method decorators in this project follow the experimental implementation enabled via the [`experimentalDecorators` compiler option](https://www.typescriptlang.org/tsconfig#experimentalDecorators) in TypeScript. Additionally, they are implemented in a way that fits asynchronous methods. When decorating a synchronous method, the decorator replaces its implementation with an asynchronous one causing the caller to have to `await` the now decorated method.
282+
If this is not the desired behavior, you can use the `logMetrics` middleware instead.
282283

283284
The `logMetrics` decorator of the metrics utility can be used when your Lambda handler function is implemented as method of a Class.
284285

Diff for: docs/core/tracer.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ You can quickly start by importing the `Tracer` class, initialize it outside the
9797

9898
=== "Decorator"
9999

100-
!!! info
101-
Powertools decorators can only be attached to class methods and follow the experimetal decorators proposal implementation found in TypeScript 4.x. As such, you need to enable the `experimentalDecorators` compiler option in your `tsconfig.json` file to use them.
100+
!!! note
101+
The class method decorators in this project follow the experimental implementation enabled via the [`experimentalDecorators` compiler option](https://www.typescriptlang.org/tsconfig#experimentalDecorators) in TypeScript. Additionally, they are implemented in a way that fits asynchronous methods. When decorating a synchronous method, the decorator replaces its implementation with an asynchronous one causing the caller to have to `await` the now decorated method.
102+
If this is not the desired behavior, you can use one of the other patterns instead.
102103

103104
```typescript hl_lines="8"
104105
--8<-- "docs/snippets/tracer/decorator.ts"
@@ -152,10 +153,14 @@ When using the `captureLambdaHandler` decorator or middleware, Tracer performs t
152153

153154
### Methods
154155

155-
You can trace other Class methods using the `captureMethod` decorator or any arbitrary function using manual instrumentation.
156+
You can trace other class methods using the `captureMethod` decorator or any arbitrary asynchronous function using manual instrumentation.
156157

157158
=== "Decorator"
158159

160+
!!! note
161+
The class method decorators in this project follow the experimental implementation enabled via the [`experimentalDecorators` compiler option](https://www.typescriptlang.org/tsconfig#experimentalDecorators) in TypeScript. Additionally, they are implemented in a way that fits asynchronous methods. When decorating a synchronous method, the decorator replaces its implementation with an asynchronous one causing the caller to have to `await` the now decorated method.
162+
If this is not the desired behavior, you can use manual instrumentation instead.
163+
159164
```typescript hl_lines="8"
160165
--8<-- "docs/snippets/tracer/captureMethodDecorator.ts"
161166
```
@@ -181,7 +186,7 @@ You can patch any AWS SDK clients by calling the `captureAWSv3Client` method:
181186

182187
=== "index.ts"
183188

184-
```typescript hl_lines="5"
189+
```typescript hl_lines="6"
185190
--8<-- "docs/snippets/tracer/captureAWSv3.ts"
186191
```
187192

@@ -192,15 +197,15 @@ You can patch all AWS SDK v2 clients by calling the `captureAWS` method:
192197

193198
=== "index.ts"
194199

195-
```typescript hl_lines="5"
200+
```typescript hl_lines="6"
196201
--8<-- "docs/snippets/tracer/captureAWSAll.ts"
197202
```
198203

199204
If you're looking to shave a few microseconds, or milliseconds depending on your function memory configuration, you can patch only specific AWS SDK v2 clients using `captureAWSClient`:
200205

201206
=== "index.ts"
202207

203-
```typescript hl_lines="5"
208+
```typescript hl_lines="6"
204209
--8<-- "docs/snippets/tracer/captureAWS.ts"
205210
```
206211

Diff for: docs/utilities/idempotency.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ The function this example has two arguments, note that while wrapping it with th
164164

165165
You can also use the `@idempotent` decorator to make your Lambda handler idempotent, similar to the `makeIdempotent` function wrapper.
166166

167+
!!! info
168+
The class method decorators in this project follow the experimental implementation enabled via the [`experimentalDecorators` compiler option](https://www.typescriptlang.org/tsconfig#experimentalDecorators) in TypeScript. Additionally, they are implemented in a way that fits asynchronous methods. When decorating a synchronous method, the decorator replaces its implementation with an asynchronous one causing the caller to have to `await` the now decorated method.
169+
If this is not the desired behavior, you can use one of the other patterns to make your logic idempotent.
170+
167171
=== "index.ts"
168172

169173
```typescript hl_lines="17"
@@ -183,8 +187,8 @@ The configuration options for the `@idempotent` decorator are the same as the on
183187
### MakeHandlerIdempotent Middy middleware
184188

185189
!!! tip "A note about Middy"
186-
Currently we support only Middy `v3.x` that you can install it by running `npm i @middy/core@~3`.
187-
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"}.
190+
Currently we support only Middy `v3.x` that you can install it by running `npm i @middy/core@~3`.
191+
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"}.
188192

189193
If you are using [Middy](https://middy.js.org){target="_blank"} as your middleware engine, you can use the `makeHandlerIdempotent` middleware to make your Lambda handler idempotent. Similar to the `makeIdempotent` function wrapper, you can quickly make your Lambda handler idempotent by initializing the `DynamoDBPersistenceLayer` class and using it with the `makeHandlerIdempotent` middleware.
190194

0 commit comments

Comments
 (0)