Bug Report: [OpenAI] Non-ASCII characters are escaped in `gen_ai.input.messages`, `gen_ai.tool.definitions`, and `gen_ai.output.messages` attributes

Author: KostyaGukishCreated Aug 18, 2026Updated Sep 5, 2026

Which component is this bug for?

OpenAI Instrumentation

Description

Non-ASCII characters are incorrectly escaped as Unicode sequences in the following OpenTelemetry attributes:

  • gen_ai.input.messages
  • gen_ai.tool.definitions
  • gen_ai.output.messages

For example, the Russian text Какая погода в Бостоне сегодня? is recorded as \u041a\u0430\u043a\u0430\u044f... instead of being preserved as UTF-8 text.

Reproduction steps

Run the following example:

from openai import OpenAI
from opentelemetry import trace
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.exporter.otlp.proto.http import Compression

tracerProvider = TracerProvider()
exporter = OTLPSpanExporter(
    endpoint=...,
    compression=Compression.Gzip,
)
tracerProvider.add_span_processor(BatchSpanProcessor(exporter))
trace.set_tracer_provider(tracerProvider)


OpenAIInstrumentor().instrument()


client = OpenAI(
    api_key=...,
    base_url=...,
)
client.chat.completions.create(
    model=...,
    messages=[
        {
        "role": "user",
        "content": "Какая погода в Бостоне сегодня?"
        }
    ],
    tools=[
        {
        "type": "function",
        "function": {
            "name": "get_current_weather",
            "description": "Узанть погоду",
            "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "Город"
                },
            },
            "required": ["location"]
            }
        }
        }
    ],
    extra_body={
        "enable_thinking": False,
    },
)

Expected behavior

Non-ASCII characters should be preserved in the OpenTelemetry attribute values.

Actual Behavior with Screenshots

Non-ASCII characters are serialized as escaped Unicode sequences in:

  • gen_ai.input.messages
  • gen_ai.tool.definitions
  • gen_ai.output.messages

For example, the input message is recorded with escaped Unicode characters instead of the original Cyrillic text. Image

Python Version

3.12.13

Provide any additional context for the Bug.

I found a similar issue in the LangChain instrumentation that was fixed in #3668

Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

Yes I am willing to submit a PR!