diff --git a/docs/core/logger.md b/docs/core/logger.md index 592e822bd9..2a5d368501 100644 --- a/docs/core/logger.md +++ b/docs/core/logger.md @@ -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 => { + // ... + }; + ``` + ### Utility settings 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 #### 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" @@ -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' // }); ``` diff --git a/docs/core/metrics.md b/docs/core/metrics.md index ae0fadcee7..c3d1fe873e 100644 --- a/docs/core/metrics.md +++ b/docs/core/metrics.md @@ -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 => { + // ... + }; + ``` + ### Utility settings The library requires two settings. You can set them as environment variables, or pass them in the constructor. diff --git a/docs/core/tracer.md b/docs/core/tracer.md index 2283fc962b..12dcc92c83 100644 --- a/docs/core/tracer.md +++ b/docs/core/tracer.md @@ -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 => { + // ... + }; + ``` + ### Utility settings The library has one optional setting. You can set it as environment variable, or pass it in the constructor.