Skip to content

Commit 9d958e4

Browse files
committed
chore(stackable-telemetry): Add SettingsDouble and SettingsTriple tuple and From impls as a config shortcut similar to before this PR
1 parent 1adfc73 commit 9d958e4

File tree

5 files changed

+94
-21
lines changed

5 files changed

+94
-21
lines changed

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum Error {
4444
///
4545
/// # Usage:
4646
/// ```
47-
/// use stackable_telemetry::tracing::{Tracing, Error};
47+
/// use stackable_telemetry::tracing::{Tracing, Error, settings::{Build as _, Settings}};
4848
/// use tracing_subscriber::filter::LevelFilter;
4949
///
5050
/// #[tokio::main]
@@ -53,9 +53,15 @@ pub enum Error {
5353
/// // `let _ =`, as that will drop immediately.
5454
/// let _tracing_guard = Tracing::builder()
5555
/// .service_name("test")
56-
/// .with_console_output("TEST_CONSOLE", LevelFilter::INFO)
57-
/// .with_otlp_log_exporter("TEST_OTLP_LOG", LevelFilter::DEBUG)
58-
/// .with_otlp_trace_exporter("TEST_OTLP_TRACE", LevelFilter::TRACE)
56+
/// .with_console_output(
57+
/// Settings::builder()
58+
/// .environment_variable("TEST_CONSOLE")
59+
/// .default_level(LevelFilter::INFO)
60+
/// .enabled(true)
61+
/// .build()
62+
/// )
63+
/// .with_otlp_log_exporter(("TEST_OTLP_LOG", LevelFilter::DEBUG).into())
64+
/// .with_otlp_trace_exporter(("TEST_OTLP_TRACE", LevelFilter::TRACE).into())
5965
/// .build()
6066
/// .init()?;
6167
///
@@ -483,20 +489,8 @@ mod test {
483489
.enabled(true)
484490
.build(),
485491
)
486-
.with_otlp_log_exporter(
487-
Settings::builder()
488-
.env_var("ABC_OTLP_LOG")
489-
.default_level(LevelFilter::DEBUG)
490-
.enabled(true)
491-
.build(),
492-
)
493-
.with_otlp_trace_exporter(
494-
Settings::builder()
495-
.env_var("ABC_OTLP_TRACE")
496-
.default_level(LevelFilter::TRACE)
497-
.enabled(true)
498-
.build(),
499-
)
492+
.with_otlp_log_exporter(("ABC_OTLP_LOG", LevelFilter::DEBUG).into())
493+
.with_otlp_trace_exporter(("ABC_OTLP_TRACE", LevelFilter::TRACE).into())
500494
.build();
501495

502496
assert_eq!(

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use tracing::level_filters::LevelFilter;
22

3-
use super::{Build, CommonSettings, Settings, SettingsBuilder};
3+
use super::{Build, CommonSettings, Settings, SettingsBuilder, SettingsDouble, SettingsTriple};
44

55
#[derive(Debug, Default, PartialEq)]
66
pub struct ConsoleLogSettings {
@@ -73,6 +73,24 @@ impl CommonSettings for ConsoleLogSettings {
7373
}
7474
}
7575

76+
impl From<SettingsDouble> for ConsoleLogSettings {
77+
fn from(value: SettingsDouble) -> Self {
78+
Self {
79+
common_settings: value.into(),
80+
..Default::default()
81+
}
82+
}
83+
}
84+
85+
impl From<SettingsTriple> for ConsoleLogSettings {
86+
fn from(value: SettingsTriple) -> Self {
87+
Self {
88+
common_settings: value.into(),
89+
..Default::default()
90+
}
91+
}
92+
}
93+
7694
#[cfg(test)]
7795
mod test {
7896
use tracing::level_filters::LevelFilter;

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,31 @@ impl From<SettingsBuilder> for Settings {
102102
}
103103
}
104104

105+
pub(crate) type SettingsDouble = (&'static str, LevelFilter);
106+
pub(crate) type SettingsTriple = (&'static str, LevelFilter, bool);
107+
108+
// for enabling a subscriber in one line with no extra settings
109+
impl From<SettingsDouble> for Settings {
110+
fn from((environment_variable, default_level): SettingsDouble) -> Self {
111+
Settings {
112+
environment_variable,
113+
default_level,
114+
enabled: true,
115+
}
116+
}
117+
}
118+
119+
// for configuring a subscriber in one line with no extra settings
120+
impl From<SettingsTriple> for Settings {
121+
fn from((environment_variable, default_level, enabled): SettingsTriple) -> Self {
122+
Settings {
123+
environment_variable,
124+
default_level,
125+
enabled,
126+
}
127+
}
128+
}
129+
105130
#[cfg(test)]
106131
mod test {
107132
use super::*;

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use tracing::level_filters::LevelFilter;
22

3-
use super::{Build, CommonSettings, Settings, SettingsBuilder};
3+
use super::{Build, CommonSettings, Settings, SettingsBuilder, SettingsDouble, SettingsTriple};
44

55
#[derive(Debug, Default, PartialEq)]
66
pub struct OtlpLogSettings {
@@ -56,6 +56,24 @@ impl CommonSettings for OtlpLogSettings {
5656
}
5757
}
5858

59+
impl From<SettingsDouble> for OtlpLogSettings {
60+
fn from(value: SettingsDouble) -> Self {
61+
Self {
62+
common_settings: value.into(),
63+
..Default::default()
64+
}
65+
}
66+
}
67+
68+
impl From<SettingsTriple> for OtlpLogSettings {
69+
fn from(value: SettingsTriple) -> Self {
70+
Self {
71+
common_settings: value.into(),
72+
..Default::default()
73+
}
74+
}
75+
}
76+
5977
#[cfg(test)]
6078
mod test {
6179
use tracing::level_filters::LevelFilter;

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use tracing::level_filters::LevelFilter;
22

3-
use super::{Build, CommonSettings, Settings, SettingsBuilder};
3+
use super::{Build, CommonSettings, Settings, SettingsBuilder, SettingsDouble, SettingsTriple};
44

55
#[derive(Debug, Default, PartialEq)]
66
pub struct OtlpTraceSettings {
@@ -56,6 +56,24 @@ impl CommonSettings for OtlpTraceSettings {
5656
}
5757
}
5858

59+
impl From<SettingsDouble> for OtlpTraceSettings {
60+
fn from(value: SettingsDouble) -> Self {
61+
Self {
62+
common_settings: value.into(),
63+
..Default::default()
64+
}
65+
}
66+
}
67+
68+
impl From<SettingsTriple> for OtlpTraceSettings {
69+
fn from(value: SettingsTriple) -> Self {
70+
Self {
71+
common_settings: value.into(),
72+
..Default::default()
73+
}
74+
}
75+
}
76+
5977
#[cfg(test)]
6078
mod test {
6179
use tracing::level_filters::LevelFilter;

0 commit comments

Comments
 (0)