Skip to content

feat(otel): set http.response.status_code on the success SERVER span#28090

Merged
yassin-berriai merged 1 commit into
litellm_internal_stagingfrom
litellm_otel_success_span_status_code
May 16, 2026
Merged

feat(otel): set http.response.status_code on the success SERVER span#28090
yassin-berriai merged 1 commit into
litellm_internal_stagingfrom
litellm_otel_success_span_status_code

Conversation

@ryan-crabbe-berri

@ryan-crabbe-berri ryan-crabbe-berri commented May 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

The proxy SERVER span (Received Proxy Server Request) only carried http.response.status_code on failures (set in _record_exception_on_span); successful requests had no status-code attribute. This left error-ratio and status-breakdown dashboards with no 2xx denominator and made the span non-compliant with the OTel HTTP semantic conventions (the attribute is required whenever a response is sent, not error-only). This adds a set_response_status_code_attribute helper and calls it from async_post_call_success_hook with 200, symmetric with the failure path and with the route / preprocessing-duration attributes that already land on the success SERVER span. Follow-up to #28040.

Screenshot

Screenshot 2026-05-16 at 3 05 07 PM Screenshot 2026-05-16 at 3 05 34 PM

Test plan

  • tests/test_litellm/integrations/test_opentelemetry.py::TestOpenTelemetrySetResponseStatusCodeAttribute — int-200 on success, None status code omits the attribute, None span is a no-op
  • make test-unit slice: 18 tests in the OTel attribute suite (route / preprocessing / server-span / new) pass; Black clean
  • Manual: Jaeger all-in-one + proxy with callbacks: ["otel"]; mock-success 200 request → Received Proxy Server Request span carries http.response.status_code=200 alongside http.route, url.path, litellm.preprocessing.duration_ms

The proxy SERVER span ("Received Proxy Server Request") only carried
http.response.status_code on failures (set in _record_exception_on_span),
so success traces had no 2xx bucket — error-ratio and status-breakdown
dashboards were missing their denominator and the span violated the HTTP
semconv (the attribute is required whenever a response is sent). Add a
set_response_status_code_attribute helper and call it from
async_post_call_success_hook with 200, symmetric with the failure path
and the existing route/preprocessing-duration SERVER-span attributes.
@greptile-apps

greptile-apps Bot commented May 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds http.response.status_code=200 to the successful proxy SERVER span (Received Proxy Server Request) in the OpenTelemetry integration. Previously the attribute was only set on failure spans via _record_exception_on_span, leaving dashboards with no 2xx denominator and the span non-compliant with OTel HTTP semantic conventions.

  • A new set_response_status_code_attribute helper is added, mirroring the pattern of set_proxy_request_route_attributes and set_preprocessing_duration_attribute; it no-ops when span or value is None.
  • async_post_call_success_hook calls the helper with 200, symmetric with the failure path.
  • Three new unit tests verify the int-200 case, the None-value no-op, and the None-span no-op using in-memory OTel spans only.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to adding one telemetry attribute on the success path, with a proper null guard and no mutations to request handling logic.

The helper is a thin wrapper around safe_set_attribute, the null/None guards match the existing pattern, and the call site in async_post_call_success_hook is additive only. Tests are well-targeted in-memory unit tests with no network calls. No existing tests were modified or weakened.

No files require special attention.

Important Files Changed

Filename Overview
litellm/integrations/opentelemetry.py Adds set_response_status_code_attribute helper and calls it with 200 in the success hook; symmetrically placed with the failure-path attribute already set in _record_exception_on_span.
tests/test_litellm/integrations/test_opentelemetry.py Adds three focused unit tests for set_response_status_code_attribute using in-memory spans only; no network calls, consistent with existing test patterns in the file.

Reviews (1): Last reviewed commit: "feat(otel): set http.response.status_cod..." | Re-trigger Greptile

@codecov

codecov Bot commented May 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/integrations/opentelemetry.py 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@yassin-berriai yassin-berriai merged commit 86f73e5 into litellm_internal_staging May 16, 2026
115 checks passed
@yassin-berriai yassin-berriai deleted the litellm_otel_success_span_status_code branch May 16, 2026 22:29
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