From 4f2ac34ce1916f47c810f211c83c3f7cf77e675d Mon Sep 17 00:00:00 2001 From: Gary Sassano <10464497+garysassano@users.noreply.github.com> Date: Wed, 11 Dec 2024 06:32:37 +0100 Subject: [PATCH] fix: `faas.max_memory` should be an `int` and converted to Bytes (#135) --- opentelemetry-aws/src/detector/lambda.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/opentelemetry-aws/src/detector/lambda.rs b/opentelemetry-aws/src/detector/lambda.rs index ddcd5ca7..ef191784 100644 --- a/opentelemetry-aws/src/detector/lambda.rs +++ b/opentelemetry-aws/src/detector/lambda.rs @@ -27,7 +27,10 @@ impl ResourceDetector for LambdaResourceDetector { let aws_region = env::var(AWS_REGION_ENV_VAR).unwrap_or_default(); let function_version = env::var(AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR).unwrap_or_default(); - let function_memory_limit = env::var(AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR).unwrap_or_default(); + // Convert memory limit from MB (string) to Bytes (int) as required by semantic conventions. + let function_memory_limit = env::var(AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR) + .map(|s| s.parse::().unwrap_or_default() * 1024 * 1024) + .unwrap_or_default(); // Instance attributes corresponds to the log stream name for AWS Lambda; // See the FaaS resource specification for more details. let instance = env::var(AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR).unwrap_or_default(); @@ -71,7 +74,7 @@ mod tests { ), KeyValue::new(semconv::resource::FAAS_NAME, "my-lambda-function"), KeyValue::new(semconv::resource::FAAS_VERSION, "$LATEST"), - KeyValue::new(semconv::resource::FAAS_MAX_MEMORY, "128"), + KeyValue::new(semconv::resource::FAAS_MAX_MEMORY, 128 * 1024 * 1024), ]); let detector = LambdaResourceDetector {};