@@ -14,6 +14,8 @@ use crate::{
1414 timer:: Timer ,
1515} ;
1616
17+ const LOG_TAG : & str = "Pyroscope::Agent" ;
18+
1719/// Pyroscope Agent Configuration. This is the configuration that is passed to the agent.
1820/// # Example
1921/// ```
@@ -58,7 +60,7 @@ impl PyroscopeConfig {
5860 /// ```ignore
5961 /// let mut config = PyroscopeConfig::new("http://localhost:8080", "my-app");
6062 /// config.set_sample_rate(10)
61- /// .unwrap() ;
63+ /// ? ;
6264 /// ```
6365 pub fn sample_rate ( self , sample_rate : i32 ) -> Self {
6466 Self {
@@ -72,8 +74,7 @@ impl PyroscopeConfig {
7274 /// ```ignore
7375 /// use pyroscope::pyroscope::PyroscopeConfig;
7476 /// let config = PyroscopeConfig::new("http://localhost:8080", "my-app")
75- /// .tags(vec![("env", "dev")])
76- /// .unwrap();
77+ /// .tags(vec![("env", "dev")])?;
7778 /// ```
7879 pub fn tags ( self , tags : & [ ( & str , & str ) ] ) -> Self {
7980 // Convert &[(&str, &str)] to HashMap(String, String)
@@ -100,7 +101,7 @@ impl PyroscopeConfig {
100101/// ```ignore
101102/// use pyroscope::pyroscope::PyroscopeAgentBuilder;
102103/// let builder = PyroscopeAgentBuilder::new("http://localhost:8080", "my-app");
103- /// let agent = builder.build().unwrap() ;
104+ /// let agent = builder.build()? ;
104105/// ```
105106pub struct PyroscopeAgentBuilder {
106107 /// Profiler backend
@@ -130,7 +131,7 @@ impl PyroscopeAgentBuilder {
130131 /// let builder = PyroscopeAgentBuilder::new("http://localhost:8080", "my-app")
131132 /// .backend(Pprof::default())
132133 /// .build()
133- /// .unwrap() ;
134+ /// ? ;
134135 /// ```
135136 pub fn backend < T > ( self , backend : T ) -> Self
136137 where T : ' static + Backend {
@@ -146,7 +147,7 @@ impl PyroscopeAgentBuilder {
146147 /// let builder = PyroscopeAgentBuilder::new("http://localhost:8080", "my-app")
147148 /// .sample_rate(99)
148149 /// .build()
149- /// .unwrap() ;
150+ /// ? ;
150151 /// ```
151152 pub fn sample_rate ( self , sample_rate : i32 ) -> Self {
152153 Self {
@@ -161,7 +162,7 @@ impl PyroscopeAgentBuilder {
161162 /// let builder = PyroscopeAgentBuilder::new("http://localhost:8080", "my-app")
162163 /// .tags(vec![("env", "dev")])
163164 /// .build()
164- /// .unwrap() ;
165+ /// ? ;
165166 /// ```
166167 pub fn tags ( self , tags : & [ ( & str , & str ) ] ) -> Self {
167168 Self {
@@ -175,15 +176,15 @@ impl PyroscopeAgentBuilder {
175176 // Initiliaze the backend
176177 let backend = Arc :: clone ( & self . backend ) ;
177178 backend. lock ( ) ?. initialize ( self . config . sample_rate ) ?;
178- log:: trace!( "PyroscopeAgent - Backend initialized") ;
179+ log:: trace!( target : LOG_TAG , " Backend initialized") ;
179180
180181 // Start Timer
181182 let timer = Timer :: default ( ) . initialize ( ) ?;
182- log:: trace!( "PyroscopeAgent - Timer initialized") ;
183+ log:: trace!( target : LOG_TAG , " Timer initialized") ;
183184
184185 // Start the SessionManager
185186 let session_manager = SessionManager :: new ( ) ?;
186- log:: trace!( "PyroscopeAgent - SessionManager initialized") ;
187+ log:: trace!( target : LOG_TAG , " SessionManager initialized") ;
187188
188189 // Return PyroscopeAgent
189190 Ok ( PyroscopeAgent {
@@ -217,44 +218,45 @@ pub struct PyroscopeAgent {
217218impl Drop for PyroscopeAgent {
218219 /// Properly shutdown the agent.
219220 fn drop ( & mut self ) {
220- log:: debug!( "PyroscopeAgent - Dropping Agent ") ;
221+ log:: debug!( target : LOG_TAG , "PyroscopeAgent::drop() ") ;
221222
222223 // Drop Timer listeners
223224 match self . timer . drop_listeners ( ) {
224- Ok ( _) => log:: trace!( "PyroscopeAgent - Dropped timer listeners") ,
225- Err ( _) => log:: error!( "PyroscopeAgent - Error Dropping timer listeners") ,
225+ Ok ( _) => log:: trace!( target : LOG_TAG , " Dropped timer listeners") ,
226+ Err ( _) => log:: error!( target : LOG_TAG , " Error Dropping timer listeners") ,
226227 }
227228
228229 // Wait for the Timer thread to finish
229230 if let Some ( handle) = self . timer . handle . take ( ) {
230231 match handle. join ( ) {
231- Ok ( _) => log:: trace!( "PyroscopeAgent - Dropped timer thread") ,
232- Err ( _) => log:: error!( "PyroscopeAgent - Error Dropping timer thread") ,
232+ Ok ( _) => log:: trace!( target : LOG_TAG , " Dropped timer thread") ,
233+ Err ( _) => log:: error!( target : LOG_TAG , " Error Dropping timer thread") ,
233234 }
234235 }
235236
236237 // Stop the SessionManager
237238 match self . session_manager . push ( SessionSignal :: Kill ) {
238- Ok ( _) => log:: trace!( "PyroscopeAgent - Sent kill signal to SessionManager") ,
239- Err ( _) => log:: error!( "PyroscopeAgent - Error sending kill signal to SessionManager") ,
239+ Ok ( _) => log:: trace!( target : LOG_TAG , " Sent kill signal to SessionManager") ,
240+ Err ( _) => log:: error!( target : LOG_TAG , " Error sending kill signal to SessionManager") ,
240241 }
241242
242243 if let Some ( handle) = self . session_manager . handle . take ( ) {
243244 match handle. join ( ) {
244- Ok ( _) => log:: trace!( "PyroscopeAgent - Dropped SessionManager thread") ,
245- Err ( _) => log:: error!( "PyroscopeAgent - Error Dropping SessionManager thread") ,
245+ Ok ( _) => log:: trace!( target : LOG_TAG , " Dropped SessionManager thread") ,
246+ Err ( _) => log:: error!( target : LOG_TAG , " Error Dropping SessionManager thread") ,
246247 }
247248 }
248249
249250 // Wait for main thread to finish
251+
250252 if let Some ( handle) = self . handle . take ( ) {
251253 match handle. join ( ) {
252- Ok ( _) => log:: trace!( "PyroscopeAgent - Dropped main thread") ,
253- Err ( _) => log:: error!( "PyroscopeAgent - Error Dropping main thread") ,
254+ Ok ( _) => log:: trace!( target : LOG_TAG , " Dropped main thread") ,
255+ Err ( _) => log:: error!( target : LOG_TAG , " Error Dropping main thread") ,
254256 }
255257 }
256258
257- log:: debug!( "PyroscopeAgent - Agent Dropped") ;
259+ log:: debug!( target : LOG_TAG , " Agent Dropped") ;
258260 }
259261}
260262
@@ -263,15 +265,15 @@ impl PyroscopeAgent {
263265 ///
264266 /// # Example
265267 /// ```ignore
266- /// let agent = PyroscopeAgent::builder("http://localhost:8080", "my-app").build().unwrap() ;
268+ /// let agent = PyroscopeAgent::builder("http://localhost:8080", "my-app").build()? ;
267269 /// ```
268270 pub fn builder < S : AsRef < str > > ( url : S , application_name : S ) -> PyroscopeAgentBuilder {
269271 // Build PyroscopeAgent
270272 PyroscopeAgentBuilder :: new ( url, application_name)
271273 }
272274
273275 fn _start ( & mut self ) -> Result < ( ) > {
274- log:: debug!( "PyroscopeAgent - Starting") ;
276+ log:: debug!( target : LOG_TAG , " Starting") ;
275277
276278 // Create a clone of Backend
277279 let backend = Arc :: clone ( & self . backend ) ;
@@ -294,10 +296,10 @@ impl PyroscopeAgent {
294296 let stx = self . session_manager . tx . clone ( ) ;
295297
296298 self . handle = Some ( std:: thread:: spawn ( move || {
297- log:: trace!( "PyroscopeAgent - Main Thread started") ;
299+ log:: trace!( target : LOG_TAG , " Main Thread started") ;
298300
299301 while let Ok ( until) = rx. recv ( ) {
300- log:: trace!( "PyroscopeAgent - Sending session {}", until) ;
302+ log:: trace!( target : LOG_TAG , " Sending session {}", until) ;
301303
302304 // Generate report from backend
303305 let report = backend. lock ( ) ?. report ( ) ?;
@@ -310,7 +312,7 @@ impl PyroscopeAgent {
310312 ) ?) ) ?;
311313
312314 if until == 0 {
313- log:: trace!( "PyroscopeAgent - Session Killed") ;
315+ log:: trace!( target : LOG_TAG , " Session Killed") ;
314316
315317 let ( lock, cvar) = & * pair;
316318 let mut running = lock. lock ( ) ?;
@@ -329,18 +331,18 @@ impl PyroscopeAgent {
329331 /// Start profiling and sending data. The agent will keep running until stopped. The agent will send data to the server every 10s secondy.
330332 /// # Example
331333 /// ```ignore
332- /// let agent = PyroscopeAgent::builder("http://localhost:8080", "my-app").build().unwrap() ;
334+ /// let agent = PyroscopeAgent::builder("http://localhost:8080", "my-app").build()? ;
333335 /// agent.start();
334336 /// ```
335337 pub fn start ( & mut self ) {
336338 match self . _start ( ) {
337- Ok ( _) => log:: trace!( "PyroscopeAgent - Agent started") ,
338- Err ( _) => log:: error!( "PyroscopeAgent - Error starting agent") ,
339+ Ok ( _) => log:: trace!( target : LOG_TAG , " Agent started") ,
340+ Err ( _) => log:: error!( target : LOG_TAG , " Error starting agent") ,
339341 }
340342 }
341343
342344 fn _stop ( & mut self ) -> Result < ( ) > {
343- log:: debug!( "PyroscopeAgent - Stopping") ;
345+ log:: debug!( target : LOG_TAG , " Stopping") ;
344346 // get tx and send termination signal
345347 if let Some ( sender) = self . tx . take ( ) {
346348 sender. send ( 0 ) ?;
@@ -371,8 +373,8 @@ impl PyroscopeAgent {
371373 /// ```
372374 pub fn stop ( & mut self ) {
373375 match self . _stop ( ) {
374- Ok ( _) => log:: trace!( "PyroscopeAgent - Agent stopped") ,
375- Err ( _) => log:: error!( "PyroscopeAgent - Error stopping agent") ,
376+ Ok ( _) => log:: trace!( target : LOG_TAG , " Agent stopped") ,
377+ Err ( _) => log:: error!( target : LOG_TAG , " Error stopping agent") ,
376378 }
377379 }
378380
@@ -387,7 +389,7 @@ impl PyroscopeAgent {
387389 /// agent.stop()?;
388390 /// ```
389391 pub fn add_tags ( & mut self , tags : & [ ( & str , & str ) ] ) -> Result < ( ) > {
390- log:: debug!( "PyroscopeAgent - Adding tags") ;
392+ log:: debug!( target : LOG_TAG , " Adding tags") ;
391393 // Check that tags are not empty
392394 if tags. is_empty ( ) {
393395 return Ok ( ( ) ) ;
@@ -430,7 +432,7 @@ impl PyroscopeAgent {
430432 /// # }
431433 /// ```
432434 pub fn remove_tags ( & mut self , tags : & [ & str ] ) -> Result < ( ) > {
433- log:: debug!( "PyroscopeAgent - Removing tags") ;
435+ log:: debug!( target : LOG_TAG , " Removing tags") ;
434436
435437 // Check that tags are not empty
436438 if tags. is_empty ( ) {
0 commit comments