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
* docs: improve contrast for inline code expressions
* docs: format stylesheet & remove invalid declarations
* docs: fix typo in connect section
* docs: clarified middy's usage & linked to official docs
* docs: uniformed main example with tabs for logger
* docs: moved aws sdk patching under getting started section
* docs: added testing your code section to logger
* docs: moved middy tips under middy examples
* docs: Moved tip under code example in testing yoru code section
#### Method 1, using a [Middy](https://github.com/middyjs/middy) middleware:
108
+
=== "Middleware"
109
109
110
-
=== "handler.ts"
110
+
!!! note
111
+
Middy comes bundled with Logger, so you can just import it when using the middleware.
112
+
113
+
!!! tip "Using Middy for the first time?"
114
+
Learn more about [its usage and lifecycle in the official Middy documentation](https://github.com/middyjs/middy#usage){target="_blank"}.
111
115
112
-
```typescript hl_lines="1 9-11"
116
+
```typescript hl_lines="1-2 10-11"
113
117
import { Logger, injectLambdaContext } from "@aws-lambda-powertools/logger";
114
118
import middy from '@middy/core';
115
119
@@ -123,9 +127,7 @@ Key | Example
123
127
.use(injectLambdaContext(logger));
124
128
```
125
129
126
-
#### Method 2, calling the `addContext` method:
127
-
128
-
=== "handler.ts"
130
+
=== "Manual"
129
131
130
132
```typescript hl_lines="7"
131
133
import { Logger } from "@aws-lambda-powertools/logger";
@@ -141,9 +143,7 @@ Key | Example
141
143
};
142
144
```
143
145
144
-
#### Method 3, using a class decorator:
145
-
146
-
=== "handler.ts"
146
+
=== "Decorator"
147
147
148
148
```typescript hl_lines="7"
149
149
import { Logger } from "@aws-lambda-powertools/logger";
@@ -621,4 +621,47 @@ This is how the printed log would look:
621
621
},
622
622
"awsAccountId": "123456789012"
623
623
}
624
-
```
624
+
```
625
+
626
+
## Testing your code
627
+
628
+
### Inject Lambda Context
629
+
630
+
When unit testing your code that makes use of `logger.addContext()` or `injectLambdaContext` middleware and decorator, you can optionally pass a dummy Lambda Context if you want your logs to contain this information.
631
+
632
+
This is a Jest sample that provides the minimum information necessary for Logger to inject context data:
If you don't want to declare your own dummy Lambda Context, you can use [`ContextExamples.helloworldContext`](https://github.com/awslabs/aws-lambda-powertools-typescript/blob/main/packages/commons/src/tests/resources/contexts/hello-world.ts#L3-L16) from [`@aws-lambda-powertools/commons`](https://www.npmjs.com/package/@aws-lambda-powertools/commons).
import { Tracer } from '@aws-lambda-powertools/tracer';
110
116
111
117
const tracer = Tracer(); // Sets service via env var
@@ -252,8 +258,6 @@ You can trace other methods using the `captureMethod` decorator or manual instru
252
258
}
253
259
```
254
260
255
-
## Advanced
256
-
257
261
### Patching AWS SDK clients
258
262
259
263
Tracer can patch [AWS SDK clients](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-nodejs-awssdkclients.html) and create traces when your application makes calls to AWS services.
@@ -300,6 +304,8 @@ If you're looking to shave a few microseconds, or milliseconds depending on your
Copy file name to clipboardExpand all lines: docs/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,5 +78,5 @@ Each TypeScript utility is installed as standalone NPM package.
78
78
79
79
## Connect
80
80
81
-
***AWS Developers Slack**: `#lambda-powertools`** - **[Invite, if you don't have an account](https://join.slack.com/t/awsdevelopers/shared_invite/zt-yryddays-C9fkWrmguDv0h2EEDzCqvw){target="_blank"}**
81
+
***AWS Developers Slack**: `#lambda-powertools` - [Invite, if you don't have an account](https://join.slack.com/t/awsdevelopers/shared_invite/zt-yryddays-C9fkWrmguDv0h2EEDzCqvw){target="_blank"}
0 commit comments