Skip to content

Commit bb34e9a

Browse files
committed
Allow setting the Sentry environment & sample rates
Also record the version in the Sentry release field.
1 parent ef006ed commit bb34e9a

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

crates/cli/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ async fn try_main() -> anyhow::Result<ExitCode> {
119119
telemetry_config.sentry.dsn.as_deref(),
120120
sentry::ClientOptions {
121121
transport: Some(Arc::new(SentryTransportFactory::new())),
122-
traces_sample_rate: 1.0,
122+
environment: telemetry_config.sentry.environment.clone().map(Into::into),
123+
release: Some(VERSION.into()),
124+
sample_rate: telemetry_config.sentry.sample_rate.unwrap_or(1.0),
125+
traces_sample_rate: telemetry_config.sentry.traces_sample_rate.unwrap_or(0.0),
123126
auto_session_tracking: true,
124127
session_mode: sentry::SessionMode::Request,
125128
..Default::default()

crates/config/src/sections/telemetry.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
// Please see LICENSE in the repository root for full details.
66

77
use schemars::JsonSchema;
8-
use serde::{Deserialize, Serialize};
8+
use serde::{Deserialize, Serialize, de::Error as _};
99
use serde_with::skip_serializing_none;
1010
use url::Url;
1111

1212
use super::ConfigurationSection;
1313

14+
fn sample_rate_example() -> f64 {
15+
0.5
16+
}
17+
1418
/// Propagation format for incoming and outgoing requests
1519
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
1620
#[serde(rename_all = "lowercase")]
@@ -116,13 +120,38 @@ fn sentry_dsn_example() -> &'static str {
116120
"https://public@host:port/1"
117121
}
118122

123+
fn sentry_environment_example() -> &'static str {
124+
"production"
125+
}
126+
119127
/// Configuration related to the Sentry integration
120128
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
121129
pub struct SentryConfig {
122130
/// Sentry DSN
123131
#[schemars(url, example = "sentry_dsn_example")]
124132
#[serde(skip_serializing_if = "Option::is_none")]
125133
pub dsn: Option<String>,
134+
135+
/// Environment to use when sending events to Sentry
136+
///
137+
/// Defaults to `production` if not set.
138+
#[schemars(example = "sentry_environment_example")]
139+
#[serde(skip_serializing_if = "Option::is_none")]
140+
pub environment: Option<String>,
141+
142+
/// Sample rate for event submissions
143+
///
144+
/// Defaults to `1.0` if not set.
145+
#[serde(skip_serializing_if = "Option::is_none")]
146+
#[schemars(example = "sample_rate_example", range(min = 0.0, max = 1.0))]
147+
pub sample_rate: Option<f32>,
148+
149+
/// Sample rate for tracing transactions
150+
///
151+
/// Defaults to `0.0` if not set.
152+
#[serde(skip_serializing_if = "Option::is_none")]
153+
#[schemars(example = "sample_rate_example", range(min = 0.0, max = 1.0))]
154+
pub traces_sample_rate: Option<f32>,
126155
}
127156

128157
impl SentryConfig {

docs/config.schema.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,33 @@
13331333
],
13341334
"type": "string",
13351335
"format": "uri"
1336+
},
1337+
"environment": {
1338+
"description": "Environment to use when sending events to Sentry\n\nDefaults to `production` if not set.",
1339+
"examples": [
1340+
"production"
1341+
],
1342+
"type": "string"
1343+
},
1344+
"sample_rate": {
1345+
"description": "Sample rate for event submissions\n\nDefaults to `1.0` if not set.",
1346+
"examples": [
1347+
0.5
1348+
],
1349+
"type": "number",
1350+
"format": "float",
1351+
"maximum": 1.0,
1352+
"minimum": 0.0
1353+
},
1354+
"traces_sample_rate": {
1355+
"description": "Sample rate for tracing transactions\n\nDefaults to `0.0` if not set.",
1356+
"examples": [
1357+
0.5
1358+
],
1359+
"type": "number",
1360+
"format": "float",
1361+
"maximum": 1.0,
1362+
"minimum": 0.0
13361363
}
13371364
}
13381365
},

0 commit comments

Comments
 (0)