@@ -218,9 +218,9 @@ pub enum Error {
218218pub struct Tracing {
219219 service_name : & ' static str ,
220220 console_log_settings : ConsoleLogSettings ,
221- file_log_settings : Option < FileLogSettings > ,
222- otlp_log_settings : Option < OtlpLogSettings > ,
223- otlp_trace_settings : Option < OtlpTraceSettings > ,
221+ file_log_settings : FileLogSettings ,
222+ otlp_log_settings : OtlpLogSettings ,
223+ otlp_trace_settings : OtlpTraceSettings ,
224224 logger_provider : Option < LoggerProvider > ,
225225}
226226
@@ -253,18 +253,22 @@ impl Tracing {
253253 layers. push ( console_output_layer. boxed ( ) ) ;
254254 }
255255
256- if let Some ( file_log_settings) = & self . file_log_settings {
256+ if let FileLogSettings :: Enabled {
257+ common_settings,
258+ file_log_dir,
259+ } = & self . file_log_settings
260+ {
257261 let env_filter_layer = env_filter_builder (
258- file_log_settings . common_settings . environment_variable ,
259- file_log_settings . default_level ,
262+ common_settings. environment_variable ,
263+ common_settings . default_level ,
260264 ) ;
261265
262266 let file_appender = RollingFileAppender :: builder ( )
263267 . rotation ( Rotation :: HOURLY )
264268 . filename_prefix ( self . service_name . to_string ( ) )
265269 . filename_suffix ( "tracing-rs.json" )
266270 . max_log_files ( 6 )
267- . build ( & file_log_settings . file_log_dir )
271+ . build ( & file_log_dir)
268272 . context ( InitRollingFileAppenderSnafu ) ?;
269273
270274 layers. push (
@@ -276,10 +280,10 @@ impl Tracing {
276280 ) ;
277281 }
278282
279- if let Some ( otlp_log_settings ) = & self . otlp_log_settings {
283+ if let OtlpLogSettings :: Enabled { common_settings } = & self . otlp_log_settings {
280284 let env_filter_layer = env_filter_builder (
281- otlp_log_settings . environment_variable ,
282- otlp_log_settings . default_level ,
285+ common_settings . environment_variable ,
286+ common_settings . default_level ,
283287 )
284288 // TODO (@NickLarsenNZ): Remove this directive once https://github.com/open-telemetry/opentelemetry-rust/issues/761 is resolved
285289 . add_directive ( "h2=off" . parse ( ) . expect ( "invalid directive" ) ) ;
@@ -304,10 +308,11 @@ impl Tracing {
304308 self . logger_provider = Some ( otel_log) ;
305309 }
306310
307- if let Some ( otlp_trace_settings ) = & self . otlp_trace_settings {
311+ if let OtlpTraceSettings :: Enabled { common_settings } = & self . otlp_trace_settings {
308312 let env_filter_layer = env_filter_builder (
309- otlp_trace_settings. common_settings . environment_variable ,
310- otlp_trace_settings. default_level ,
313+ // todo, deref?
314+ common_settings. environment_variable ,
315+ common_settings. default_level ,
311316 )
312317 // TODO (@NickLarsenNZ): Remove this directive once https://github.com/open-telemetry/opentelemetry-rust/issues/761 is resolved
313318 . add_directive ( "h2=off" . parse ( ) . expect ( "invalid directive" ) ) ;
@@ -355,12 +360,12 @@ impl Tracing {
355360impl Drop for Tracing {
356361 fn drop ( & mut self ) {
357362 tracing:: debug!(
358- opentelemetry. tracing. enabled = self . otlp_trace_settings. is_some ( ) ,
359- opentelemetry. logger. enabled = self . otlp_log_settings. is_some ( ) ,
363+ opentelemetry. tracing. enabled = self . otlp_trace_settings. is_enabled ( ) ,
364+ opentelemetry. logger. enabled = self . otlp_log_settings. is_enabled ( ) ,
360365 "shutting down opentelemetry OTLP providers"
361366 ) ;
362367
363- if self . otlp_trace_settings . is_some ( ) {
368+ if self . otlp_trace_settings . is_enabled ( ) {
364369 // NOTE (@NickLarsenNZ): This might eventually be replaced with something like SdkMeterProvider::shutdown(&self)
365370 // as has been done with the LoggerProvider (further below)
366371 // see: https://github.com/open-telemetry/opentelemetry-rust/pull/1412/files#r1409608679
@@ -434,9 +439,9 @@ impl BuilderState for builder_state::Config {}
434439pub struct TracingBuilder < S : BuilderState > {
435440 service_name : Option < & ' static str > ,
436441 console_log_settings : ConsoleLogSettings ,
437- otlp_log_settings : Option < OtlpLogSettings > ,
438- otlp_trace_settings : Option < OtlpTraceSettings > ,
439- file_log_settings : Option < FileLogSettings > ,
442+ file_log_settings : FileLogSettings ,
443+ otlp_log_settings : OtlpLogSettings ,
444+ otlp_trace_settings : OtlpTraceSettings ,
440445
441446 /// Allow the generic to be used (needed for impls).
442447 _marker : std:: marker:: PhantomData < S > ,
@@ -486,7 +491,7 @@ impl TracingBuilder<builder_state::Config> {
486491 TracingBuilder {
487492 service_name : self . service_name ,
488493 console_log_settings : self . console_log_settings ,
489- file_log_settings : Some ( file_log_settings. into ( ) ) ,
494+ file_log_settings : file_log_settings. into ( ) ,
490495 otlp_log_settings : self . otlp_log_settings ,
491496 otlp_trace_settings : self . otlp_trace_settings ,
492497 _marker : self . _marker ,
@@ -507,7 +512,7 @@ impl TracingBuilder<builder_state::Config> {
507512 TracingBuilder {
508513 service_name : self . service_name ,
509514 console_log_settings : self . console_log_settings ,
510- otlp_log_settings : Some ( otlp_log_settings. into ( ) ) ,
515+ otlp_log_settings : otlp_log_settings. into ( ) ,
511516 otlp_trace_settings : self . otlp_trace_settings ,
512517 file_log_settings : self . file_log_settings ,
513518 _marker : self . _marker ,
@@ -529,7 +534,7 @@ impl TracingBuilder<builder_state::Config> {
529534 service_name : self . service_name ,
530535 console_log_settings : self . console_log_settings ,
531536 otlp_log_settings : self . otlp_log_settings ,
532- otlp_trace_settings : Some ( otlp_trace_settings. into ( ) ) ,
537+ otlp_trace_settings : otlp_trace_settings. into ( ) ,
533538 file_log_settings : self . file_log_settings ,
534539 _marker : self . _marker ,
535540 }
@@ -607,8 +612,9 @@ mod test {
607612 }
608613 ) ;
609614
610- assert ! ( trace_guard. otlp_log_settings. is_none( ) ) ;
611- assert ! ( trace_guard. otlp_trace_settings. is_none( ) ) ;
615+ assert ! ( trace_guard. file_log_settings. is_disabled( ) ) ;
616+ assert ! ( trace_guard. otlp_log_settings. is_disabled( ) ) ;
617+ assert ! ( trace_guard. otlp_trace_settings. is_disabled( ) ) ;
612618 }
613619
614620 // #[test]
@@ -695,37 +701,38 @@ mod test {
695701 ) ;
696702 assert_eq ! (
697703 trace_guard. file_log_settings,
698- Some ( FileLogSettings {
704+ FileLogSettings :: Enabled {
699705 common_settings: Settings {
700706 environment_variable: "ABC_FILE" ,
701707 default_level: LevelFilter :: INFO
702708 } ,
703709 file_log_dir: PathBuf :: from( "/abc_file_dir" )
704- } )
710+ }
705711 ) ;
706712 assert_eq ! (
707713 trace_guard. otlp_log_settings,
708- Some ( OtlpLogSettings {
714+ OtlpLogSettings :: Enabled {
709715 common_settings: Settings {
710716 environment_variable: "ABC_OTLP_LOG" ,
711717 default_level: LevelFilter :: DEBUG
712718 } ,
713- } )
719+ }
714720 ) ;
715721 assert_eq ! (
716722 trace_guard. otlp_trace_settings,
717- Some ( OtlpTraceSettings {
723+ OtlpTraceSettings :: Enabled {
718724 common_settings: Settings {
719725 environment_variable: "ABC_OTLP_TRACE" ,
720726 default_level: LevelFilter :: TRACE
721727 }
722- } )
728+ }
723729 ) ;
724730 }
725731
726732 #[ test]
727733 fn builder_with_options ( ) {
728734 let enable_console_output = true ;
735+ let enable_filelog_output = true ;
729736 let enable_otlp_trace = true ;
730737 let enable_otlp_log = false ;
731738
@@ -736,6 +743,12 @@ mod test {
736743 . with_environment_variable ( "ABC_CONSOLE" )
737744 . build ( )
738745 } ) )
746+ . with_file_output ( enable_filelog_output. then ( || {
747+ Settings :: builder ( )
748+ . with_environment_variable ( "ABC_FILELOG" )
749+ . file_log_settings_builder ( "/dev/null" )
750+ . build ( )
751+ } ) )
739752 . with_otlp_trace_exporter ( enable_otlp_trace. then ( || {
740753 Settings :: builder ( )
741754 . with_environment_variable ( "ABC_OTLP_TRACE" )
@@ -748,11 +761,9 @@ mod test {
748761 } ) )
749762 . build ( ) ;
750763
751- matches ! (
752- tracing_builder. console_log_settings,
753- ConsoleLogSettings :: Enabled { .. }
754- ) ;
755- assert ! ( tracing_builder. otlp_trace_settings. is_some( ) ) ;
756- // assert!(tracing_builder.otlp_log_settings.is_none());
764+ assert ! ( tracing_builder. console_log_settings. is_enabled( ) ) ;
765+ assert ! ( tracing_builder. file_log_settings. is_enabled( ) ) ;
766+ assert ! ( tracing_builder. otlp_trace_settings. is_enabled( ) ) ;
767+ assert ! ( tracing_builder. otlp_log_settings. is_disabled( ) ) ;
757768 }
758769}
0 commit comments