Skip to content

Commit 36abd6a

Browse files
committed
feat(stackable-telemetry): Add a settings builder for the otlp log exporter
1 parent 0455419 commit 36abd6a

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ use tracing::level_filters::LevelFilter;
33
pub mod console_log;
44
pub use console_log::*;
55

6+
pub mod otlp_log;
7+
pub use otlp_log::*;
8+
69
pub mod otlp_trace;
710
pub use otlp_trace::*;
811

@@ -52,6 +55,15 @@ impl Build<ConsoleLogSettings> for SettingsBuilder {
5255
}
5356
}
5457

58+
impl Build<OtlpLogSettings> for SettingsBuilder {
59+
fn build(self) -> OtlpLogSettings {
60+
OtlpLogSettings {
61+
common_settings: self.into(),
62+
..Default::default()
63+
}
64+
}
65+
}
66+
5567
impl Build<OtlpTraceSettings> for SettingsBuilder {
5668
fn build(self) -> OtlpTraceSettings {
5769
OtlpTraceSettings {
@@ -86,6 +98,10 @@ impl SettingsBuilder {
8698
self.into()
8799
}
88100

101+
pub fn otlp_log_builder(self) -> OtlpLogSettingsBuilder {
102+
self.into()
103+
}
104+
89105
pub fn otlp_trace_builder(self) -> OtlpTraceSettingsBuilder {
90106
self.into()
91107
}
@@ -120,6 +136,14 @@ impl From<SettingsBuilder> for ConsoleLogSettingsBuilder {
120136
}
121137
}
122138

139+
impl From<SettingsBuilder> for OtlpLogSettingsBuilder {
140+
fn from(value: SettingsBuilder) -> Self {
141+
Self {
142+
common_settings: value.into(),
143+
}
144+
}
145+
}
146+
123147
impl From<SettingsBuilder> for OtlpTraceSettingsBuilder {
124148
fn from(value: SettingsBuilder) -> Self {
125149
Self {
@@ -162,6 +186,25 @@ mod test {
162186
assert_eq!(expected, result);
163187
}
164188

189+
#[test]
190+
fn builds_otlp_log_settings() {
191+
let expected = OtlpLogSettings {
192+
common_settings: Settings {
193+
environment_variable: "hello",
194+
enabled: true,
195+
default_level: LevelFilter::DEBUG,
196+
},
197+
};
198+
let result: OtlpLogSettings = Settings::builder()
199+
.enabled(true)
200+
.env_var("hello")
201+
.default_level(LevelFilter::DEBUG)
202+
.otlp_log_builder()
203+
.build();
204+
205+
assert_eq!(expected, result);
206+
}
207+
165208
#[test]
166209
fn builds_otlp_trace_settings() {
167210
let expected = OtlpTraceSettings {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use super::Settings;
2+
3+
#[derive(Debug, Default, PartialEq)]
4+
pub struct OtlpLogSettings {
5+
pub common_settings: Settings,
6+
}
7+
8+
pub struct OtlpLogSettingsBuilder {
9+
pub(crate) common_settings: Settings,
10+
}
11+
12+
impl OtlpLogSettingsBuilder {
13+
pub fn build(self) -> OtlpLogSettings {
14+
self.into()
15+
}
16+
}
17+
18+
impl From<OtlpLogSettingsBuilder> for OtlpLogSettings {
19+
fn from(value: OtlpLogSettingsBuilder) -> Self {
20+
Self {
21+
common_settings: value.common_settings,
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)