@@ -15,6 +15,9 @@ use std::process::id;
1515/// - process command line arguments(`process.command_args`), the full command arguments of this
1616/// application.
1717/// - 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`).
1821pub struct ProcessResourceDetector ;
1922
2023impl ResourceDetector for ProcessResourceDetector {
@@ -25,29 +28,76 @@ impl ResourceDetector for ProcessResourceDetector {
2528 . map ( |arg| arg. to_string_lossy ( ) . into_owned ( ) . into ( ) )
2629 . collect :: < Vec < StringValue > > ( ) ;
2730 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+ )
3863 . build ( )
3964 }
4065}
4166
42- #[ cfg( target_os = "linux" ) ]
4367#[ cfg( test) ]
4468mod tests {
4569 use super :: ProcessResourceDetector ;
4670 use opentelemetry_sdk:: resource:: ResourceDetector ;
71+ use opentelemetry_semantic_conventions:: resource:: PROCESS_RUNTIME_DESCRIPTION ;
4772
73+ #[ cfg( target_os = "linux" ) ]
4874 #[ test]
4975 fn test_processor_resource_detector ( ) {
5076 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+ ) ;
52102 }
53103}
0 commit comments