@@ -15,6 +15,9 @@ use std::process::id;
15
15
/// - process command line arguments(`process.command_args`), the full command arguments of this
16
16
/// application.
17
17
/// - OS assigned process id(`process.pid`).
18
+ /// - process runtime version(`process.runtime.version`).
19
+ /// - process runtime name(`process.runtime.name`).
20
+ /// - process runtime description(`process.runtime.description`).
18
21
pub struct ProcessResourceDetector ;
19
22
20
23
impl ResourceDetector for ProcessResourceDetector {
@@ -25,29 +28,76 @@ impl ResourceDetector for ProcessResourceDetector {
25
28
. map ( |arg| arg. to_string_lossy ( ) . into_owned ( ) . into ( ) )
26
29
. collect :: < Vec < StringValue > > ( ) ;
27
30
Resource :: builder_empty ( )
28
- . with_attributes ( vec ! [
29
- KeyValue :: new(
30
- opentelemetry_semantic_conventions:: attribute:: PROCESS_COMMAND_ARGS ,
31
- Value :: Array ( cmd_arg_val. into( ) ) ,
32
- ) ,
33
- KeyValue :: new(
34
- opentelemetry_semantic_conventions:: attribute:: PROCESS_PID ,
35
- id( ) as i64 ,
36
- ) ,
37
- ] )
31
+ . with_attributes (
32
+ vec ! [
33
+ Some ( KeyValue :: new(
34
+ opentelemetry_semantic_conventions:: attribute:: PROCESS_COMMAND_ARGS ,
35
+ Value :: Array ( cmd_arg_val. into( ) ) ,
36
+ ) ) ,
37
+ Some ( KeyValue :: new(
38
+ opentelemetry_semantic_conventions:: attribute:: PROCESS_PID ,
39
+ id( ) as i64 ,
40
+ ) ) ,
41
+ Some ( KeyValue :: new(
42
+ opentelemetry_semantic_conventions:: attribute:: PROCESS_RUNTIME_NAME ,
43
+ "rustc" ,
44
+ ) ) ,
45
+ // Set from build.rs
46
+ option_env!( "RUSTC_VERSION" ) . map( |rustc_version| {
47
+ KeyValue :: new(
48
+ opentelemetry_semantic_conventions:: attribute:: PROCESS_RUNTIME_VERSION ,
49
+ rustc_version,
50
+ )
51
+ } ) ,
52
+ // Set from build.rs
53
+ option_env!( "RUSTC_VERSION_DESCRIPTION" ) . map( |rustc_version_desc| {
54
+ KeyValue :: new(
55
+ opentelemetry_semantic_conventions:: attribute:: PROCESS_RUNTIME_DESCRIPTION ,
56
+ rustc_version_desc,
57
+ )
58
+ } ) ,
59
+ ]
60
+ . into_iter ( )
61
+ . flatten ( ) ,
62
+ )
38
63
. build ( )
39
64
}
40
65
}
41
66
42
- #[ cfg( target_os = "linux" ) ]
43
67
#[ cfg( test) ]
44
68
mod tests {
45
69
use super :: ProcessResourceDetector ;
46
70
use opentelemetry_sdk:: resource:: ResourceDetector ;
71
+ use opentelemetry_semantic_conventions:: resource:: PROCESS_RUNTIME_DESCRIPTION ;
47
72
73
+ #[ cfg( target_os = "linux" ) ]
48
74
#[ test]
49
75
fn test_processor_resource_detector ( ) {
50
76
let resource = ProcessResourceDetector . detect ( ) ;
51
- assert_eq ! ( resource. len( ) , 2 ) ; // we cannot assert on the values because it changes along with runtime.
77
+ assert_eq ! ( resource. len( ) , 5 ) ; // we cannot assert on the values because it changes along with runtime.
78
+ }
79
+
80
+ #[ test]
81
+ fn test_processor_resource_detector_runtime ( ) {
82
+ use opentelemetry_semantic_conventions:: attribute:: {
83
+ PROCESS_RUNTIME_NAME , PROCESS_RUNTIME_VERSION ,
84
+ } ;
85
+
86
+ let resource = ProcessResourceDetector . detect ( ) ;
87
+
88
+ assert_eq ! (
89
+ resource. get( & PROCESS_RUNTIME_NAME . into( ) ) ,
90
+ Some ( "rustc" . into( ) )
91
+ ) ;
92
+
93
+ assert_eq ! (
94
+ resource. get( & PROCESS_RUNTIME_VERSION . into( ) ) ,
95
+ Some ( env!( "RUSTC_VERSION" ) . into( ) )
96
+ ) ;
97
+
98
+ assert_eq ! (
99
+ resource. get( & PROCESS_RUNTIME_DESCRIPTION . into( ) ) ,
100
+ Some ( env!( "RUSTC_VERSION_DESCRIPTION" ) . into( ) )
101
+ ) ;
52
102
}
53
103
}
0 commit comments