feat(otel): set http.response.status_code on the success SERVER span#28090
Conversation
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 SummaryThis PR adds
Confidence Score: 5/5Safe 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 No files require special attention.
|
| 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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Summary
The proxy SERVER span (
Received Proxy Server Request) only carriedhttp.response.status_codeon 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 aset_response_status_code_attributehelper and calls it fromasync_post_call_success_hookwith200, 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
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-opmake test-unitslice: 18 tests in the OTel attribute suite (route / preprocessing / server-span / new) pass; Black cleancallbacks: ["otel"];mock-success200 request →Received Proxy Server Requestspan carrieshttp.response.status_code=200alongsidehttp.route,url.path,litellm.preprocessing.duration_ms