@@ -104,11 +104,11 @@ pub enum Error {
104
104
/// #[tokio::main]
105
105
/// async fn main() -> Result<(), Error> {
106
106
/// let options = TelemetryOptions {
107
- /// no_console_output : false,
108
- /// rolling_logs : None,
109
- /// rolling_logs_period : None,
110
- /// otlp_traces : true,
111
- /// otlp_logs : true,
107
+ /// console_log_disabled : false,
108
+ /// file_log_directory : None,
109
+ /// file_log_rotation_period : None,
110
+ /// otel_trace_exporter_enabled : true,
111
+ /// otel_log_exporter_enabled : true,
112
112
/// };
113
113
///
114
114
/// let _tracing_guard = Tracing::pre_configured("test", options).init()?;
@@ -120,7 +120,9 @@ pub enum Error {
120
120
/// ```
121
121
///
122
122
/// Also see the documentation for [`TelemetryOptions`] which details how it can be used as CLI
123
- /// arguments via [`clap`].
123
+ /// arguments via [`clap`]. Additionally see [this section](#environment-variables-and-cli-arguments)
124
+ /// in the docs for a full list of environment variables and CLI arguments used by the pre-configured
125
+ /// instance.
124
126
///
125
127
/// ## Builders
126
128
///
@@ -213,6 +215,29 @@ pub enum Error {
213
215
/// }
214
216
/// ```
215
217
///
218
+ /// ## Environment Variables and CLI Arguments
219
+ ///
220
+ /// ### Console logs
221
+ ///
222
+ /// - `CONSOLE_LOG_DISABLED` (`--console-log-disabled`): Disables console logs when set to `true`.
223
+ /// - `CONSOLE_LOG_LEVEL`: Set the log level for the console logs.
224
+ ///
225
+ /// ### File logs
226
+ ///
227
+ /// - `FILE_LOG_DIRECTORY` (`--file-log-directory`): Enable the file logs and set the file log directory.
228
+ /// - `FILE_LOG_ROTATION_PERIOD` (`--file-log-rotation-period`): Set the rotation period of log files
229
+ /// - `FILE_LOG_LEVEL`: Set the log level for file logs
230
+ ///
231
+ /// ### OTEL logs
232
+ ///
233
+ /// - `OTEL_LOG_EXPORTER_ENABLED` (`--otel-log-exporter-enabled`): Enable exporting OTEL logs
234
+ /// - `OTEL_LOG_EXPORTER_LEVEL`: Set the log level for OTEL logs
235
+ ///
236
+ /// ### OTEL traces
237
+ ///
238
+ /// - `OTEL_TRACE_EXPORTER_ENABLED` (`--otel-trace-exporter-enabled`): Enable exporting OTEL traces
239
+ /// - `OTEL_TRACE_EXPORTER_LEVEL`: Set the log level for OTEL traces
240
+ ///
216
241
/// # Additional Configuration
217
242
///
218
243
/// You can configure the OTLP trace and log exports through the variables defined in the opentelemetry crates:
@@ -286,15 +311,15 @@ pub struct Tracing {
286
311
287
312
impl Tracing {
288
313
/// The environment variable used to set the console log level filter.
289
- pub const CONSOLE_LOG_ENV_VAR : & str = "CONSOLE_LOG " ;
314
+ pub const CONSOLE_LOG_LEVEL_ENV : & str = "CONSOLE_LOG_LEVEL " ;
290
315
/// The environment variable used to set the rolling file log level filter.
291
- pub const FILE_LOG_ENV_VAR : & str = "FILE_LOG " ;
316
+ pub const FILE_LOG_LEVEL_ENV : & str = "FILE_LOG_LEVEL " ;
292
317
/// The filename used for the rolling file logs.
293
318
pub const FILE_LOG_SUFFIX : & str = "tracing-rs.json" ;
294
- /// The environment variable used to set the OTLP log level filter.
295
- pub const OTLP_LOG_ENV_VAR : & str = "OTLP_LOG " ;
296
- /// The environment variable used to set the OTLP trace level filter.
297
- pub const OTLP_TRACE_ENV_VAR : & str = "OTLP_TRACE " ;
319
+ /// The environment variable used to set the OTEL log level filter.
320
+ pub const OTEL_LOG_EXPORTER_LEVEL_ENV : & str = "OTEL_LOG_EXPORTER_LEVEL " ;
321
+ /// The environment variable used to set the OTEL trace level filter.
322
+ pub const OTEL_TRACE_EXPORTER_LEVEL_ENV : & str = "OTEL_TRACE_EXPORTER_LEVEL " ;
298
323
299
324
/// Creates and returns a [`TracingBuilder`].
300
325
pub fn builder ( ) -> TracingBuilder < builder_state:: PreServiceName > {
@@ -304,47 +329,56 @@ impl Tracing {
304
329
/// Creates an returns a pre-configured [`Tracing`] instance which can be initialized by
305
330
/// calling [`Tracing::init()`].
306
331
///
307
- /// ### Environment Variables and Default Levels
332
+ /// Also see [this section](#environment-variables-and-cli-arguments) in the docs for all full
333
+ /// list of environment variables and CLI arguments used by the pre-configured instance.
334
+ ///
335
+ /// ### Default Levels
308
336
///
309
- /// | Level Filter for | Environment Variable | Default Level |
310
- /// | ---------------- | ------------------------------------------ | ------------- |
311
- /// | Console logs | [`CONSOLE_LOG`](Self::CONSOLE_LOG_ENV_VAR) | `INFO` |
312
- /// | File logs | [`FILE_LOG`](Self::FILE_LOG_ENV_VAR) | `INFO` |
313
- /// | OTLP logs | [`OTLP_LOG`](Self::OTLP_LOG_ENV_VAR) | `INFO` |
314
- /// | OTLP traces | [`OTLP_TRACE`](Self::OTLP_TRACE_ENV_VAR) | `INFO` |
337
+ /// - Console logs: INFO
338
+ /// - File logs: INFO
339
+ /// - OTEL logs: INFO
340
+ /// - OTEL traces: INFO
315
341
///
316
342
/// ### Default Values
317
343
///
318
344
/// - If `rolling_logs_period` is [`None`], this function will use a default value of
319
- /// [`RollingPeriod ::Never`].
345
+ /// [`RotationPeriod ::Never`].
320
346
pub fn pre_configured ( service_name : & ' static str , options : TelemetryOptions ) -> Self {
321
347
let TelemetryOptions {
322
- no_console_output ,
323
- rolling_logs ,
324
- rolling_logs_period ,
325
- otlp_traces ,
326
- otlp_logs ,
348
+ console_log_disabled ,
349
+ file_log_directory ,
350
+ file_log_rotation_period ,
351
+ otel_trace_exporter_enabled ,
352
+ otel_log_exporter_enabled ,
327
353
} = options;
328
354
329
- let rolling_logs_period = rolling_logs_period . unwrap_or_default ( ) ;
355
+ let file_log_rotation_period = file_log_rotation_period . unwrap_or_default ( ) ;
330
356
331
357
Self :: builder ( )
332
358
. service_name ( service_name)
333
359
. with_console_output ( (
334
- Self :: CONSOLE_LOG_ENV_VAR ,
360
+ Self :: CONSOLE_LOG_LEVEL_ENV ,
335
361
LevelFilter :: INFO ,
336
- !no_console_output ,
362
+ !console_log_disabled ,
337
363
) )
338
- . with_file_output ( rolling_logs . map ( |log_directory| {
364
+ . with_file_output ( file_log_directory . map ( |log_directory| {
339
365
Settings :: builder ( )
340
- . with_environment_variable ( Self :: FILE_LOG_ENV_VAR )
366
+ . with_environment_variable ( Self :: FILE_LOG_LEVEL_ENV )
341
367
. with_default_level ( LevelFilter :: INFO )
342
368
. file_log_settings_builder ( log_directory, Self :: FILE_LOG_SUFFIX )
343
- . with_rotation_period ( rolling_logs_period )
369
+ . with_rotation_period ( file_log_rotation_period )
344
370
. build ( )
345
371
} ) )
346
- . with_otlp_log_exporter ( ( Self :: OTLP_LOG_ENV_VAR , LevelFilter :: INFO , otlp_logs) )
347
- . with_otlp_trace_exporter ( ( Self :: OTLP_TRACE_ENV_VAR , LevelFilter :: INFO , otlp_traces) )
372
+ . with_otlp_log_exporter ( (
373
+ Self :: OTEL_LOG_EXPORTER_LEVEL_ENV ,
374
+ LevelFilter :: INFO ,
375
+ otel_log_exporter_enabled,
376
+ ) )
377
+ . with_otlp_trace_exporter ( (
378
+ Self :: OTEL_TRACE_EXPORTER_LEVEL_ENV ,
379
+ LevelFilter :: INFO ,
380
+ otel_trace_exporter_enabled,
381
+ ) )
348
382
. build ( )
349
383
}
350
384
@@ -723,43 +757,39 @@ struct Cli {
723
757
#[ cfg_attr( feature = "clap" , derive( clap:: Args , PartialEq , Eq ) ) ]
724
758
#[ derive( Debug , Default ) ]
725
759
pub struct TelemetryOptions {
726
- /// Disable console output .
760
+ /// Disable console logs .
727
761
#[ cfg_attr( feature = "clap" , arg( long, env) ) ]
728
- pub no_console_output : bool ,
762
+ pub console_log_disabled : bool ,
729
763
730
- /// Enable logging to rolling files located in the specified DIRECTORY.
764
+ /// Enable logging to files located in the specified DIRECTORY.
731
765
#[ cfg_attr(
732
766
feature = "clap" ,
733
- arg(
734
- long,
735
- env = "ROLLING_LOGS_DIR" ,
736
- value_name = "DIRECTORY" ,
737
- group = "rolling_logs_group"
738
- )
767
+ arg( long, env, value_name = "DIRECTORY" , group = "file_log" )
739
768
) ]
740
- pub rolling_logs : Option < PathBuf > ,
769
+ pub file_log_directory : Option < PathBuf > ,
741
770
742
771
/// Time PERIOD after which log files are rolled over.
743
772
#[ cfg_attr(
744
773
feature = "clap" ,
745
- arg( long, env, value_name = "PERIOD" , requires = "rolling_logs_group " )
774
+ arg( long, env, value_name = "PERIOD" , requires = "file_log " )
746
775
) ]
747
- pub rolling_logs_period : Option < RollingPeriod > ,
776
+ pub file_log_rotation_period : Option < RotationPeriod > ,
748
777
749
- /// Enable exporting traces via OTLP.
778
+ /// Enable exporting OpenTelemetry traces via OTLP.
750
779
#[ cfg_attr( feature = "clap" , arg( long, env) ) ]
751
- pub otlp_traces : bool ,
780
+ pub otel_trace_exporter_enabled : bool ,
752
781
753
- /// Enable exporting logs via OTLP.
782
+ /// Enable exporting OpenTelemetry logs via OTLP.
754
783
#[ cfg_attr( feature = "clap" , arg( long, env) ) ]
755
- pub otlp_logs : bool ,
784
+ pub otel_log_exporter_enabled : bool ,
756
785
}
757
786
758
787
/// Supported periods when the log file is rolled over.
759
788
#[ cfg_attr( feature = "clap" , derive( clap:: ValueEnum ) ) ]
760
789
#[ derive( Clone , Debug , Default , PartialEq , Eq , strum:: Display , strum:: EnumString ) ]
790
+ #[ strum( serialize_all = "PascalCase" ) ]
761
791
#[ allow( missing_docs) ]
762
- pub enum RollingPeriod {
792
+ pub enum RotationPeriod {
763
793
Minutely ,
764
794
Hourly ,
765
795
Daily ,
@@ -768,13 +798,13 @@ pub enum RollingPeriod {
768
798
Never ,
769
799
}
770
800
771
- impl From < RollingPeriod > for Rotation {
772
- fn from ( value : RollingPeriod ) -> Self {
801
+ impl From < RotationPeriod > for Rotation {
802
+ fn from ( value : RotationPeriod ) -> Self {
773
803
match value {
774
- RollingPeriod :: Minutely => Self :: MINUTELY ,
775
- RollingPeriod :: Hourly => Self :: HOURLY ,
776
- RollingPeriod :: Daily => Self :: DAILY ,
777
- RollingPeriod :: Never => Self :: NEVER ,
804
+ RotationPeriod :: Minutely => Self :: MINUTELY ,
805
+ RotationPeriod :: Hourly => Self :: HOURLY ,
806
+ RotationPeriod :: Daily => Self :: DAILY ,
807
+ RotationPeriod :: Never => Self :: NEVER ,
778
808
}
779
809
}
780
810
}
@@ -982,11 +1012,11 @@ mod test {
982
1012
#[ test]
983
1013
fn pre_configured ( ) {
984
1014
let tracing = Tracing :: pre_configured ( "test" , TelemetryOptions {
985
- no_console_output : false ,
986
- rolling_logs : None ,
987
- rolling_logs_period : None ,
988
- otlp_traces : true ,
989
- otlp_logs : false ,
1015
+ console_log_disabled : false ,
1016
+ file_log_directory : None ,
1017
+ file_log_rotation_period : None ,
1018
+ otel_trace_exporter_enabled : true ,
1019
+ otel_log_exporter_enabled : false ,
990
1020
} ) ;
991
1021
992
1022
assert ! ( tracing. otlp_trace_settings. is_enabled( ) ) ;
0 commit comments