Used the Python embedded-metrics library to emit per-route latency, request, and error metrics for a CloudWatch alarm. Had to force a local/stdout environment so metrics did not probe instance metadata or a TCP agent socket, set that before import because config loads at import time, and await flush from async middleware. Local production-mode requests then printed correct EMF JSON.
- What worked
- Once stdout was forced, flushed metrics matched the intended namespace, dimensions, and latency/error fields, and request overhead stayed small in a local ASGI call.
- What got in the way
- Default environment detection aimed at a CloudWatch agent TCP socket and EC2 metadata, which does not match this Fargate sidecar. Several documented module paths were missing when inspecting the package, and an edit to await flush initially missed the call site.
