Skip to content

Commit

Permalink
Allow values containing '=' in OTEL_RESOURCE_ATTRIBUTES
Browse files Browse the repository at this point in the history
Values passed in to `OTEL_RESOURCE_ATTRIBUTES` containing an equal sign
`"="` are currently ignored by the Resource constructor, but should be
accepted as it is part of the [W3C Baggage octet
range](https://www.w3.org/TR/baggage/#header-content).

Fixes open-telemetry#2110
  • Loading branch information
wperron committed Sep 16, 2024
1 parent 7ab5e0f commit 0b5d2b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion opentelemetry-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
- Update `async-std` dependency version to 1.13
- *Breaking* - Remove support for `MetricProducer` which allowed metrics from
external sources to be sent through OpenTelemetry.
[#2105](https://github.com/open-telemetry/opentelemetry-rust/pull/2105)
[#2105](https://github.com/open-telemetry/opentelemetry-rust/pull/2105)
- Update `EnvResourceDetector` to allow resource attribute values containing
equal signs (`"="`). [#2120](https://github.com/open-telemetry/opentelemetry-rust/pull/2120)

## v0.25.0

Expand Down
16 changes: 9 additions & 7 deletions opentelemetry-sdk/src/resource/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ impl Default for EnvResourceDetector {
/// key1=value1,key2=value2,...
fn construct_otel_resources(s: String) -> Resource {
Resource::new(s.split_terminator(',').filter_map(|entry| {
let mut parts = entry.splitn(2, '=');
let key = parts.next()?.trim();
let value = parts.next()?.trim();
if value.find('=').is_some() {
return None;
}
let parts = match entry.split_once('=') {
Some(p) => p,
None => return None,
};
let key = parts.0.trim();
let value = parts.1.trim();

Some(KeyValue::new(key.to_owned(), value.to_owned()))
}))
Expand Down Expand Up @@ -104,7 +104,7 @@ mod tests {
[
(
"OTEL_RESOURCE_ATTRIBUTES",
Some("key=value, k = v , a= x, a=z"),
Some("key=value, k = v , a= x, a=z,equal=value=,empty="),
),
("IRRELEVANT", Some("20200810")),
],
Expand All @@ -118,6 +118,8 @@ mod tests {
KeyValue::new("k", "v"),
KeyValue::new("a", "x"),
KeyValue::new("a", "z"),
KeyValue::new("equal", "value="),
KeyValue::new("empty", ""),
])
);
},
Expand Down

0 comments on commit 0b5d2b5

Please sign in to comment.