Skip to content

Commit

Permalink
add aws.log.group.names attribute to LambdaResourceDetector
Browse files Browse the repository at this point in the history
  • Loading branch information
garysassano committed Dec 11, 2024
1 parent 7e1c53a commit aa63a14
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions opentelemetry-aws/src/detector/lambda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,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"),
Expand All @@ -39,6 +41,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,
vec![log_group_name].into(),
),
];

Resource::new(attributes)
Expand All @@ -61,6 +67,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"),
Expand All @@ -72,6 +82,10 @@ 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::AWS_LOG_GROUP_NAMES,
vec!["/aws/lambda/my-lambda-function"].into(),
),
]);

let detector = LambdaResourceDetector {};
Expand All @@ -84,6 +98,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]
Expand Down

0 comments on commit aa63a14

Please sign in to comment.