Skip to content

fix(otel)!: print OTel v2 spans to stdout only when the operator asks - #48723

Merged
yucheng-berri merged 4 commits into
mainfrom
litellm_otel_v2_no_unrequested_console
Oct 29, 2026
Merged

yucheng-berri merged 4 commits into
mainfrom
litellm_otel_v2_no_unrequested_console

Conversation

@yucheng-berri

@yucheng-berri yucheng-berri commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

With the OTel v2 path on (LITELLM_OTEL_V2=true), the proxy printed every span, prompts included, to stdout even though nobody asked for a console exporter: next to a Langfuse or Arize callback, for keys and teams that send traces to their own Langfuse project, and with no callback at all. That costs CPU on the request path and floods logs. After this PR, spans go to stdout only when the operator asks for it: OTEL_EXPORTER=console, a console exporter in the config, or the plain otel callback with nothing else configured.

Details

TLDR

Problem this solves:

  • V2 vendor callbacks also dump every span as JSON to stdout
  • Key-level and team-level Langfuse destinations dump them too
  • So does V2 with no callback listed
  • Prompts land in container logs; console export costs about 10-15% throughput

How it solves it:

  • The built-in console default prints only for the otel callback
  • Vendor callbacks and the proxy's background tracer never print it
  • OTEL_EXPORTER=console and kind: console exporters still print, as before

Intentional product change: V2 proxies stop printing span JSON to stdout unless the operator asks. Set OTEL_EXPORTER=console to keep it.

User Flow

Before: a team's key sends traces to the team's own Langfuse project, and the proxy's stdout fills with every request's span JSON, prompt included

  1. The admin sets LITELLM_OTEL_V2=true and no OTEL_EXPORTER, with or without callbacks: ["langfuse_otel"] and global Langfuse keys
  2. They create a key with POST http://localhost:4000/key/generate whose metadata.logging sends langfuse_otel traces to the team's Langfuse project
  3. A developer sends POST http://localhost:4000/v1/chat/completions with that key and gets a 200; the trace shows up in the team's Langfuse project
  4. The proxy's stdout also gets a {"name": "chat gpt-4o-mini", "context": {...}} block per span, prompt text included

After: the same setup sends traces to Langfuse only

  1. Same env and config, no OTEL_EXPORTER
  2. Same key, created the same way
  3. Same POST http://localhost:4000/v1/chat/completions returns 200 and the trace shows up in the team's Langfuse project
  4. The proxy's stdout has no span JSON; setting OTEL_EXPORTER=console brings it back

Linear ticket

Refs LIT-10205

This fixes the stdout dump the ticket reports (V2, global Langfuse keys) and the one in the reporter's next setup (per-key Langfuse, no global keys). The missing tags and user on per-key traces without global keys is #48718. Both PRs add tests to test_otel_v2_destinations.py, in different classes.

Behavior changes

Removed / renamed

  • None

Silent regressions to watch

  • An operator who relied on the unrequested stdout span dump loses it, with a vendor callback, key or team destinations, or no callback. Migration: set OTEL_EXPORTER=console.
  • callbacks: ["langfuse_otel", "otel"] with no OTEL_* env stops printing, because otel listed second reuses the Langfuse tracer; ["otel", "langfuse_otel"] still prints.

Migration for existing customers

  • None required. Anyone who wants the stdout copy sets OTEL_EXPORTER=console.

Regression tests

  • tests/integration/observability/test_langfuse_otel_console_output.py: real proxy and a local Langfuse sink. With global keys, stdout has no span JSON when OTEL_EXPORTER is unset and has it with =console. With only a key-level Langfuse destination and no global keys, stdout has none, whether langfuse_otel is listed or not. Red on main, green here.
  • tests/unit/integrations/otel/test_otel_v2_destinations.py::TestConsolePlaceholder: Langfuse with keys exports only to Langfuse, a named console exporter prints, the otel callback prints when nothing else is configured, and the proxy's background tracer prints only with OTEL_EXPORTER=console. The background-tracer case fails on main; the otel case fails if the callback stops asking for the console default.
  • Two TestArizeTenantOnly tests no longer expect the stdout copy.

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Screenshots / Proof of Fix

Live A/B on one VM, base and head side by side:

  • Before: main cf7c35a1174
  • After: fada02e3060, which is this PR's head 4e50a922e8b merged into cf7c35a1174
  • Rig: a real proxy at 2 workers (4 for load), real Postgres 16, real OpenAI gpt-4o-mini, real Langfuse Cloud, Arize AX, AgentOps and W&B Weave
  • Recorders: one in front of OpenAI and one in front of Langfuse, each logging and forwarding to the real destination, so the A/B diffs what each side sent
  • Lookup: every request carries a unique marker and is read back from Langfuse /api/public/v2/observations

