traceloop / traceloop/openllmetry

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

Open
#4,426 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.4k
Forks
1.1k
Avg merge
8d 14h
Merged PRs (30d)
2

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the OpenAI Instrumentation serialization path and compare the similar LangChain instrumentation fix in issue #3668. Reproduce the example with Cyrillic text, then verify that gen_ai.input.messages, gen_ai.tool.definitions, and gen_ai.output.messages preserve non-ASCII characters as UTF-8 rather than escaped Unicode sequences.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.