Skip to content

Commit cb4209f

Browse files
authored
fix(config) Add traces_sample_rate config (#95)
* fix(config) Add traces_sample_rate config We need a traces_sample_rate in order to collect tracing data. With this change made I was able to validate that tracing data is being collected and sent to sentry. * clippy
1 parent eb28135 commit cb4209f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pub struct Config {
1919
/// The environment to report to sentry errors to.
2020
pub sentry_env: Option<Cow<'static, str>>,
2121

22+
/// The sampling rate for tracing data.
23+
pub traces_sample_rate: Option<f32>,
24+
2225
/// The log level to filter logging to.
2326
pub log_level: LogLevel,
2427

@@ -88,6 +91,7 @@ impl Default for Config {
8891
Self {
8992
sentry_dsn: None,
9093
sentry_env: None,
94+
traces_sample_rate: Some(0.0),
9195
log_level: LogLevel::Debug,
9296
log_format: LogFormat::Text,
9397
grpc_addr: "0.0.0.0".to_owned(),

src/logging.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ pub enum LogFormat {
5656
Text,
5757
}
5858

59+
#[derive(Debug)]
5960
pub struct LoggingConfig {
6061
/// The sentry DSN to use for error reporting.
6162
pub sentry_dsn: Option<String>,
6263

6364
/// The environment to report to sentry errors to.
6465
pub sentry_env: Option<Cow<'static, str>>,
6566

67+
/// The tracing sample rate
68+
pub traces_sample_rate: f32,
69+
6670
/// The log level to filter logging to.
6771
pub log_level: LogLevel,
6872

@@ -75,6 +79,7 @@ impl LoggingConfig {
7579
LoggingConfig {
7680
sentry_dsn: config.sentry_dsn.clone(),
7781
sentry_env: config.sentry_env.clone(),
82+
traces_sample_rate: config.traces_sample_rate.unwrap_or(0.0),
7883
log_level: config.log_level,
7984
log_format: config.log_format,
8085
}
@@ -89,6 +94,7 @@ pub fn init(log_config: LoggingConfig) {
8994
dsn,
9095
release: Some(Cow::Borrowed(get_version())),
9196
environment: log_config.sentry_env.clone(),
97+
traces_sample_rate: log_config.traces_sample_rate,
9298
..Default::default()
9399
});
94100

0 commit comments

Comments
 (0)