1- use opentelemetry:: KeyValue ;
1+ use opentelemetry:: { Array , KeyValue , StringValue , Value } ;
22use opentelemetry_sdk:: resource:: ResourceDetector ;
33use opentelemetry_sdk:: Resource ;
44use opentelemetry_semantic_conventions as semconv;
@@ -12,6 +12,7 @@ const AWS_REGION_ENV_VAR: &str = "AWS_REGION";
1212const AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR : & str = "AWS_LAMBDA_FUNCTION_VERSION" ;
1313const AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR : & str = "AWS_LAMBDA_LOG_STREAM_NAME" ;
1414const AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR : & str = "AWS_LAMBDA_FUNCTION_MEMORY_SIZE" ;
15+ const AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR : & str = "AWS_LAMBDA_LOG_GROUP_NAME" ;
1516
1617/// Resource detector that collects resource information from AWS Lambda environment.
1718pub struct LambdaResourceDetector ;
@@ -34,6 +35,7 @@ impl ResourceDetector for LambdaResourceDetector {
3435 // Instance attributes corresponds to the log stream name for AWS Lambda;
3536 // See the FaaS resource specification for more details.
3637 let instance = env:: var ( AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR ) . unwrap_or_default ( ) ;
38+ let log_group_name = env:: var ( AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR ) . unwrap_or_default ( ) ;
3739
3840 let attributes = [
3941 KeyValue :: new ( semconv:: resource:: CLOUD_PROVIDER , "aws" ) ,
@@ -42,6 +44,10 @@ impl ResourceDetector for LambdaResourceDetector {
4244 KeyValue :: new ( semconv:: resource:: FAAS_NAME , lambda_name) ,
4345 KeyValue :: new ( semconv:: resource:: FAAS_VERSION , function_version) ,
4446 KeyValue :: new ( semconv:: resource:: FAAS_MAX_MEMORY , function_memory_limit) ,
47+ KeyValue :: new (
48+ semconv:: resource:: AWS_LOG_GROUP_NAMES ,
49+ Value :: Array ( Array :: from ( vec ! [ StringValue :: from( log_group_name) ] ) ) ,
50+ ) ,
4551 ] ;
4652
4753 Resource :: new ( attributes)
@@ -64,6 +70,10 @@ mod tests {
6470 "2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc" ,
6571 ) ;
6672 set_var ( AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR , "128" ) ;
73+ set_var (
74+ AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR ,
75+ "/aws/lambda/my-lambda-function" ,
76+ ) ;
6777
6878 let expected = Resource :: new ( [
6979 KeyValue :: new ( semconv:: resource:: CLOUD_PROVIDER , "aws" ) ,
@@ -75,6 +85,12 @@ mod tests {
7585 KeyValue :: new ( semconv:: resource:: FAAS_NAME , "my-lambda-function" ) ,
7686 KeyValue :: new ( semconv:: resource:: FAAS_VERSION , "$LATEST" ) ,
7787 KeyValue :: new ( semconv:: resource:: FAAS_MAX_MEMORY , 128 * 1024 * 1024 ) ,
88+ KeyValue :: new (
89+ semconv:: resource:: AWS_LOG_GROUP_NAMES ,
90+ Value :: Array ( Array :: from ( vec ! [ StringValue :: from(
91+ "/aws/lambda/my-lambda-function" . to_string( ) ,
92+ ) ] ) ) ,
93+ ) ,
7894 ] ) ;
7995
8096 let detector = LambdaResourceDetector { } ;
@@ -87,6 +103,7 @@ mod tests {
87103 remove_var ( AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR ) ;
88104 remove_var ( AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR ) ;
89105 remove_var ( AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR ) ;
106+ remove_var ( AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR ) ;
90107 }
91108
92109 #[ sealed_test]
0 commit comments