Skip to content

Commit eb0cb94

Browse files
committed
Check that sample rates are in range in the config
1 parent 5bcc1ec commit eb0cb94

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

crates/cli/src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,8 @@ async fn try_main() -> anyhow::Result<ExitCode> {
109109
// Load the base configuration files
110110
let figment = opts.figment();
111111

112-
// Telemetry config could fail to load, but that's probably OK, since the whole
113-
// config will be loaded afterwards, and crash if there is a problem.
114-
// Falling back to default.
115-
let telemetry_config = TelemetryConfig::extract(&figment).unwrap_or_default();
112+
let telemetry_config =
113+
TelemetryConfig::extract(&figment).context("Failed to load telemetry config")?;
116114

117115
// Setup Sentry
118116
let sentry = sentry::init((

crates/config/src/sections/telemetry.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,35 @@ impl TelemetryConfig {
193193

194194
impl ConfigurationSection for TelemetryConfig {
195195
const PATH: Option<&'static str> = Some("telemetry");
196+
197+
fn validate(&self, _figment: &figment::Figment) -> Result<(), figment::Error> {
198+
if let Some(sample_rate) = self.sentry.sample_rate {
199+
if !(0.0..=1.0).contains(&sample_rate) {
200+
return Err(figment::error::Error::custom(
201+
"Sentry sample rate must be between 0.0 and 1.0",
202+
)
203+
.with_path("sentry.sample_rate"));
204+
}
205+
}
206+
207+
if let Some(sample_rate) = self.sentry.traces_sample_rate {
208+
if !(0.0..=1.0).contains(&sample_rate) {
209+
return Err(figment::error::Error::custom(
210+
"Sentry sample rate must be between 0.0 and 1.0",
211+
)
212+
.with_path("sentry.traces_sample_rate"));
213+
}
214+
}
215+
216+
if let Some(sample_rate) = self.tracing.sample_rate {
217+
if !(0.0..=1.0).contains(&sample_rate) {
218+
return Err(figment::error::Error::custom(
219+
"Tracing sample rate must be between 0.0 and 1.0",
220+
)
221+
.with_path("tracing.sample_rate"));
222+
}
223+
}
224+
225+
Ok(())
226+
}
196227
}

0 commit comments

Comments
 (0)