diff --git a/opentelemetry-aws/src/detector/lambda.rs b/opentelemetry-aws/src/detector/lambda.rs index ef191784..3564fb84 100644 --- a/opentelemetry-aws/src/detector/lambda.rs +++ b/opentelemetry-aws/src/detector/lambda.rs @@ -1,4 +1,4 @@ -use opentelemetry::KeyValue; +use opentelemetry::{Array, KeyValue, StringValue, Value}; use opentelemetry_sdk::resource::ResourceDetector; use opentelemetry_sdk::Resource; use opentelemetry_semantic_conventions as semconv; @@ -12,6 +12,7 @@ const AWS_REGION_ENV_VAR: &str = "AWS_REGION"; const AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR: &str = "AWS_LAMBDA_FUNCTION_VERSION"; const AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR: &str = "AWS_LAMBDA_LOG_STREAM_NAME"; const AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR: &str = "AWS_LAMBDA_FUNCTION_MEMORY_SIZE"; +const AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR: &str = "AWS_LAMBDA_LOG_GROUP_NAME"; /// Resource detector that collects resource information from AWS Lambda environment. pub struct LambdaResourceDetector; @@ -34,6 +35,7 @@ impl ResourceDetector for LambdaResourceDetector { // 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(); + let log_group_name = env::var(AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR).unwrap_or_default(); let attributes = [ KeyValue::new(semconv::resource::CLOUD_PROVIDER, "aws"), @@ -42,6 +44,10 @@ impl ResourceDetector for LambdaResourceDetector { KeyValue::new(semconv::resource::FAAS_NAME, lambda_name), KeyValue::new(semconv::resource::FAAS_VERSION, function_version), KeyValue::new(semconv::resource::FAAS_MAX_MEMORY, function_memory_limit), + KeyValue::new( + semconv::resource::AWS_LOG_GROUP_NAMES, + Value::Array(Array::from(vec![StringValue::from(log_group_name)])), + ), ]; Resource::new(attributes) @@ -64,6 +70,10 @@ mod tests { "2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc", ); set_var(AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR, "128"); + set_var( + AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR, + "/aws/lambda/my-lambda-function", + ); let expected = Resource::new([ KeyValue::new(semconv::resource::CLOUD_PROVIDER, "aws"), @@ -75,6 +85,12 @@ 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 * 1024 * 1024), + KeyValue::new( + semconv::resource::AWS_LOG_GROUP_NAMES, + Value::Array(Array::from(vec![StringValue::from( + "/aws/lambda/my-lambda-function".to_string(), + )])), + ), ]); let detector = LambdaResourceDetector {}; @@ -87,6 +103,7 @@ mod tests { remove_var(AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR); remove_var(AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR); remove_var(AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR); + remove_var(AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR); } #[sealed_test]