The AWS Embedded Metrics Python library provides an easy way to emit custom metrics asynchronously, allowing users to consolidate logs and metrics into a single data stream without complex metric client setup. It formats metric data in a structured log format (EMF) for consumption by CloudWatch Logs and then CloudWatch. The current version is 3.5.0, and it follows an active release cadence with frequent updates.
pip install aws-embedded-metricsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use the `@metric_scope` decorator to capture custom metrics. Metrics, dimensions, and properties defined within the decorated function will be flushed as a single Embedded Metric Format (EMF) log entry at the end of the function's execution. Locally, these entries are printed to stdout; in AWS environments, they are typically picked up by the CloudWatch Agent.
Review your metric and dimension definitions. Ensure compliance with new validation rules. Explicitly manage dimension preservation if needed using `metrics.set_preserve_dimensions()`.
Consolidate your dimensions or create multiple dimension sets if you require more than 30 distinct dimensions per metric group.
Ensure your deployment environment (EC2, ECS, EKS) has the CloudWatch Agent running and properly configured to ingest EMF logs from your application's `stdout`. Verify agent logs for processing errors.
To enable high-resolution for a metric, call `metrics.set_storage_resolution(1)` for that metric or globally within the scope. Be aware of increased costs for high-resolution metrics.
Upgrade to `aws-embedded-metrics>=3.3.0` for improved async generator support. Always test thoroughly when using with complex asynchronous patterns.