Skip to content

Commit

Permalink
docs: Add usage sub-section in docs (#604)
Browse files Browse the repository at this point in the history
* docs: added usage section

* Update docs/core/logger.md

Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>

* Update docs/core/metrics.md

Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>

* Update docs/core/tracer.md

Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>

Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
  • Loading branch information
dreamorosi and ijemmy authored Mar 3, 2022
1 parent cc0445c commit 63a503f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
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 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.

=== "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 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.

=== "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 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.

=== "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

0 comments on commit 63a503f

Please sign in to comment.