Skip to content

Commit 66b7264

Browse files
committed
feat(config): Allow environment references in Relay configuration
1 parent d16059c commit 66b7264

File tree

6 files changed

+44
-4
lines changed

6 files changed

+44
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
**Features**:
6+
7+
- Allow environment references in Relay configuration. ([#4748](https://github.com/getsentry/relay/pull/4748))
8+
39
## 25.5.0
410

511
**Features**:

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ sentry-types = "0.36.0"
172172
sentry_protos = "0.2.0"
173173
serde = { version = "1.0.215", features = ["derive", "rc"] }
174174
serde-transcode = "1.1.1"
175+
serde-vars = "0.2"
175176
serde_bytes = "0.11"
176177
serde_json = "1.0.133"
177178
serde_path_to_error = "0.1.16"

relay-config/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ relay-log = { workspace = true, features = ["init"] }
2727
relay-metrics = { workspace = true }
2828
relay-redis = { workspace = true }
2929
serde = { workspace = true }
30+
serde-vars = { workspace = true }
3031
serde_json = { workspace = true }
3132
serde_yaml = { workspace = true }
3233
thiserror = { workspace = true }

relay-config/src/config.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,18 @@ trait ConfigObject: DeserializeOwned + Serialize {
174174

175175
let f = fs::File::open(&path)
176176
.with_context(|| ConfigError::file(ConfigErrorKind::CouldNotOpenFile, &path))?;
177+
let f = io::BufReader::new(f);
177178

179+
let mut source = serde_vars::EnvSource::default();
178180
match Self::format() {
179-
ConfigFormat::Yaml => serde_yaml::from_reader(io::BufReader::new(f))
180-
.with_context(|| ConfigError::file(ConfigErrorKind::BadYaml, &path)),
181-
ConfigFormat::Json => serde_json::from_reader(io::BufReader::new(f))
182-
.with_context(|| ConfigError::file(ConfigErrorKind::BadJson, &path)),
181+
ConfigFormat::Yaml => {
182+
serde_vars::deserialize(serde_yaml::Deserializer::from_reader(f), &mut source)
183+
.with_context(|| ConfigError::file(ConfigErrorKind::BadYaml, &path))
184+
}
185+
ConfigFormat::Json => {
186+
serde_vars::deserialize(&mut serde_json::Deserializer::from_reader(f), &mut source)
187+
.with_context(|| ConfigError::file(ConfigErrorKind::BadJson, &path))
188+
}
183189
}
184190
}
185191

tests/integration/test_config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,19 @@ def test_invalid_topics_raise_error(mini_sentry, relay_with_processing):
2828

2929
error = str(mini_sentry.test_failures.get_nowait())
3030
assert "failed to validate the topic with name" in error
31+
32+
33+
def test_missing_env_var_in_config(mini_sentry, relay, relay_credentials):
34+
credentials = relay_credentials()
35+
relay = relay(
36+
mini_sentry,
37+
credentials=credentials,
38+
wait_health_check=False,
39+
options={
40+
"http": {
41+
"encoding": "${THIS_DOES_NOT_EXIST_OTHER_WISE_THE_TEST_WILL_PASS}",
42+
}
43+
},
44+
)
45+
46+
assert relay.wait_for_exit() != 0

0 commit comments

Comments
 (0)