Key-only Langfuse on the head proxy, no global keys. The dashboard Logs page shows chat, messages and responses calls made with a key whose metadata.logging sends langfuse_otel to its team's Langfuse project. The proxy printed 0 spans to stdout during those calls.

Logs page, key-only Langfuse

The chat call's trace in that key's Langfuse project (chatcmpl-Ee5WJSOrwSIWTrORnaaMhSJi7iQPI, user audit-user):

Langfuse trace, key-only

Before (cf7c35a1174): the key-only setup still prints span JSON

  1. LITELLM_OTEL_V2=true, no OTEL_EXPORTER, no global Langfuse keys, no callbacks
  2. Create a key whose metadata.logging sends langfuse_otel to its team's Langfuse project
  3. Send chat, a streamed messages call, a responses call and a provider-401 call with that key. All four return the expected status, and each trace lands in the team's project
  4. stdout gets 129 span JSON blocks (a_key), prompt text included

After (fada02e3060): same setup, same steps

  1. Same env
  2. Same key
  3. Same four calls. The same statuses come back, and the same traces reach Langfuse; the recorded Langfuse posts have identical span names and attribute key sets
  4. stdout gets 0 span JSON blocks

Every leg, stdout span JSON blocks before → after:

setup before after traffic and wire
callbacks: [langfuse_otel], global keys: chat, messages, responses × (SDK sync, SDK async stream, curl), bad model 400, provider 401, unauthenticated 401, same request ×3, disable header, key with litellm_disabled_callbacks 221 0 every cell identical, wire identical
success_callback / failure_callback 131 / 125 0 / 0 identical
key-only Langfuse, no global keys (two runs) 129 / 127 0 / 0 identical
team-only Langfuse, no global keys (two runs) 162 / 137 0 / 0 identical
V2 with no callback at all 75 0 identical
langfuse_otel with global keys, mixed traffic plus a per-key call 90 0 wire identical
Arize AX / AgentOps / W&B Weave 66 / 76 / 76 0 / 0 / 0 200s, wire identical
[langfuse_otel, otel], no OTEL_* env (declared) 76 0 wire identical
load: 4 workers, 120 chat calls 994 0 120×200 on both
callbacks: [langfuse_otel], no global keys 73 1 see caveats
otel alone / [otel, langfuse_otel] 78 / 77 78 / 79 still prints
OTEL_EXPORTER=console / kind: console spec / OTEL_EXPORTER="" 79 / 76 / 139 78 / 79 / 155 still prints
V1 langfuse_otel, no keys 4 4 unchanged

Reporter's prod config, anonymized, run on stock 1.104.1, main cf7c35a1174 and this PR:

  • Setup: V2 on, revoked global keys that get 401, per-key langfuse_otel success_and_failure, their four-callback list, their OTEL_BSP_* and LITELLM_LOG=ERROR, 2 workers
  • Traffic: 26 requests: chat, a streamed call, messages, responses, a provider 401, a plain key and a 20-request burst
  • stdout: 231 / 312 / 0 span blocks, and 101 / 77 / 0 prompt copies
  • Langfuse: per-key delivery, tags and user were the same on all three

Chaos (2 workers, local Langfuse recorder):

fault before after
Langfuse returns 503 for 8 s during a 42-request burst 7×200 at the client, 35 client timeouts; the proxy still sent 37 traces, all accepted 42×200; 42 traces sent, 41 accepted
/health/services?service=langfuse_otel during the outage 200 "success" 200 "success"
SIGKILL one worker mid-burst 18×200, 16 delivered 19×200, 17 delivered
10 requests after the replacement worker came up 10 of 10 delivered 10 of 10 delivered
SIGTERM the proxy 1 s into a 20-request burst 19 of 20 delivered 15 of 20 delivered

Notes on the chaos run:

  • The before side's client timed out on the outage burst because the shared VM was saturated by parallel legs at that moment. Both sides made the same 95 upstream calls.
  • SIGTERM drops spans still queued, on both sides. Across four chaos runs the restart burst delivered 5/0, 0/20, 20/19 and 19/15 (before/after), so neither side is consistently ahead.
  • stdout went from 786 span blocks to 0 over the chaos run.

