Skip to content

Commit 951f5cc

Browse files
committed
docs(stackable-telemetry): Partially add docs
Note: More docs will appear in a future PR so that this PR isn't a blocker. Tip: Enable `#![warn(missing_docs)]`
1 parent 2e4f19f commit 951f5cc

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

crates/stackable-telemetry/src/tracing/settings/console_log.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
1+
//! Console Log Subscriber Settings.
2+
13
use tracing::level_filters::LevelFilter;
24

35
use super::{Build, CommonSettings, Settings, SettingsBuilder};
46

7+
/// Configure specific settings for the Console Log subscriber.
58
#[derive(Debug, Default, PartialEq)]
69
pub struct ConsoleLogSettings {
10+
/// Common subscriber settings that apply to the Console Log Subscriber.
711
pub common_settings: Settings,
12+
13+
/// Console Subscriber log event output format.
814
pub log_format: Format,
915
}
1016

17+
/// Console Subscriber log event output formats.
18+
///
19+
/// Currently, only [Plain][Format::Plain] is supported.
1120
#[derive(Debug, Default, PartialEq)]
1221
pub enum Format {
22+
/// Use the plain unstructured log output.
23+
///
24+
/// ANSI color output is enabled by default, but can be disabled at runtime by
25+
/// setting `NO_COLOR` to a non-empty value.
26+
///
27+
/// See: [`Layer::with_ansi`][tracing_subscriber::fmt::Layer::with_ansi].
1328
#[default]
1429
Plain,
1530
// Json { pretty: bool },
1631
// LogFmt,
1732
}
1833

34+
/// For building [`ConsoleLogSettings`].
35+
///
36+
/// <div class="warning">
37+
/// Do not use directly, instead use the [`Settings::builder`] associated function.
38+
/// </div>
1939
pub struct ConsoleLogSettingsBuilder {
2040
pub(crate) common_settings: Settings,
2141
pub(crate) log_format: Format,

crates/stackable-telemetry/src/tracing/settings/mod.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Subscriber settings.
2+
13
use tracing::level_filters::LevelFilter;
24

35
pub mod console_log;
@@ -9,23 +11,40 @@ pub use otlp_log::*;
911
pub mod otlp_trace;
1012
pub use otlp_trace::*;
1113

12-
// this trait is to make it simpler to access common settings from specific settings.
14+
/// Simplifies access common settings from subscriber specific settings.
1315
pub trait CommonSettings {
16+
/// Access to the [`Settings::environment_variable`] field.
1417
fn environment_variable(&self) -> &'static str;
18+
19+
/// Access to the [`Settings::default_level`] field.
1520
fn default_level(&self) -> LevelFilter;
21+
22+
/// Access to the [`Settings::enabled`] field.
1623
fn enabled(&self) -> bool;
1724
}
1825

26+
/// General settings that apply to any subscriber.
1927
#[derive(Debug, PartialEq)]
2028
pub struct Settings {
29+
/// The environment variable used to set the [`LevelFilter`].
30+
///
31+
/// When the environment variable is set, it will override what is set by
32+
/// [`Self::default_level`].
2133
pub environment_variable: &'static str,
2234

35+
/// The [`LevelFilter`] to fallback to if [`Self::environment_variable`] has
36+
/// not been set.
2337
pub default_level: LevelFilter,
2438

39+
/// Whether or not the subscriber is enabled.
40+
///
41+
/// When set to `true`, the [`tracing::Subscriber`] will be added to the
42+
/// [`tracing_subscriber::Layer`] list.
2543
pub enabled: bool,
2644
}
2745

2846
impl Settings {
47+
/// Builder methods to override defaults.
2948
pub fn builder() -> SettingsBuilder {
3049
SettingsBuilder::default()
3150
}
@@ -37,13 +56,16 @@ impl Default for Settings {
3756
}
3857
}
3958

59+
/// For building [`Settings`].
4060
pub struct SettingsBuilder {
4161
environment_variable: &'static str,
4262
enabled: bool,
4363
default_level: LevelFilter,
4464
}
4565

66+
/// Finalizer to be implemented on builders.
4667
pub trait Build<T> {
68+
/// Finalize settings.
4769
fn build(self) -> T;
4870
}
4971

@@ -54,16 +76,27 @@ impl Build<Settings> for SettingsBuilder {
5476
}
5577

5678
impl SettingsBuilder {
79+
/// Set the environment variable used for overriding the [`Settings::default_level`].
80+
///
81+
/// Defaults to `RUST_LOG`.
82+
// TODO (@NickLarsenNZ): set a constant for the default environment variable.
5783
pub fn with_environment_variable(mut self, name: &'static str) -> Self {
5884
self.environment_variable = name;
5985
self
6086
}
6187

88+
/// Set the default [`LevelFilter`].
89+
///
90+
/// Defaults to [`LevelFilter::OFF`].
91+
// TODO (@NickLarsenNZ): set a constant for the default level.
6292
pub fn with_default_level(mut self, level: impl Into<LevelFilter>) -> Self {
6393
self.default_level = level.into();
6494
self
6595
}
6696

97+
/// Enable or disable the [`tracing::Subscriber`].
98+
///
99+
/// Defaults to `false`.
67100
// TODO (@NickLarsenNZ): Currently this has to be called to enable the
68101
// subscriber. Eventually it should become optional, and default to on (if
69102
// settings are supplied). Therefore, the fields in TracingBuilder to hold
@@ -75,14 +108,17 @@ impl SettingsBuilder {
75108
self
76109
}
77110

111+
/// Set specific [`ConsoleLogSettings`].
78112
pub fn console_log_settings_builder(self) -> ConsoleLogSettingsBuilder {
79113
self.into()
80114
}
81115

116+
/// Set specific [`OtlpLogSettings`].
82117
pub fn otlp_log_settings_builder(self) -> OtlpLogSettingsBuilder {
83118
self.into()
84119
}
85120

121+
/// Set specific [`OtlpTraceSettings`].
86122
pub fn otlp_trace_settings_builder(self) -> OtlpTraceSettingsBuilder {
87123
self.into()
88124
}

crates/stackable-telemetry/src/tracing/settings/otlp_log.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! OTLP Log Subscriber Settings.
2+
13
use tracing::level_filters::LevelFilter;
24

35
use super::{Build, CommonSettings, Settings, SettingsBuilder};

crates/stackable-telemetry/src/tracing/settings/otlp_trace.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! OTLP Trace Subscriber Settings.
2+
13
use tracing::level_filters::LevelFilter;
24

35
use super::{Build, CommonSettings, Settings, SettingsBuilder};

0 commit comments

Comments
 (0)