Skip to content

Commit 63a503f

Browse files
dreamorosiijemmy
andauthored
docs: Add usage sub-section in docs (#604)
* docs: added usage section * Update docs/core/logger.md Co-authored-by: ijemmy <[email protected]> * Update docs/core/metrics.md Co-authored-by: ijemmy <[email protected]> * Update docs/core/tracer.md Co-authored-by: ijemmy <[email protected]> Co-authored-by: ijemmy <[email protected]>
1 parent cc0445c commit 63a503f

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

Diff for: docs/core/logger.md

+18-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ Install the library in your project:
2929
npm install @aws-lambda-powertools/logger
3030
```
3131

32+
### Usage
33+
34+
The `Logger` utility must always be instantiated outside of the Lambda handler. In doing this, subsequent invocations processed by the same instance of your function can reuse these resources. This saves cost by reducing function run time. In addition, `Logger` can keep track of a cold start and inject the appropriate fields into logs.
35+
36+
=== "handler.ts"
37+
38+
```typescript hl_lines="1 3"
39+
import { Logger } from '@aws-lambda-powertools/logger';
40+
41+
const logger = new Logger({ serviceName: 'serverlessAirline' });
42+
43+
export const handler = async (_event, _context): Promise<void> => {
44+
// ...
45+
};
46+
```
47+
3248
### Utility settings
3349

3450
The library requires two settings. You can set them as environment variables, or pass them in the constructor.
@@ -44,8 +60,6 @@ For a **complete list** of supported environment variables, refer to [this secti
4460

4561
#### Example using AWS Serverless Application Model (SAM)
4662

47-
The `Logger` utility is instantiated outside of the Lambda handler. In doing this, the same instance can be used across multiple invocations inside the same execution environment. This allows `Metrics` to be aware of things like whether or not a given invocation had a cold start or not.
48-
4963
=== "handler.ts"
5064

5165
```typescript hl_lines="1 4"
@@ -56,8 +70,8 @@ The `Logger` utility is instantiated outside of the Lambda handler. In doing thi
5670

5771
// You can also pass the parameters in the constructor
5872
// const logger = new Logger({
59-
// logLevel: "WARN",
60-
// serviceName: "serverlessAirline"
73+
// logLevel: 'WARN',
74+
// serviceName: 'serverlessAirline'
6175
// });
6276
```
6377

Diff for: docs/core/metrics.md

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ Install the library in your project:
4343
npm install @aws-lambda-powertools/metrics
4444
```
4545

46+
### Usage
47+
48+
The `Metrics` utility must always be instantiated outside of the Lambda handler. In doing this, subsequent invocations processed by the same instance of your function can reuse these resources. This saves cost by reducing function run time. In addition, `Metrics` can track cold start and emit the appropriate metrics.
49+
50+
=== "handler.ts"
51+
52+
```typescript hl_lines="1 3"
53+
import { Metrics } from '@aws-lambda-powertools/metrics';
54+
55+
const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });
56+
57+
export const handler = async (_event, _context): Promise<void> => {
58+
// ...
59+
};
60+
```
61+
4662
### Utility settings
4763

4864
The library requires two settings. You can set them as environment variables, or pass them in the constructor.

Diff for: docs/core/tracer.md

+16
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ Install the library in your project:
3131
npm install @aws-lambda-powertools/tracer
3232
```
3333

34+
### Usage
35+
36+
The `Tracer` utility must always be instantiated outside of the Lambda handler. In doing this, subsequent invocations processed by the same instance of your function can reuse these resources. This saves cost by reducing function run time. In addition, `Tracer` can track cold start and annotate the traces accordingly.
37+
38+
=== "handler.ts"
39+
40+
```typescript hl_lines="1 3"
41+
import { Tracer } from '@aws-lambda-powertools/tracer';
42+
43+
const tracer = new Tracer({ serviceName: 'serverlessAirline' });
44+
45+
export const handler = async (_event, _context): Promise<void> => {
46+
// ...
47+
};
48+
```
49+
3450
### Utility settings
3551

3652
The library has one optional setting. You can set it as environment variable, or pass it in the constructor.

0 commit comments

Comments
 (0)