From b654a9df4f2ebd8fecee1a8a15b30056cd37feb9 Mon Sep 17 00:00:00 2001 From: Gary Sassano <10464497+garysassano@users.noreply.github.com> Date: Mon, 9 Dec 2024 23:07:33 +0100 Subject: [PATCH 1/5] fix: memory limit should be defined in Bytes, not MB --- opentelemetry-aws/src/detector/lambda.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/opentelemetry-aws/src/detector/lambda.rs b/opentelemetry-aws/src/detector/lambda.rs index ddcd5ca7..2aed4844 100644 --- a/opentelemetry-aws/src/detector/lambda.rs +++ b/opentelemetry-aws/src/detector/lambda.rs @@ -27,7 +27,11 @@ 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 to Bytes 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() + .to_string(); // 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(); From 6deade6af557640910a32855190daec030caf081 Mon Sep 17 00:00:00 2001 From: Gary Sassano <10464497+garysassano@users.noreply.github.com> Date: Mon, 9 Dec 2024 23:14:41 +0100 Subject: [PATCH 2/5] do not convert to string --- opentelemetry-aws/src/detector/lambda.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/opentelemetry-aws/src/detector/lambda.rs b/opentelemetry-aws/src/detector/lambda.rs index 2aed4844..22f04b54 100644 --- a/opentelemetry-aws/src/detector/lambda.rs +++ b/opentelemetry-aws/src/detector/lambda.rs @@ -30,8 +30,7 @@ impl ResourceDetector for LambdaResourceDetector { // Convert memory limit from MB to Bytes 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() - .to_string(); + .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(); @@ -75,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), ]); let detector = LambdaResourceDetector {}; From f1b14a00e18ac89ff78d07eb10625cacdb0eb6c6 Mon Sep 17 00:00:00 2001 From: Gary Sassano <10464497+garysassano@users.noreply.github.com> Date: Mon, 9 Dec 2024 23:25:30 +0100 Subject: [PATCH 3/5] update test --- opentelemetry-aws/src/detector/lambda.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-aws/src/detector/lambda.rs b/opentelemetry-aws/src/detector/lambda.rs index 22f04b54..9a31a10c 100644 --- a/opentelemetry-aws/src/detector/lambda.rs +++ b/opentelemetry-aws/src/detector/lambda.rs @@ -74,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 {}; From d7818c930628fc1df76dfd579ed735ef0a77962b Mon Sep 17 00:00:00 2001 From: Gary Sassano <10464497+garysassano@users.noreply.github.com> Date: Mon, 9 Dec 2024 23:33:35 +0100 Subject: [PATCH 4/5] improve comment --- opentelemetry-aws/src/detector/lambda.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opentelemetry-aws/src/detector/lambda.rs b/opentelemetry-aws/src/detector/lambda.rs index 9a31a10c..ef191784 100644 --- a/opentelemetry-aws/src/detector/lambda.rs +++ b/opentelemetry-aws/src/detector/lambda.rs @@ -27,7 +27,7 @@ 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(); - // Convert memory limit from MB to Bytes as required by semantic conventions. + // 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(); From 4a10e1aab3e796de0a93d6db72f7fecae817133b Mon Sep 17 00:00:00 2001 From: Gary Sassano <10464497+garysassano@users.noreply.github.com> Date: Tue, 10 Dec 2024 00:53:01 +0100 Subject: [PATCH 5/5] fix lint errors --- opentelemetry-contrib/src/trace/context.rs | 2 +- opentelemetry-contrib/src/trace/tracer_source.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry-contrib/src/trace/context.rs b/opentelemetry-contrib/src/trace/context.rs index f196f559..ebfb63c1 100644 --- a/opentelemetry-contrib/src/trace/context.rs +++ b/opentelemetry-contrib/src/trace/context.rs @@ -91,7 +91,7 @@ pub fn new_span_if_recording( /// ``` /// use opentelemetry::trace::{SpanBuilder, TraceContextExt as _}; /// use opentelemetry_contrib::trace::{new_span_if_parent_sampled, Contextualized, TracerSource}; - +/// /// enum Message{Command}; /// let (tx, rx) = std::sync::mpsc::channel(); /// diff --git a/opentelemetry-contrib/src/trace/tracer_source.rs b/opentelemetry-contrib/src/trace/tracer_source.rs index fdef67a1..8b89c35b 100644 --- a/opentelemetry-contrib/src/trace/tracer_source.rs +++ b/opentelemetry-contrib/src/trace/tracer_source.rs @@ -47,7 +47,7 @@ impl<'a> TracerSource<'a> { } } -impl<'a> Debug for Variant<'a> { +impl Debug for Variant<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use Variant::*; match self {