opentelemetry-cpp icon indicating copy to clipboard operation
opentelemetry-cpp copied to clipboard

URL encoded values for `OTEL_EXPORTER_OTLP_HEADERS` are not exported

Open pyohannes opened this issue 1 year ago • 2 comments
trafficstars

Describe your environment

$ uname -a
Linux [...] 6.5.0-14-generic #14~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Nov 20 18:15:30 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.4.0-1ubuntu1~22.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-XeT9lY/gcc-11-11.4.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04) 
$ git log -1 --format="%H"
2b5c2b404448d8b675c2d645e27e9affd609ccb7

Steps to reproduce

$ export OTEL_EXPORTER_OTLP_HEADERS=Authorization=Basic%20NzAx[...]==
$ ./examples/otlp/example_otlp_http
,Body:{"status":"error","error":"authentication error: no credentials provided"}tp_client.cc:103 [OTLP HTTP Client] Export failed, Status:401, Header:  Content-Length: 74
[Error] File: /home/johannes/Source/opentelemetry-cpp/exporters/otlp/src/otlp_http_exporter.cc:118 [OTLP HTTP Client] ERROR: Export 1 trace span(s) error: 1
,Body:{"status":"error","error":"authentication error: no credentials provided"}tp_client.cc:103 [OTLP HTTP Client] Export failed, Status:401, Header:  Content-Length: 74
[Error] File: /home/johannes/Source/opentelemetry-cpp/exporters/otlp/src/otlp_http_exporter.cc:118 [OTLP HTTP Client] ERROR: Export 1 trace span(s) error: 1
,Body:{"status":"error","error":"authentication error: no credentials provided"}tp_client.cc:103 [OTLP HTTP Client] Export failed, Status:401, Header:  Content-Length: 74
[Error] File: /home/johannes/Source/opentelemetry-cpp/exporters/otlp/src/otlp_http_exporter.cc:118 [OTLP HTTP Client] ERROR: Export 1 trace span(s) error: 1
,Body:{"status":"error","error":"authentication error: no credentials provided"}tp_client.cc:103 [OTLP HTTP Client] Export failed, Status:401, Header:  Content-Length: 74
[Error] File: /home/johannes/Source/opentelemetry-cpp/exporters/otlp/src/otlp_http_exporter.cc:118 [OTLP HTTP Client] ERROR: Export 1 trace span(s) error: 1
$
$ export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic 20NzAx[...]=="
$ ./examples/otlp/example_otlp_http
$

What is the expected behavior?

The C++ SDK should support URL encoded values in OTEL_EXPORTER_OTLP_HEADERS. For backward compatibility, also non-URL encoded values should be supported.

Both this settings should work:

OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic%20AAA"
OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic AAA"

What is the actual behavior?

Currently only non-URL encoded values are supported.

Additional context

The OTel specification requires values for OTEL_EXPORTER_OTLP_HEADERS to be formatted conforming with the W3C Baggage specification.

The W3C Baggage spec requires values to be URL encoded:

A value contains a string whose character encoding MUST be UTF-8 [Encoding]. Any characters outside of the baggage-octet range of characters MUST be percent-encoded. Characters which are not required to be percent-encoded MAY be percent-encoded.

This has been discussed in open-telemetry/opentelemetry-specification#3832, the result being that the behavior described in the OTel and W3C specification is desired and SDKs should support URL encoded values.

pyohannes avatar Feb 06 '24 14:02 pyohannes

Thanks for the report.

I also assume this is about C++, not .NET.

marcalff avatar Feb 06 '24 14:02 marcalff

And @pyohannes can self-assign this one, he still knows the otel-cpp code better. jk :)

lalitb avatar Feb 06 '24 19:02 lalitb