From 2d613280e6c1c40faa885c74efbbfe7a10185522 Mon Sep 17 00:00:00 2001 From: William Perron Date: Fri, 13 Sep 2024 08:57:51 -0400 Subject: [PATCH] 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 --- opentelemetry-sdk/src/resource/env.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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", ""), ]) ); },