Skip to content

Commit 0b5d2b5

Browse files
committed
Allow values containing '=' in OTEL_RESOURCE_ATTRIBUTES
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 #2110
1 parent 7ab5e0f commit 0b5d2b5

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

opentelemetry-sdk/CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
- Update `async-std` dependency version to 1.13
66
- *Breaking* - Remove support for `MetricProducer` which allowed metrics from
77
external sources to be sent through OpenTelemetry.
8-
[#2105](https://github.com/open-telemetry/opentelemetry-rust/pull/2105)
8+
[#2105](https://github.com/open-telemetry/opentelemetry-rust/pull/2105)
9+
- Update `EnvResourceDetector` to allow resource attribute values containing
10+
equal signs (`"="`). [#2120](https://github.com/open-telemetry/opentelemetry-rust/pull/2120)
911

1012
## v0.25.0
1113

opentelemetry-sdk/src/resource/env.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ impl Default for EnvResourceDetector {
4545
/// key1=value1,key2=value2,...
4646
fn construct_otel_resources(s: String) -> Resource {
4747
Resource::new(s.split_terminator(',').filter_map(|entry| {
48-
let mut parts = entry.splitn(2, '=');
49-
let key = parts.next()?.trim();
50-
let value = parts.next()?.trim();
51-
if value.find('=').is_some() {
52-
return None;
53-
}
48+
let parts = match entry.split_once('=') {
49+
Some(p) => p,
50+
None => return None,
51+
};
52+
let key = parts.0.trim();
53+
let value = parts.1.trim();
5454

5555
Some(KeyValue::new(key.to_owned(), value.to_owned()))
5656
}))
@@ -104,7 +104,7 @@ mod tests {
104104
[
105105
(
106106
"OTEL_RESOURCE_ATTRIBUTES",
107-
Some("key=value, k = v , a= x, a=z"),
107+
Some("key=value, k = v , a= x, a=z,equal=value=,empty="),
108108
),
109109
("IRRELEVANT", Some("20200810")),
110110
],
@@ -118,6 +118,8 @@ mod tests {
118118
KeyValue::new("k", "v"),
119119
KeyValue::new("a", "x"),
120120
KeyValue::new("a", "z"),
121+
KeyValue::new("equal", "value="),
122+
KeyValue::new("empty", ""),
121123
])
122124
);
123125
},

0 commit comments

Comments
 (0)