diff --git a/opentelemetry-sdk/CHANGELOG.md b/opentelemetry-sdk/CHANGELOG.md index 876e1a973c..c640826d72 100644 --- a/opentelemetry-sdk/CHANGELOG.md +++ b/opentelemetry-sdk/CHANGELOG.md @@ -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 diff --git a/opentelemetry-sdk/src/resource/env.rs b/opentelemetry-sdk/src/resource/env.rs index b5287e1c76..6284911ace 100644 --- a/opentelemetry-sdk/src/resource/env.rs +++ b/opentelemetry-sdk/src/resource/env.rs @@ -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())) })) @@ -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")), ], @@ -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", ""), ]) ); },