Skip to content

fix(otel): stamp team attributes before ending proxy span - #45612

Open
MaxRink wants to merge 1 commit into
BerriAI:mainfrom
MaxRink:fix/otel-team-attributes-before-span-end
Open

MaxRink wants to merge 1 commit into
BerriAI:mainfrom
MaxRink:fix/otel-team-attributes-before-span-end

Conversation

@MaxRink

@MaxRink MaxRink commented Oct 9, 2026 •

Copy link
Copy Markdown

What does this change?

Stamp proxy-root team attributes before the success callback closes the
LiteLLM-created proxy span. The same lookup now covers metadata used by
Anthropic routes.

Why?

_handle_success currently calls _close_proxy_span_ok, which ends the proxy
root, and then calls _set_team_attributes_on_proxy_span_from_kwargs. The
second call attempts to set attributes on the ended span and OpenTelemetry
emits Setting attribute on ended span.. This was reproduced against the
pinned gateway and the current upstream head.

Testing

  • Extended tests/unit/integrations/test_opentelemetry.py with an in-memory
    tracer regression covering both metadata containers, finished root
    attributes, and zero ended-span warnings
  • python3 -m py_compile litellm/integrations/opentelemetry.py tests/unit/integrations/test_opentelemetry.py
  • Focused regression passed in a disposable network-disabled v1.104.2 image
    with no provider credentials or OTLP exporter
  • Full pytest collection was unavailable in the local image because pytest is
    not installed; hosted unit and lint checks are running on this PR

Related context: #16779

@CLAassistant

CLAassistant commented Oct 9, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@MaxRink
MaxRink marked this pull request as ready for review October 9, 2026 16:58
Copilot AI balanced review requested due to automatic review settings October 9, 2026 16:58
@codspeed

codspeed Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 35 untouched benchmarks


Comparing MaxRink:fix/otel-team-attributes-before-span-end (433cb5a) with main (0a1dbc0)

Open in CodSpeed

Copilot AI 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.

🟡 Changes recommended

Anthropic metadata routes remain unstamped, and the new test violates enforced test-placement and LIT010 rules

5 open findings
What changed in this PR

Moves proxy-root team attribute stamping before span closure to prevent ended-span warnings

Changes:

  • Reorders team attribute stamping on successful requests
  • Adds an in-memory OpenTelemetry regression test
File Description
litellm/​integrations/​opentelemetry.py Stamps team attributes before closing the proxy span
tests/​unit/​integrations/​test_otel_proxy_span_lifecycle.py Tests successful proxy span closure and attributes

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread litellm/integrations/opentelemetry.py Resolved
Comment thread litellm/integrations/opentelemetry.py Resolved
@greptile-apps

greptile-apps Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new blocking issue found

Summary

The PR stamps team attributes before closing the proxy root span and adds lookup through litellm_metadata

  • Successful proxy traces keep team details on the root span.

Reviews (2) · Last reviewed commit: "ci: remove temporary GHCR publisher from..." · Reviewed by Greptile

Comment thread litellm/integrations/opentelemetry.py Resolved
@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@MaxRink
MaxRink marked this pull request as draft October 9, 2026 17:08
@MaxRink
MaxRink marked this pull request as ready for review October 9, 2026 23:20
Set the team id and alias attributes on the proxy request span before
the span ends, reading them from either litellm_metadata or metadata,
so they are exported instead of being dropped with an
'attribute on ended span' warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxRink
MaxRink force-pushed the fix/otel-team-attributes-before-span-end branch from a954c96 to 433cb5a Compare October 27, 2026 18:02
@MaxRink

MaxRink commented Oct 27, 2026

Copy link
Copy Markdown
Author

CI note: the osv-scan failure doesn't come from this PR. This PR doesn't touch the lockfiles, and the job flags Pillow, msgpack and filelock advisories in uv.lock on main. #48552 tracks this; see also #48611 (msgpack) and #48302 (filelock).

Rebased onto current main and squashed to a single commit (433cb5a). The temporary GHCR publisher commits cancelled each other out, so I dropped them. The new team-attribute tests pass locally, and the rest of test_opentelemetry.py fails in exactly the same way locally as on main.

This branch has not been deployed

No deployments
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.

4 participants