tests/integration/observability/test_langfuse_otel_console_output.py passed 4 runs in a row at INTEGRATION_WORKERS=4. The OTel unit suites pass: 1563 tests.

ran /live-pr-risk on 4e50a922e8b and found no regressions/backward incompatible risks beyond the declared stdout change

Type

🐛 Bug Fix

Caveats (if any)

Medium

Low

  • GenAI metrics and logs exporters are untouched by this PR

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Note

Medium Risk
Intentional breaking change for anyone relying on silent stdout span dumps without OTEL_EXPORTER=console; observability wiring is central but scoped to placeholder console export, not OTLP or fan-out.

Overview
Stops unrequested console span dumps on the OTel v2 path. When no exporter was configured, config normalization still folded in a placeholder console spec, so Langfuse/Arize callbacks, per-key destinations, and the proxy background tracer all printed full span JSON (prompts included) to stdout.

How it changes: build_tracer_provider now skips that placeholder unless console_default=True. That flag is threaded through OpenTelemetryV2, build_otel_v2_logger, and TenantTracerCache, and is set only when the proxy builds the plain otel callback in litellm_logging.py. Explicit operator choices (OTEL_EXPORTER=console, a configured console exporter) still export to stdout. is_unconfigured_placeholder moves to model/config.py for shared use with preset helpers.

Tests: New integration coverage for Langfuse + stdout behavior; unit TestConsolePlaceholder and updated Arize tenant tests that no longer expect the extra stdout copy.

Reviewed by Cursor Bugbot for commit 4e50a92. Bugbot is set up for automated code reviews on this repo. Configure here.

…dout

With LITELLM_OTEL_V2 on and a vendor callback such as langfuse_otel or arize
holding operator credentials, the proxy printed every span as JSON to stdout,
prompts included, on the request path. Nobody set OTEL_EXPORTER, but the
console placeholder that OpenTelemetryV2Config folds in for an empty exporter
list stayed next to the vendor's own exporter.

The provider now skips that placeholder when the config has any other
exporter. A console exporter the operator names with OTEL_EXPORTER=console is
kept, and so is the placeholder when it is the only exporter.
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge, with both numbered findings fixed

Summary

This PR stops unrequested OTel v2 span output while keeping explicitly configured console exporters and the plain otel callback's default output

The latest changes carry that console choice through service-name routing and remove inherited Langfuse keys from tests that require no global keys. Both numbered findings are fixed. No new actionable issue was found in the changes since the previous review

  • OTel v2 prints spans to stdout only when console output is chosen.

Reviews (4) · Last reviewed commit: "fix(otel): keep the otel callback's cons..." · Reviewed by Greptile

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@codspeed

codspeed Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 35 untouched benchmarks


Comparing litellm_otel_v2_no_unrequested_console (4e50a92) with main (cf7c35a)

Open in CodSpeed

@yucheng-berri yucheng-berri changed the title fix(otel): stop OTel v2 vendor presets from printing every span to stdout fix(otel)!: stop OTel v2 vendor presets from printing every span to stdout Oct 28, 2026
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

The proxy's background V2 logger (published when no callback built one, which is
what key-only and team-only Langfuse destinations run under) also kept the
unconfigured console exporter, so it printed every span with prompts to stdout.
The console default now prints only for a listed otel callback or an exporter the
operator named.
@yucheng-berri yucheng-berri changed the title fix(otel)!: stop OTel v2 vendor presets from printing every span to stdout fix(otel)!: print OTel v2 spans to stdout only when the operator asks Oct 28, 2026
…utes

A key or team otel_service_name moves the call onto a provider the tenant
tracer cache builds, which never got the console choice, so the plain otel
callback stopped printing those calls. The no-operator-keys integration rig
also drops inherited Langfuse keys.
@yucheng-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 4e50a92. Configure here.

@yucheng-berri
yucheng-berri merged commit ffcc4f7 into main Oct 29, 2026
99 of 104 checks passed
@yucheng-berri
yucheng-berri deleted the litellm_otel_v2_no_unrequested_console branch October 29, 2026 19:20
yucheng-berri added a commit that referenced this pull request Oct 29, 2026
…tdout exporter (#49129)

#48718 added TestLangfuseDestinationFields while #48723 made the unconfigured
stdout placeholder opt-in (console_default=True, the otel callback's setting).
Both merged within a minute, so main's integrations job fails six tests that
read the placeholder's exporter. Build those providers with console_default=True
so the operator-exporter checks keep their target.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants