Metrics
| CLASS | DESCRIPTION |
|---|---|
Metrics |
Metrics create an CloudWatch EMF object with up to 100 metrics |
Metrics ¶
Metrics(
service: str | None = None,
namespace: str | None = None,
provider: AmazonCloudWatchEMFProvider | None = None,
function_name: str | None = None,
)
Metrics create an CloudWatch EMF object with up to 100 metrics
Use Metrics when you need to create multiple metrics that have dimensions in common (e.g. service_name="payment").
Metrics up to 100 metrics in memory and are shared across all its instances. That means it can be safely instantiated outside of a Lambda function, or anywhere else.
A decorator (log_metrics) is provided so metrics are published at the end of its execution. If more than 100 metrics are added at a given function execution, these metrics are serialized and published before adding a given metric to prevent metric truncation.
Example
Creates a few metrics and publish at the end of a function execution
1 2 3 4 5 6 7 8 9 10 | |
Environment variables
POWERTOOLS_METRICS_NAMESPACE : str
metric namespace
POWERTOOLS_SERVICE_NAME : str
service name used for default dimension
POWERTOOLS_METRICS_DISABLED: bool
Powertools metrics disabled (e.g. "true", "True", "TRUE")
| PARAMETER | DESCRIPTION |
|---|---|
service
|
service name to be used as metric dimension, by default "service_undefined"
TYPE:
|
namespace
|
Namespace for metrics
TYPE:
|
provider
|
Pre-configured AmazonCloudWatchEMFProvider provider
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
MetricUnitError
|
When metric unit isn't supported by CloudWatch |
MetricResolutionError
|
When metric resolution isn't supported by CloudWatch |
MetricValueError
|
When metric value isn't a number |
SchemaValidationError
|
When metric object fails EMF schema validation |
| METHOD | DESCRIPTION |
|---|---|
set_timestamp |
Set the timestamp for the metric. |
Source code in aws_lambda_powertools/metrics/metrics.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
set_timestamp ¶
set_timestamp(timestamp: int)
Set the timestamp for the metric.
Source code in aws_lambda_powertools/metrics/metrics.py
136 137 138 139 140 141 142 143 144 145 146 147 | |