From e808c75da406962e13d86f0ba663b9a1f06b3f0e Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 28 Feb 2022 15:07:09 +0000 Subject: [PATCH 1/4] docs: added usage section --- docs/core/logger.md | 22 ++++++++++++++++++---- docs/core/metrics.md | 16 ++++++++++++++++ docs/core/tracer.md | 16 ++++++++++++++++ 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/docs/core/logger.md b/docs/core/logger.md index 592e822bd9..84ce6e5d55 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 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. + +=== "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..24733cf6b9 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 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 => { + // ... + }; + ``` + ### 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..4fa46fe2ce 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 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 => { + // ... + }; + ``` + ### Utility settings The library has one optional setting. You can set it as environment variable, or pass it in the constructor. From 5307d489b52e0d8da4e876eddc77bd5b9371815a Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 3 Mar 2022 15:54:25 +0100 Subject: [PATCH 2/4] Update docs/core/logger.md Co-authored-by: ijemmy --- docs/core/logger.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/logger.md b/docs/core/logger.md index 84ce6e5d55..2a5d368501 100644 --- a/docs/core/logger.md +++ b/docs/core/logger.md @@ -31,7 +31,7 @@ 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. +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" From 21ca09e66c56b69c155a3576e9f3e3c601a46312 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 3 Mar 2022 15:54:33 +0100 Subject: [PATCH 3/4] Update docs/core/metrics.md Co-authored-by: ijemmy --- docs/core/metrics.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/metrics.md b/docs/core/metrics.md index 24733cf6b9..c3d1fe873e 100644 --- a/docs/core/metrics.md +++ b/docs/core/metrics.md @@ -45,7 +45,7 @@ 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. +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" From 01cb4b405c280b0bb98f1f0be3ace4d41d509406 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 3 Mar 2022 15:54:50 +0100 Subject: [PATCH 4/4] Update docs/core/tracer.md Co-authored-by: ijemmy --- docs/core/tracer.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/tracer.md b/docs/core/tracer.md index 4fa46fe2ce..12dcc92c83 100644 --- a/docs/core/tracer.md +++ b/docs/core/tracer.md @@ -33,7 +33,7 @@ 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. +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"