Skip to content

Commit 7527782

Browse files
authored
Support both URL-encoded and non-URL encoded values for OTEL_EXPORTER_OTLP_HEADERS (#5316)
1 parent 72889f2 commit 7527782

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
typically the case when using the experimental Logs Bridge API.
2727
([#5300](https://github.com/open-telemetry/opentelemetry-dotnet/pull/5300))
2828

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

3135
Released 2023-Dec-08

src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public static THeaders GetHeaders<THeaders>(this OtlpExporterOptions options, Ac
5858
var headers = new THeaders();
5959
if (!string.IsNullOrEmpty(optionHeaders))
6060
{
61+
// According to the specification, URL-encoded headers must be supported.
62+
optionHeaders = Uri.UnescapeDataString(optionHeaders);
63+
6164
Array.ForEach(
6265
optionHeaders.Split(','),
6366
(pair) =>

test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class OtlpExporterOptionsExtensionsTests : Http2UnencryptedSupportTests
1616
[InlineData("key==value", new string[] { "key" }, new string[] { "=value" })]
1717
[InlineData("access-token=abc=/123,timeout=1234", new string[] { "access-token", "timeout" }, new string[] { "abc=/123", "1234" })]
1818
[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)
19+
[InlineData("Authorization=Basic%20AAA", new string[] { "authorization" }, new string[] { "Basic AAA" })]
20+
[InlineData("Authorization=Basic AAA", new string[] { "authorization" }, new string[] { "Basic AAA" })]
1921
public void GetMetadataFromHeadersWorksCorrectFormat(string headers, string[] keys, string[] values)
2022
{
2123
var options = new OtlpExporterOptions

0 commit comments

Comments
 (0)