Skip to content

Commit

Permalink
Support both URL-encoded and non-URL encoded values for `OTEL_EXPORTE…
Browse files Browse the repository at this point in the history
…R_OTLP_HEADERS` (#5316)
  • Loading branch information
pyohannes authored Feb 7, 2024
1 parent 72889f2 commit 7527782
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
typically the case when using the experimental Logs Bridge API.
([#5300](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5300))

* URL encoded values in `OTEL_EXPORTER_OTLP_HEADERS` are now correctly decoded
as it is mandated by the specification.
([#5316](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5268))

## 1.7.0

Released 2023-Dec-08
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ public static THeaders GetHeaders<THeaders>(this OtlpExporterOptions options, Ac
var headers = new THeaders();
if (!string.IsNullOrEmpty(optionHeaders))
{
// According to the specification, URL-encoded headers must be supported.
optionHeaders = Uri.UnescapeDataString(optionHeaders);

Array.ForEach(
optionHeaders.Split(','),
(pair) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class OtlpExporterOptionsExtensionsTests : Http2UnencryptedSupportTests
[InlineData("key==value", new string[] { "key" }, new string[] { "=value" })]
[InlineData("access-token=abc=/123,timeout=1234", new string[] { "access-token", "timeout" }, new string[] { "abc=/123", "1234" })]
[InlineData("key1=value1;key2=value2", new string[] { "key1" }, new string[] { "value1;key2=value2" })] // semicolon is not treated as a delimiter (https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#specifying-headers-via-environment-variables)
[InlineData("Authorization=Basic%20AAA", new string[] { "authorization" }, new string[] { "Basic AAA" })]
[InlineData("Authorization=Basic AAA", new string[] { "authorization" }, new string[] { "Basic AAA" })]
public void GetMetadataFromHeadersWorksCorrectFormat(string headers, string[] keys, string[] values)
{
var options = new OtlpExporterOptions
Expand Down

0 comments on commit 7527782

Please sign in to comment.