Skip to content

Commit 8463d71

Browse files
authored
fix: Correctly apply environment from env (#293)
1 parent 2a64a98 commit 8463d71

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- The deprecated `error-chain` and `failure` integrations, features and crates were removed.
88

9+
**Fixes**:
10+
11+
- Fix regression defaulting `ClientOptions::environment` from `SENTRY_ENVIRONMENT`.
12+
913
## 0.21.0
1014

1115
**Breaking Changes**:

sentry-core/src/clientoptions.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,11 @@ impl fmt::Debug for ClientOptions {
173173

174174
impl Default for ClientOptions {
175175
fn default() -> ClientOptions {
176-
let env = if cfg!(debug_assertions) {
177-
"development"
178-
} else {
179-
"production"
180-
};
181176
ClientOptions {
182177
dsn: None,
183178
debug: false,
184179
release: None,
185-
environment: Some(env.into()),
180+
environment: None,
186181
sample_rate: 1.0,
187182
max_breadcrumbs: 100,
188183
attach_stacktrace: false,

sentry/src/defaults.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ pub fn apply_defaults(mut opts: ClientOptions) -> ClientOptions {
9595
.map(Cow::Owned)
9696
.or_else(|| {
9797
Some(Cow::Borrowed(if cfg!(debug_assertions) {
98-
"debug"
98+
"development"
9999
} else {
100-
"release"
100+
"production"
101101
}))
102102
});
103103
}
@@ -116,3 +116,26 @@ pub fn apply_defaults(mut opts: ClientOptions) -> ClientOptions {
116116
}
117117
opts
118118
}
119+
120+
#[cfg(test)]
121+
mod tests {
122+
use super::*;
123+
124+
#[test]
125+
fn test_default_environment() {
126+
let opts = ClientOptions {
127+
environment: Some("explicit-env".into()),
128+
..Default::default()
129+
};
130+
let opts = apply_defaults(opts);
131+
assert_eq!(opts.environment.unwrap(), "explicit-env");
132+
133+
let opts = apply_defaults(Default::default());
134+
// I doubt anyone runs test code without debug assertions
135+
assert_eq!(opts.environment.unwrap(), "development");
136+
137+
env::set_var("SENTRY_ENVIRONMENT", "env-from-env");
138+
let opts = apply_defaults(Default::default());
139+
assert_eq!(opts.environment.unwrap(), "env-from-env");
140+
}
141+
}

0 commit comments

Comments
 (0)