Skip to content

docs: Add usage sub-section in docs #604

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 4 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions docs/core/logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ Install the library in your project:
npm install @aws-lambda-powertools/logger
```

### Usage

The `Logger` utility should 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 to this, `Logger` can also be aware of things like whether or not a given invocation had a cold start or not and inject the appropriate fields into the log.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The `Logger` utility should 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 to this, `Logger` can also be aware of things like whether or not a given invocation had a cold start or not and inject the appropriate fields into the log.
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 track cold start and inject the appropriate fields into the logs.


=== "handler.ts"

```typescript hl_lines="1 3"
import { Logger } from '@aws-lambda-powertools/logger';

const logger = new Logger({ serviceName: 'serverlessAirline' });

export const handler = async (_event, _context): Promise<void> => {
// ...
};
```

### Utility settings

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

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

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.

=== "handler.ts"

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

// You can also pass the parameters in the constructor
// const logger = new Logger({
// logLevel: "WARN",
// serviceName: "serverlessAirline"
// logLevel: 'WARN',
// serviceName: 'serverlessAirline'
// });
```

Expand Down
16 changes: 16 additions & 0 deletions docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ Install the library in your project:
npm install @aws-lambda-powertools/metrics
```

### Usage

The `Metrics` utility should 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 to this, `Metrics` can also be aware of things like whether or not a given invocation had a cold start or not and emit the appropriate metrics.

=== "handler.ts"

```typescript hl_lines="1 3"
import { Metrics } from '@aws-lambda-powertools/metrics';

const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' });

export const handler = async (_event, _context): Promise<void> => {
// ...
};
```

### Utility settings

The library requires two settings. You can set them as environment variables, or pass them in the constructor.
Expand Down
16 changes: 16 additions & 0 deletions docs/core/tracer.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ Install the library in your project:
npm install @aws-lambda-powertools/tracer
```

### Usage

The `Tracer` utility should 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 to this, `Tracer` can also be aware of things like whether or not a given invocation had a cold start or not and annotate your traces accordingly.

=== "handler.ts"

```typescript hl_lines="1 3"
import { Tracer } from '@aws-lambda-powertools/tracer';

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

export const handler = async (_event, _context): Promise<void> => {
// ...
};
```

### Utility settings

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