[{"data":1,"prerenderedAt":71},["ShallowReactive",2],{"pattern-lambda-cloudwatch-otlp-metrics-python-sam":3,"pattern-group-lambda-cloudwatch-otlp-metrics-python-sam":6},{"id":4,"title":5,"architectureURL":6,"cleanup":7,"contributors":11,"deploy":13,"description":16,"extension":17,"framework":18,"gitHub":19,"highlight":6,"introBox":23,"language":29,"level":30,"meta":31,"patternArch":32,"patternGroup":46,"patternGroupLabel":6,"resources":47,"stem":65,"testing":66,"videoId":6,"__hash__":70},"patterns\u002Fpatterns\u002Flambda-cloudwatch-otlp-metrics-python-sam.json","Send custom AWS Lambda metrics to Amazon CloudWatch over OTLP",null,{"headline":8,"text":9},"Cleanup",[10],"Delete the stack with \u003Ccode>sam delete --stack-name STACK_NAME --region $REGION\u003C\u002Fcode> and enter \u003Ccode>y\u003C\u002Fcode> at each confirmation prompt, confirm it with \u003Ccode>aws cloudformation list-stacks\u003C\u002Fcode>, then delete the local out.json response file. The shared AWS SAM CLI managed artifacts bucket and the optional account and Region wide enrichment settings are not created by the stack and are left in place. Metric data points that were already ingested cannot be deleted and age out under the included retention.",[12],"content\u002Fcontributors\u002Fmanish-s.json",{"text":14},[15],"\u003Ccode>sam deploy --guided\u003C\u002Fcode>","Record custom metrics in AWS Lambda with the OpenTelemetry metrics API and send them to the Amazon CloudWatch OTLP endpoint via the ADOT layer.","json","AWS SAM",{"template":20},{"patternPath":21,"templateFile":22},"lambda-cloudwatch-otlp-metrics\u002Fpython\u002Fsam","template.yaml",{"headline":24,"text":25},"How it works",[26,27,28],"This pattern deploys a Python AWS Lambda function with the AWS Distro for OpenTelemetry (ADOT) Lambda layer. The function records custom metrics with the OpenTelemetry metrics API. A collector in the layer receives them over local OTLP, signs each request with SigV4 and sends them to the Amazon CloudWatch OTLP endpoint. The function makes no AWS SDK calls for metrics and needs only \u003Ccode>cloudwatch:PutMetricData\u003C\u002Fcode> beyond basic logging permissions.","Compared with \u003Ccode>PutMetricData\u003C\u002Fcode> or embedded metric format logs, OTLP has no per-series charge and allows up to 150 labels per data point instead of 30 dimensions, so it suits high-cardinality metrics such as per-tenant or business metrics. Keep label values bounded, and don't use request IDs or UUIDs as labels.","Three details are easy to get wrong. The collector in the ADOT layer has no processors, so naming one such as \u003Ccode>batch\u003C\u002Fcode> stops it from starting. The function flushes the meter provider before it returns, because Lambda freezes the environment straight after. The metrics are queried with PromQL in Query Studio, not in the classic CloudWatch metrics console.","Python","300",{},{"icon1":33,"icon2":38,"line1":42},{"x":34,"y":35,"service":36,"label":37},25,50,"lambda-event-functions","AWS Lambda\nwith ADOT layer",{"x":39,"y":35,"service":40,"label":41},75,"cloudwatch","Amazon CloudWatch\nOTLP endpoint",{"from":43,"to":44,"label":45},"icon1","icon2","OTLP metrics","lambda-cloudwatch-otlp-metrics",{"headline":48,"bullets":49},"Additional resources",[50,53,56,59,62],{"text":51,"link":52},"Publish custom metrics with OpenTelemetry","https:\u002F\u002Fdocs.aws.amazon.com\u002FAmazonCloudWatch\u002Flatest\u002Fmonitoring\u002Fmetrics-otel-send.html",{"text":54,"link":55},"Amazon CloudWatch OTLP endpoints and limits","https:\u002F\u002Fdocs.aws.amazon.com\u002FAmazonCloudWatch\u002Flatest\u002Fmonitoring\u002FCloudWatch-OTLPEndpoint.html",{"text":57,"link":58},"AWS Distro for OpenTelemetry Lambda support for Python","https:\u002F\u002Faws-otel.github.io\u002Fdocs\u002Fgetting-started\u002Flambda\u002Flambda-python",{"text":60,"link":61},"Query Amazon CloudWatch metrics with PromQL","https:\u002F\u002Fdocs.aws.amazon.com\u002FAmazonCloudWatch\u002Flatest\u002Fmonitoring\u002FCloudWatch-PromQL.html",{"text":63,"link":64},"OpenTelemetry metrics API for Python","https:\u002F\u002Fopentelemetry.io\u002Fdocs\u002Flanguages\u002Fpython\u002Finstrumentation\u002F","patterns\u002Flambda-cloudwatch-otlp-metrics-python-sam",{"headline":67,"text":68},"Testing",[69],"Invoke the function a few times with the test event in events\u002Forder.json, wait one to two minutes, then query the counter with PromQL using the signed request script in the pattern folder, or in Query Studio in the CloudWatch console. See the README for detailed instructions.","gVxWL8au18tMcx-NO7wdmtEOvoatiaElwbwzUJ4OcdQ",1794652453852]