fix(resource): percent-decode attribute values#3586
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3586 +/- ##
=======================================
+ Coverage 83.0% 83.2% +0.1%
=======================================
Files 130 130
Lines 27993 28234 +241
=======================================
+ Hits 23250 23493 +243
+ Misses 4743 4741 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This integrates the Mercury `opentelemetry-rust` fork with fixes from a couple PRs: See: - open-telemetry/opentelemetry-rust#3586 - open-telemetry/opentelemetry-rust#3587 Follow-up to Arian's review: #18 (review)
This integrates the Mercury `opentelemetry-rust` fork with fixes from a couple PRs: See: - open-telemetry/opentelemetry-rust#3586 - open-telemetry/opentelemetry-rust#3587 Follow-up to Arian's review: #18 (review)
This integrates the Mercury `opentelemetry-rust` fork with fixes from a couple PRs: See: - open-telemetry/opentelemetry-rust#3586 - open-telemetry/opentelemetry-rust#3587 Follow-up to Arian's review: #18 (review)
This integrates the Mercury `opentelemetry-rust` fork with fixes from a couple PRs: See: - open-telemetry/opentelemetry-rust#3586 - open-telemetry/opentelemetry-rust#3587 Follow-up to Arian's review: #18 (review)
This integrates the Mercury `opentelemetry-rust` fork with fixes from a couple PRs: See: - open-telemetry/opentelemetry-rust#3586 - open-telemetry/opentelemetry-rust#3587 Follow-up to Arian's review: #18 (review)
This integrates the Mercury `opentelemetry-rust` fork with fixes from a couple PRs: See: - open-telemetry/opentelemetry-rust#3586 - open-telemetry/opentelemetry-rust#3587 Follow-up to Arian's review: #18 (review)
This integrates the Mercury `opentelemetry-rust` fork with fixes from a couple PRs: See: - open-telemetry/opentelemetry-rust#3586 - open-telemetry/opentelemetry-rust#3587 Follow-up to Arian's review: #18 (review)
This integrates the Mercury `opentelemetry-rust` fork with fixes from a couple PRs: See: - open-telemetry/opentelemetry-rust#3586 - open-telemetry/opentelemetry-rust#3587 Follow-up to Arian's review: #18 (review)
This integrates the Mercury `opentelemetry-rust` fork with fixes from a couple PRs: See: - open-telemetry/opentelemetry-rust#3586 - open-telemetry/opentelemetry-rust#3587 Follow-up to Arian's review: #18 (review)
| @@ -50,9 +51,13 @@ fn construct_otel_resources(s: String) -> Resource { | |||
| None => return None, | |||
| }; | |||
| let key = parts.0.trim(); | |||
There was a problem hiding this comment.
I believe we should also percent-decode keys. As per specs:
The OTEL_RESOURCE_ATTRIBUTES environment variable will contain of a list of key value pairs, represented as key1=value1,key2=value2. All attribute values MUST be considered strings. The , and = characters in keys and values MUST be percent encoded. Other characters MAY be [percent-encoded](https://datatracker.ietf.org/doc/html/rfc3986#section-2.1), e.g. values outside the ANSI characters set.
| // (e.g. `%20`) in the value is preserved. Per the Resource SDK spec | ||
| // the value MUST be percent-decoded; keys are baggage tokens and are | ||
| // not encoded. | ||
| let value = percent_decode_str(parts.1.trim()).decode_utf8_lossy(); |
There was a problem hiding this comment.
decode_utf8_lossy() accepts invalid encoded UTF-8 by inserting replacement characters. The Resource SDK spec says decoding failures should discard the entire env var and report an error. The existing baggage propagator already uses decode_utf8() and logs invalid UTF-8 instead of doing lossy decoding, so this new path should probably follow that shape.
Fixes #857
Changes
$OTEL_RESOURCE_ATTRIBUTESvalues are now percent-decoded in line with the spec.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial, user-facing changes