99//! The module provides abstractions for the reporter and the collector. And it also defines
1010//! the data structures that are used to represent the events.
1111
12- use crate :: intercept:: supervise:: supervise;
12+ pub mod supervise;
13+ mod tcp;
14+
1315use crate :: { args, config} ;
16+ use anyhow:: Context ;
1417use serde:: { Deserialize , Serialize } ;
1518use std:: collections:: HashMap ;
1619use std:: path:: { Path , PathBuf } ;
1720use std:: process:: { Command , ExitCode } ;
1821use std:: sync:: mpsc:: { channel, Receiver , Sender } ;
1922use std:: sync:: Arc ;
20- use std:: { env, fmt, thread} ;
21-
22- pub mod supervise;
23- pub mod tcp;
23+ use std:: { fmt, thread} ;
24+ use supervise:: supervise;
2425
2526/// Declare the environment variables used by the intercept mode.
26- pub const KEY_DESTINATION : & str = "INTERCEPT_REPORTER_ADDRESS" ;
27- pub const KEY_PRELOAD_PATH : & str = "LD_PRELOAD" ;
27+ const KEY_DESTINATION : & str = "INTERCEPT_COLLECTOR_ADDRESS" ;
28+ const KEY_PRELOAD_PATH : & str = "LD_PRELOAD" ;
29+
30+ /// Creates a new reporter instance.
31+ ///
32+ /// This function is supposed to be called from another process than the collector.
33+ /// Therefore, the reporter destination is passed as an environment variable.
34+ /// The reporter destination is the address of the collector service.
35+ pub fn create_reporter ( ) -> anyhow:: Result < Box < dyn Reporter > > {
36+ let reporter =
37+ // Get the reporter address from the environment variable
38+ std:: env:: var ( KEY_DESTINATION )
39+ . with_context ( || format ! ( "${} is missing from the environment" , KEY_DESTINATION ) )
40+ // Create a new reporter
41+ . and_then ( tcp:: ReporterOnTcp :: new) ?;
42+ Ok ( Box :: new ( reporter) )
43+ }
2844
2945/// Represents the remote sink of supervised process events.
3046///
@@ -299,7 +315,7 @@ impl InterceptEnvironment {
299315 InterceptEnvironment :: Wrapper {
300316 bin_dir, address, ..
301317 } => {
302- let path_original = env:: var ( "PATH" ) . unwrap_or_else ( |_| String :: new ( ) ) ;
318+ let path_original = std :: env:: var ( "PATH" ) . unwrap_or_else ( |_| String :: new ( ) ) ;
303319 let path_updated = InterceptEnvironment :: insert_to_path (
304320 & path_original,
305321 Self :: path_to_string ( bin_dir. path ( ) ) ,
@@ -310,7 +326,8 @@ impl InterceptEnvironment {
310326 ]
311327 }
312328 InterceptEnvironment :: Preload { path, address, .. } => {
313- let path_original = env:: var ( KEY_PRELOAD_PATH ) . unwrap_or_else ( |_| String :: new ( ) ) ;
329+ let path_original =
330+ std:: env:: var ( KEY_PRELOAD_PATH ) . unwrap_or_else ( |_| String :: new ( ) ) ;
314331 let path_updated = InterceptEnvironment :: insert_to_path (
315332 & path_original,
316333 Self :: path_to_string ( path) ,
0 commit comments