Open arielvalentin opened 2 weeks ago
We're hitting this too - and I was just paged for it due to it happening frequently enough to trip an alert. I ended up here by searching for the base error (Encoding::UndefinedConversionError
) and noticed there's another, older Issue, possibly related?
@fbogsany are you still keen on handling these cases in instrumentations instead of in the SDK?
Should the OTel SDK force users to encode strings as UTF-8 before using them in user defined properties like the Names or Attributes or should force encode strings as UTF-8?
A little background
The
Encoding::UndefinedConversionError
exception is raised in the OTLP Exporter when creating aOpentelemetry::Proto::Common::V1::AnyValue#string_value
and the string values are encoded asASCII-8BIT
.I am still working on tracking this down but based on the error message we see coming from the error handler, we know it is likely because either the web server or rack is reading the HTTP headers with
ASCII-8BIT
encoding:Reproducing the Problem
One of the characters in the header is
张
, so I have put together a short demonstration of the problem:If the user supplies a string that is encoded as UTF-8 then it works as expected:
With Forced Encoding to UTF-8 it works:
What does DD Trace do?
It force encodes keys and values to UTF-8 if necessary:
https://github.com/DataDog/dd-trace-rb/blob/4b1901101c0f4d1033558bd9c0ff2e1c2b963bc7/lib/datadog/tracing/metadata/tagging.rb#L52 https://github.com/DataDog/dd-trace-rb/blob/4b1901101c0f4d1033558bd9c0ff2e1c2b963bc7/lib/datadog/core/utils.rb#L47
The full backtrace