From 752778270def63bc710f286856cc9ffe48e7bf39 Mon Sep 17 00:00:00 2001 From: Johannes Tax Date: Wed, 7 Feb 2024 20:23:32 +0100 Subject: [PATCH] Support both URL-encoded and non-URL encoded values for `OTEL_EXPORTER_OTLP_HEADERS` (#5316) --- src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md | 4 ++++ .../OtlpExporterOptionsExtensions.cs | 3 +++ .../OtlpExporterOptionsExtensionsTests.cs | 2 ++ 3 files changed, 9 insertions(+) diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md index 6978f0c8a38..f862133e31f 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md @@ -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 diff --git a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs index 496dbf4c8c4..91a23749804 100644 --- a/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs +++ b/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/OtlpExporterOptionsExtensions.cs @@ -58,6 +58,9 @@ public static THeaders GetHeaders(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) => diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs index db92c0c65dd..37a41697f26 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/OtlpExporterOptionsExtensionsTests.cs @@ -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