You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -222,7 +223,7 @@ If you ever forget to use `child` param, we will return an existing `Logger` wit
222
223
223
224
You can dynamically set a percentage of your logs to **DEBUG** level using `sample_rate` param or via env var `POWERTOOLS_LOGGER_SAMPLE_RATE`.
224
225
225
-
This happens on an entire request basis, and <strong>DEBUG</strong> level is set at the constructor. That means, concurrent requests or infrequent invocations are more likely to occur as [new Lambda execution contexts are created](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html), not reused.
226
+
Sampling calculation happens at the Logger class initialization. This means, when configured it, sampling it's more likely to happen during concurrent requests, or infrequent invocations as [new Lambda execution contexts are created](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html), not reused.
226
227
227
228
<Notetype="info">
228
229
If you want this logic to happen on every invocation regardless whether Lambda reuses the execution environment or not, then create your Logger inside your Lambda handler.
Copy file name to clipboardExpand all lines: docs/content/core/metrics.mdx
+7-3
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,9 @@ description: Core utility
5
5
6
6
importNotefrom"../../src/components/Note"
7
7
8
-
Metrics creates custom metrics asynchronously via logging metrics to standard output following Amazon CloudWatch Embedded Metric Format (EMF).
8
+
Metrics creates custom metrics asynchronously by logging metrics to standard output following Amazon CloudWatch Embedded Metric Format (EMF).
9
+
10
+
These metrics can be visualized through [Amazon CloudWatch Console](https://console.aws.amazon.com/cloudwatch/).
9
11
10
12
**Key features**
11
13
@@ -32,7 +34,9 @@ Resources:
32
34
```
33
35
34
36
We recommend you use your application or main service as a metric namespace.
35
-
You can explicitly set a namespace name via `namespace` param or via `POWERTOOLS_METRICS_NAMESPACE` env var. This sets **namespace** key that will be used for all metrics.
37
+
You can explicitly set a namespace name via `namespace` param or via `POWERTOOLS_METRICS_NAMESPACE` env var.
38
+
39
+
This sets **namespace** key that will be used for all metrics.
36
40
You can also pass a service name via `service` param or `POWERTOOLS_SERVICE_NAME` env var. This will create a dimension with the service name.
`MetricUnit` enum facilitate finding a supported metric unit by CloudWatch. Alternatively, you can pass the value as a string if you already know them e.g. "Count".
69
73
70
-
CloudWatch EMF supports a max of 100 metrics. Metrics will automatically flush all metrics when adding the 100th metric, where subsequent metrics will be aggregated into a new EMF object.
74
+
CloudWatch EMF supports a max of 100 metrics. Metrics utility will flush all metrics when adding the 100th metric while subsequent metrics will be aggregated into a new EMF object, for your convenience.
Copy file name to clipboardExpand all lines: docs/content/core/tracer.mdx
+29-9
Original file line number
Diff line number
Diff line change
@@ -17,12 +17,6 @@ Tracer is an opinionated thin wrapper for [AWS X-Ray Python SDK](https://github.
17
17
* Support tracing async methods, generators, and context managers
18
18
* Auto patch supported modules, or a tuple of explicit modules supported by AWS X-Ray
19
19
20
-
<Notetype="warning">
21
-
<strong>Returning sensitive information from your Lambda handler or functions, where Tracer is used?</strong>
22
-
<br/><br/>
23
-
You can disable Tracer from capturing their responses as tracing metadata with <strong><code>capture_response=False</code></strong> parameter in both capture_lambda_handler and capture_method decorators.
24
-
</Note><br/>
25
-
26
20
## Initialization
27
21
28
22
Your AWS Lambda function must have permission to send traces to AWS X-Ray - Here is an example using AWS Serverless Application Model (SAM)
@@ -58,7 +52,7 @@ You can trace your Lambda function handler via `capture_lambda_handler`.
58
52
When using this decorator, Tracer performs these additional tasks to ease operations:
59
53
60
54
* Creates a `ColdStart` annotation to easily filter traces that have had an initialization overhead
61
-
*Adds any response, or full exceptions generated by the handler as metadata
55
+
*Captures any response, or full exceptions generated by the handler, and include as tracing metadata
62
56
63
57
```python:title=lambda_handler.py
64
58
from aws_lambda_powertools import Tracer
@@ -69,7 +63,17 @@ def handler(event, context):
69
63
charge_id = event.get('charge_id')
70
64
payment = collect_payment(charge_id)
71
65
...
66
+
```
67
+
68
+
<Notetype="warning">
69
+
<strong>Returning sensitive information from your Lambda handler or functions, where Tracer is used?</strong>
70
+
<br/><br/>
71
+
You can disable Tracer from capturing their responses as tracing metadata with <strong><code>capture_response=False</code></strong> parameter in both capture_lambda_handler and capture_method decorators.
Tracer automatically patches all [supported libraries by X-Ray](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-python-patching.html) during initialization, by default. Underneath, AWS X-Ray SDK checks whether a supported library has been imported before patching.
180
+
181
+
If you're looking to shave a few microseconds, or milliseconds depending on your function memory configuration, you can patch specific modules using `patch_modules` param:
This snippet assumes you have <strong>aiohttp</strong> as a dependency
@@ -199,7 +219,7 @@ You can use `tracer.provider` attribute to access all methods provided by AWS X-
199
219
200
220
This is useful when you need a feature available in X-Ray that is not available in the Tracer utility, for example [thread-safe](https://github.com/aws/aws-xray-sdk-python/#user-content-trace-threadpoolexecutor), or [context managers](https://github.com/aws/aws-xray-sdk-python/#user-content-start-a-custom-segmentsubsegment).
201
221
202
-
## Concurrent asynchronous functions
222
+
###Concurrent asynchronous functions
203
223
204
224
<Notetype="info">
205
225
<ahref="https://github.com/aws/aws-xray-sdk-python/issues/164">As of now, X-Ray SDK will raise an exception when async functions are run and traced concurrently</a>.
Copy file name to clipboardExpand all lines: docs/content/index.mdx
+32-18
Original file line number
Diff line number
Diff line change
@@ -3,44 +3,47 @@ title: Homepage
3
3
description: AWS Lambda Powertools Python
4
4
---
5
5
6
+
importNotefrom"../src/components/Note"
7
+
6
8
Powertools is a suite of utilities for AWS Lambda Functions that makes tracing with AWS X-Ray, structured logging and creating custom metrics asynchronously easier.
7
9
10
+
<Notetype="info">
11
+
<strong>Looking for a quick run through of the core utilities?</strong><br/><br/>
12
+
Check out <ahref="https://aws.amazon.com/blogs/opensource/simplifying-serverless-best-practices-with-lambda-powertools/">this detailed blog post</a> with a practical example.
13
+
</Note>
14
+
8
15
## Install
9
16
10
17
Powertools is available in PyPi. You can use your favourite dependency management tool to install it
*[Tracing](./core/tracer) - Decorators and utilities to trace Lambda function handlers, and both synchronous and asynchronous functions
18
-
*[Logging](./core/logger) - Structured logging made easier, and decorator to enrich structured logging with key Lambda context details
19
-
*[Metrics](./core/metrics) - Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)
20
-
*[Bring your own middleware](./utilities/middleware_factory) - Decorator factory to create your own middleware to run logic before, and after each Lambda invocation
21
-
*[Parameters utility](./utilities/parameters) - Retrieve parameter values from AWS Systems Manager Parameter Store, AWS Secrets Manager, or Amazon DynamoDB, and cache them for a specific amount of time
22
-
23
-
## Tenets
22
+
**Quick hello world example using SAM CLI**
23
+
```bash:title=hello_world.sh
24
+
sam init --location https://github.com/aws-samples/cookiecutter-aws-sam-python
25
+
```
24
26
25
-
***AWS Lambda only** – We optimise for AWS Lambda function environments and supported runtimes only. Utilities might work with web frameworks and non-Lambda environments, though they are not officially supported.
26
-
***Eases the adoption of best practices** – The main priority of the utilities is to facilitate best practices adoption, as defined in the AWS Well-Architected Serverless Lens; all other functionality is optional.
27
-
***Keep it lean** – Additional dependencies are carefully considered for security and ease of maintenance, and prevent negatively impacting startup time.
28
-
***We strive for backwards compatibility** – New features and changes should keep backwards compatibility. If a breaking change cannot be avoided, the deprecation and migration process should be clearly defined.
29
-
***We work backwards from the community** – We aim to strike a balance of what would work best for 80% of customers. Emerging practices are considered and discussed via Requests for Comment (RFCs)
30
-
***Idiomatic** – Utilities follow programming language idioms and language-specific best practices.
27
+
## Features
31
28
32
-
_`*` Core utilities are Tracer, Logger and Metrics. Optional utilities may vary across languages._
[Tracing](./core/tracer) | Decorators and utilities to trace Lambda function handlers, and both synchronous and asynchronous functions
32
+
[Logging](./core/logger) | Structured logging made easier, and decorator to enrich structured logging with key Lambda context details
33
+
[Metrics](./core/metrics) | Custom Metrics created asynchronously via CloudWatch Embedded Metric Format (EMF)
34
+
[Bring your own middleware](.//utilities/middleware_factory) | Decorator factory to create your own middleware to run logic before, and after each Lambda invocation
35
+
[Parameters utility](./utilities/parameters) | Retrieve parameter values from AWS Systems Manager Parameter Store, AWS Secrets Manager, or Amazon DynamoDB, and cache them for a specific amount of time
33
36
34
37
## Environment variables
35
38
36
39
**Environment variables** used across suite of utilities.
@@ -54,3 +57,14 @@ from aws_lambda_powertools.logging.logger import set_package_logger
54
57
55
58
set_package_logger()
56
59
```
60
+
61
+
## Tenets
62
+
63
+
***AWS Lambda only** – We optimise for AWS Lambda function environments and supported runtimes only. Utilities might work with web frameworks and non-Lambda environments, though they are not officially supported.
64
+
***Eases the adoption of best practices** – The main priority of the utilities is to facilitate best practices adoption, as defined in the AWS Well-Architected Serverless Lens; all other functionality is optional.
65
+
***Keep it lean** – Additional dependencies are carefully considered for security and ease of maintenance, and prevent negatively impacting startup time.
66
+
***We strive for backwards compatibility** – New features and changes should keep backwards compatibility. If a breaking change cannot be avoided, the deprecation and migration process should be clearly defined.
67
+
***We work backwards from the community** – We aim to strike a balance of what would work best for 80% of customers. Emerging practices are considered and discussed via Requests for Comment (RFCs)
68
+
***Idiomatic** – Utilities follow programming language idioms and language-specific best practices.
69
+
70
+
_`*` Core utilities are Tracer, Logger and Metrics. Optional utilities may vary across languages._
0 commit comments