1
- use opentelemetry:: KeyValue ;
1
+ use opentelemetry:: { Array , KeyValue , StringValue , Value } ;
2
2
use opentelemetry_sdk:: resource:: ResourceDetector ;
3
3
use opentelemetry_sdk:: Resource ;
4
4
use opentelemetry_semantic_conventions as semconv;
@@ -12,6 +12,7 @@ const AWS_REGION_ENV_VAR: &str = "AWS_REGION";
12
12
const AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR : & str = "AWS_LAMBDA_FUNCTION_VERSION" ;
13
13
const AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR : & str = "AWS_LAMBDA_LOG_STREAM_NAME" ;
14
14
const 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" ;
15
16
16
17
/// Resource detector that collects resource information from AWS Lambda environment.
17
18
pub struct LambdaResourceDetector ;
@@ -34,6 +35,7 @@ impl ResourceDetector for LambdaResourceDetector {
34
35
// Instance attributes corresponds to the log stream name for AWS Lambda;
35
36
// See the FaaS resource specification for more details.
36
37
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 ( ) ;
37
39
38
40
let attributes = [
39
41
KeyValue :: new ( semconv:: resource:: CLOUD_PROVIDER , "aws" ) ,
@@ -42,6 +44,10 @@ impl ResourceDetector for LambdaResourceDetector {
42
44
KeyValue :: new ( semconv:: resource:: FAAS_NAME , lambda_name) ,
43
45
KeyValue :: new ( semconv:: resource:: FAAS_VERSION , function_version) ,
44
46
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
+ ) ,
45
51
] ;
46
52
47
53
Resource :: new ( attributes)
@@ -64,6 +70,10 @@ mod tests {
64
70
"2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc" ,
65
71
) ;
66
72
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
+ ) ;
67
77
68
78
let expected = Resource :: new ( [
69
79
KeyValue :: new ( semconv:: resource:: CLOUD_PROVIDER , "aws" ) ,
@@ -75,6 +85,12 @@ mod tests {
75
85
KeyValue :: new ( semconv:: resource:: FAAS_NAME , "my-lambda-function" ) ,
76
86
KeyValue :: new ( semconv:: resource:: FAAS_VERSION , "$LATEST" ) ,
77
87
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
+ ) ,
78
94
] ) ;
79
95
80
96
let detector = LambdaResourceDetector { } ;
@@ -87,6 +103,7 @@ mod tests {
87
103
remove_var ( AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR ) ;
88
104
remove_var ( AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR ) ;
89
105
remove_var ( AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR ) ;
106
+ remove_var ( AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR ) ;
90
107
}
91
108
92
109
#[ sealed_test]
0 commit comments