litellm - 💡(How to fix) Fix [Bug]: `attributes.metadata.spend_logs_metadata` sent as Python string instead of JSON in OpenTelemetry spans [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Fix Action

Fixed

Code Example

litellm_settings:
  success_callback: ["otel"]

general_settings:
  master_key: "sk-1234"

---

curl -X POST http://localhost:4000/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-1234" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello"}],
    "metadata": {
      "spend_logs_metadata": {
        "project": "my-project",
        "env": "production"
      }
    }
  }'

---

attributes.metadata.spend_logs_metadata = "{'project': 'my-project', 'env': 'production'}"

---

attributes.metadata.spend_logs_metadata = "{\"project\": \"my-project\", \"env\": \"production\"}"

---
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

When using the custom spend log metadata feature, the spend_logs_metadata value shows up in OpenTelemetry span attributes as a Python string representation ({'key': 'value'}) instead of a proper JSON string ({"key": "value"}). This makes it impossible to parse downstream in tools like Jaeger, Honeycomb, or Grafana Tempo.

Steps to Reproduce

Configure LiteLLM proxy with OpenTelemetry enabled (e.g. OTEL_EXPORTER=console is enough to observe the output).

  1. Set up a success_callback callback in your config.yaml:
litellm_settings:
  success_callback: ["otel"]

general_settings:
  master_key: "sk-1234"
  1. Make a request to the proxy and pass spend_logs_metadata as a dict in the request metadata:
curl -X POST http://localhost:4000/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-1234" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Hello"}],
    "metadata": {
      "spend_logs_metadata": {
        "project": "my-project",
        "env": "production"
      }
    }
  }'
  1. Inspect the OTEL span output. The attributes.metadata.spend_logs_metadata attribute will look like this:
attributes.metadata.spend_logs_metadata = "{'project': 'my-project', 'env': 'production'}"

Expected:

attributes.metadata.spend_logs_metadata = "{\"project\": \"my-project\", \"env\": \"production\"}"

The single-quoted Python representation is not valid JSON and cannot be parsed by any standard JSON parser.

Relevant log output

What part of LiteLLM is this about?

SDK (litellm Python package)

What LiteLLM version are you on ?

v1.83.10

Twitter / LinkedIn details

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix [Bug]: `attributes.metadata.spend_logs_metadata` sent as Python string instead of JSON in OpenTelemetry spans [1 pull requests]