Repository navigation
fix(otel): restore error.* span attributes on v2 error spans (LIT-4179) - #32524
yucheng-berri merged 1 commit into
Conversation
Greptile SummaryRestores the four missing
Confidence Score: 5/5Additive-only change; all new SpanError fields default to None, the emitter's success path is untouched, and the exception event continues to emit unchanged. Every modified call site is inside the existing error branch of finish_span. The three new SpanError fields are Optional with None defaults, so no existing SpanError construction site is broken. The _stamp_litellm_error_attributes helper guards each attribute behind a truthiness check, so guardrail-shape errors that carry only a message produce no spurious empty-string attributes. All assertions in the touched existing test remain identical. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/integrations/otel/emitter.py | Adds two module-level helpers (_stamp_otel_error_attributes, _stamp_litellm_error_attributes) and calls them in finish_span's error branch; no logic change to success paths. |
| litellm/integrations/otel/model/payloads.py | SpanError gains three optional fields (code, stack_trace, llm_provider); _parse_error threads them from error_information with None-safe as_str coercions. |
| litellm/integrations/otel/model/semconv.py | Error class gains MESSAGE constant; new LiteLLMError class adds CODE, STACK_TRACE, LLM_PROVIDER under the error.* namespace for v1 byte-for-byte parity. |
| litellm/integrations/otel/init.py | Re-exports LiteLLMError on the package surface alongside Error. |
| tests/test_litellm/integrations/otel/test_otel_v2_components.py | Four new regression tests added; existing test_error_message_recorded_as_full_exception_event_untruncated has only its docstring and comment text updated — all assertions remain identical, no coverage weakened. |
| tests/test_litellm/integrations/otel/test_otel_v2_sources_of_truth.py | Two new payload-level tests for _parse_error detail threading; uniqueness sweep extended to include LiteLLMError. |
Reviews (2): Last reviewed commit: "fix(otel): restore error.* span attribut..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
bugbot run |
There was a problem hiding this comment.
✅ 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 7e12b0027d81ef0f79ec41c3d52a700d5386d857. Configure here.
5d1c3b1 to
29f263a
Compare
The v2 emitter has never stamped error.message / error.code / error.stack_trace / error.llm_provider as span attributes; only error.type reached the wire. Backends that flatten span attributes into label indexes (Elastic APM labels.error_*, Datadog span tags) lost these four fields when v2 became the active integration on v1.90+ for otel_v2-flagged deployments. The pre-existing exception span event carrying the full message (LIT-3758) is unchanged; the message now rides both places at once, matching v1s shape. SpanError grows three optional detail fields; _parse_error threads them from StandardLoggingPayloadErrorInformation; the emitters error branch stamps them via a new module-level helper, guarded per field so guardrail-shape errors are not polluted with empty attributes. New semconv constants mirror open_inference.ErrorAttributes byte-for-byte, so v1 and v2 consumers read the same keys. Regression tests extend the mapped test files under tests/test_litellm/integrations/otel/. pytest reports 243 passed.
29f263a to
5c21928
Compare
|
bugbot run |
There was a problem hiding this comment.
✅ 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 5c21928. Configure here.
….1) (#1475) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [ghcr.io/berriai/litellm](https://images.chainguard.dev/directory/image/wolfi-base/overview) ([source](https://github.com/BerriAI/litellm)) | patch | `v1.91.0` → `v1.91.1` | --- ### Release Notes <details> <summary>BerriAI/litellm (ghcr.io/berriai/litellm)</summary> ### [`v1.91.1`](https://github.com/BerriAI/litellm/releases/tag/v1.91.1) [Compare Source](BerriAI/litellm@v1.91.1...v1.91.1) ##### Verify Docker Image Signature All LiteLLM Docker images are signed with [cosign](https://docs.sigstore.dev/cosign/overview/). Every release is signed with the same key introduced in [commit `0112e53`](BerriAI/litellm@0112e53). **Verify using the pinned commit hash (recommended):** A commit hash is cryptographically immutable, so this is the strongest way to ensure you are using the original signing key: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/0112e53046018d726492c814b3644b7d376029d0/cosign.pub \ ghcr.io/berriai/litellm:v1.91.1 ``` **Verify using the release tag (convenience):** Tags are protected in this repository and resolve to the same key. This option is easier to read but relies on tag protection rules: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/v1.91.1/cosign.pub \ ghcr.io/berriai/litellm:v1.91.1 ``` Expected output: ``` The following checks were performed on each of these signatures: - The cosign claims were validated - The signatures were verified against the specified public key ``` *** ##### What's Changed - chore(release): backport [#​32256](BerriAI/litellm#32256), [#​32405](BerriAI/litellm#32405), [#​32524](BerriAI/litellm#32524) to stable/1.91.x and cut 1.91.1 by [@​yuneng-berri](https://github.com/yuneng-berri) in [#​32552](BerriAI/litellm#32552) **Full Changelog**: <BerriAI/litellm@v1.91.0...v1.91.1> ### [`v1.91.1`](https://github.com/BerriAI/litellm/releases/tag/v1.91.1) [Compare Source](BerriAI/litellm@v1.91.0...v1.91.1) ##### Verify Docker Image Signature All LiteLLM Docker images are signed with [cosign](https://docs.sigstore.dev/cosign/overview/). Every release is signed with the same key introduced in [commit `0112e53`](BerriAI/litellm@0112e53). **Verify using the pinned commit hash (recommended):** A commit hash is cryptographically immutable, so this is the strongest way to ensure you are using the original signing key: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/0112e53046018d726492c814b3644b7d376029d0/cosign.pub \ ghcr.io/berriai/litellm:v1.91.1 ``` **Verify using the release tag (convenience):** Tags are protected in this repository and resolve to the same key. This option is easier to read but relies on tag protection rules: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/v1.91.1/cosign.pub \ ghcr.io/berriai/litellm:v1.91.1 ``` Expected output: ``` The following checks were performed on each of these signatures: - The cosign claims were validated - The signatures were verified against the specified public key ``` *** ##### What's Changed - chore(release): backport [#​32256](BerriAI/litellm#32256), [#​32405](BerriAI/litellm#32405), [#​32524](BerriAI/litellm#32524) to stable/1.91.x and cut 1.91.1 by [@​yuneng-berri](https://github.com/yuneng-berri) in [#​32552](BerriAI/litellm#32552) **Full Changelog**: <BerriAI/litellm@v1.91.0...v1.91.1> </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMDEuMSIsInVwZGF0ZWRJblZlciI6IjQzLjEwMS4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19--> Reviewed-on: https://git.erwanleboucher.dev/eleboucher/homelab/pulls/1475
….1) (#488) This PR contains the following updates: | Package | Update | Change | |---|---|---| | [ghcr.io/berriai/litellm](https://images.chainguard.dev/directory/image/wolfi-base/overview) ([source](https://github.com/BerriAI/litellm)) | patch | `v1.91.0` → `v1.91.1` | --- ### Release Notes <details> <summary>BerriAI/litellm (ghcr.io/berriai/litellm)</summary> ### [`v1.91.1`](https://github.com/BerriAI/litellm/releases/tag/v1.91.1) [Compare Source](BerriAI/litellm@v1.91.1...v1.91.1) ##### Verify Docker Image Signature All LiteLLM Docker images are signed with [cosign](https://docs.sigstore.dev/cosign/overview/). Every release is signed with the same key introduced in [commit `0112e53`](BerriAI/litellm@0112e53). **Verify using the pinned commit hash (recommended):** A commit hash is cryptographically immutable, so this is the strongest way to ensure you are using the original signing key: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/0112e53046018d726492c814b3644b7d376029d0/cosign.pub \ ghcr.io/berriai/litellm:v1.91.1 ``` **Verify using the release tag (convenience):** Tags are protected in this repository and resolve to the same key. This option is easier to read but relies on tag protection rules: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/v1.91.1/cosign.pub \ ghcr.io/berriai/litellm:v1.91.1 ``` Expected output: ``` The following checks were performed on each of these signatures: - The cosign claims were validated - The signatures were verified against the specified public key ``` *** ##### What's Changed - chore(release): backport [#​32256](BerriAI/litellm#32256), [#​32405](BerriAI/litellm#32405), [#​32524](BerriAI/litellm#32524) to stable/1.91.x and cut 1.91.1 by [@​yuneng-berri](https://github.com/yuneng-berri) in [#​32552](BerriAI/litellm#32552) **Full Changelog**: <BerriAI/litellm@v1.91.0...v1.91.1> ### [`v1.91.1`](https://github.com/BerriAI/litellm/releases/tag/v1.91.1) [Compare Source](BerriAI/litellm@v1.91.0...v1.91.1) ##### Verify Docker Image Signature All LiteLLM Docker images are signed with [cosign](https://docs.sigstore.dev/cosign/overview/). Every release is signed with the same key introduced in [commit `0112e53`](BerriAI/litellm@0112e53). **Verify using the pinned commit hash (recommended):** A commit hash is cryptographically immutable, so this is the strongest way to ensure you are using the original signing key: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/0112e53046018d726492c814b3644b7d376029d0/cosign.pub \ ghcr.io/berriai/litellm:v1.91.1 ``` **Verify using the release tag (convenience):** Tags are protected in this repository and resolve to the same key. This option is easier to read but relies on tag protection rules: ```bash cosign verify \ --key https://raw.githubusercontent.com/BerriAI/litellm/v1.91.1/cosign.pub \ ghcr.io/berriai/litellm:v1.91.1 ``` Expected output: ``` The following checks were performed on each of these signatures: - The cosign claims were validated - The signatures were verified against the specified public key ``` *** ##### What's Changed - chore(release): backport [#​32256](BerriAI/litellm#32256), [#​32405](BerriAI/litellm#32405), [#​32524](BerriAI/litellm#32524) to stable/1.91.x and cut 1.91.1 by [@​yuneng-berri](https://github.com/yuneng-berri) in [#​32552](BerriAI/litellm#32552) **Full Changelog**: <BerriAI/litellm@v1.91.0...v1.91.1> </details> --- ### Configuration 📅 **Schedule**: (in timezone America/New_York) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNTIuMSIsInVwZGF0ZWRJblZlciI6IjQzLjI1Mi4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19--> Reviewed-on: https://git.greyrock.io/greyrock-labs/home-ops/pulls/488
…9) (BerriAI#32524) The v2 emitter has never stamped error.message / error.code / error.stack_trace / error.llm_provider as span attributes; only error.type reached the wire. Backends that flatten span attributes into label indexes (Elastic APM labels.error_*, Datadog span tags) lost these four fields when v2 became the active integration on v1.90+ for otel_v2-flagged deployments. The pre-existing exception span event carrying the full message (LIT-3758) is unchanged; the message now rides both places at once, matching v1s shape. SpanError grows three optional detail fields; _parse_error threads them from StandardLoggingPayloadErrorInformation; the emitters error branch stamps them via a new module-level helper, guarded per field so guardrail-shape errors are not polluted with empty attributes. New semconv constants mirror open_inference.ErrorAttributes byte-for-byte, so v1 and v2 consumers read the same keys. Regression tests extend the mapped test files under tests/test_litellm/integrations/otel/. pytest reports 243 passed. (cherry picked from commit 85d1fe6)
Relevant issues
Linear ticket
Resolves LIT-4179
Pre-Submission checklist
Screenshots / Proof of Fix
Captured on macOS with a Jaeger v2.19.0 all-in-one binary receiving OTLP/HTTP on :4318 from a local litellm proxy running against a config that points
gpt-4oat the IANA discard port so every completion fails with a real Connection error. Same request body in both runs, same Jaeger backend, same trace ID space; only the litellm binary differs.Reproduction commands
Before, unfixed baseline commit
db2402754aTags on the
chat gpt-4ospan carryerror.typealone. The four othererror.*fields never land on the span. Elastic APM's default APM ingest reads span attributes intolabels.*, so on the customer's Kibana viewlabels.error_message/labels.error_code/labels.error_stack_trace/labels.error_llm_providerall render empty.Logs (1)still contains theexceptionevent withexception.message(from PR #30380 / LIT-3758), so backends that consume the OTel exception event field continue to see the full untruncated message; Elastic's default ingest does not surface that onlabels.*.After, this branch

Same request, same Jaeger instance:
Tags now carry the full v1-shape error detail set:
error.code = 500,error.llm_provider = openai,error.message = litellm.InternalServerError: ...,error.stack_trace = File "/Users/.../litellm/utils.py", line 1689, in wrapper_async ...with the full traceback preserved,error.type = InternalServerError.Logs (1)still shows theexceptionevent withexception.messageintact so PR #30380's Elasticsearch truncation fix stays in place.Elastic APM's ingest maps recognized
error.*attributes tolabels.error_*by default, so downstream Kibanalabels.error_messageetc. panels populate as they did on v1.89.Type
🐛 Bug Fix
Changes
Root cause
The v2 emitter (
litellm/integrations/otel/emitter.py:SpanEmitter.finish_span) stamps onlyerror.typeas a span attribute; the message rides the span-status description plus, since PR #30380, a semconv-standardexceptionevent underexception.message. The v1 integration (litellm/integrations/opentelemetry.py:_record_exception_on_span) stamps five span attributes (error.type,error.message,error.code,error.stack_trace,error.llm_provider). When v2 became the active integration on v1.90+ forotel_v2-flagged deployments, downstream backends that flatten span attributes into label indexes (Elastic APMlabels.error_*, Datadog span tags) lost the four detail fields; v2 was never taught to stamp them.The v2 emitter was born without these fields (commit
d82eb33a60, "typed semconv-aligned OpenTelemetry instrumentation"); PR #30380 added the exception event, not the missing attributes. The regression surfaces on v1.90 because that is the release where v2 fully replaced v1 forotel_v2-flagged customers.Fix
Additive; v2 now stamps the same four detail attributes as v1, with keys byte-for-byte matching
litellm/integrations/_types/open_inference.py:ErrorAttributesso consumers do not care which integration produced the span. The exception event is preserved so PR #30380's Elasticsearch keyword-truncation fix stays in force; the message now lives in both places.Attribute keys are split across two semconv classes so a reader can tell OTel-defined keys apart from litellm's namespace-extension keys at a glance:
class Errorinsemconv.pyholds only the OTel-registry-defined keys —error.type(Stable) anderror.message(Deprecated but still defined; kept for byte-for-byte parity with v1).class LiteLLMErrorholdserror.code,error.stack_trace,error.llm_provider. None of these three appears in the OTelerror.*registry; per semconv extension rules a namespace may carry additional vendor keys as long as no defined name collides. Thetest_attribute_keys_are_unique_across_namespacessources-of-truth test enforces the no-collision invariant across all attribute classes.The wire is byte-for-byte unchanged from v1: all five keys still emit under the
error.*namespace, so consumer dashboards continue to renderlabels.error_*without changes.Files touched:
litellm/integrations/otel/model/payloads.py:SpanErrorgrows three optional fields (code,stack_trace,llm_provider);_parse_errorthreads them from the payload'serror_informationblock.litellm/integrations/otel/model/semconv.py:Errorgrows aMESSAGEconstant for the OTel-registry key; newLiteLLMErrorclass carries the three litellm-namespaced extension keys with their rationale in the docstring.litellm/integrations/otel/emitter.py: two module-level helpers,_stamp_otel_error_attributes(stampsError.TYPE+Error.MESSAGE) and_stamp_litellm_error_attributes(stamps the threeLiteLLMError.*keys, guarded per field so guardrail-shape errors that only carry a message are not polluted with empty-string attributes). Called in that order fromfinish_span's existing error branch.litellm/integrations/otel/__init__.py: re-exportsLiteLLMErroralongsideErroron the package surface.Regression tests
Extended the mapped test files under
tests/test_litellm/integrations/otel/:test_otel_v2_components.py:test_error_details_stamped_as_span_attributes_for_labels_ingestpins the LIT-4179 regression against future drift, asserting bothError.*andLiteLLMError.*keys land on the span;test_error_details_omitted_when_span_error_carries_only_messagelocks the per-field guard onLiteLLMError.*;test_v2_error_attribute_keys_match_v1_error_attributes_byte_for_bytelocks the vocabulary across both classes against v1;test_error_message_falls_back_to_error_type_when_message_absentpins the three-surface consistency invariant. The pre-existingtest_error_message_recorded_as_full_exception_event_untruncatedcontinues to cover the exception-event path.test_otel_v2_sources_of_truth.py:test_llm_call_adapter_carries_error_detail_fieldsandtest_llm_call_adapter_error_details_default_to_none_when_absentcover the payload-to-SpanErrorplumbing;test_attribute_keys_are_unique_across_namespacesnow sweepsLiteLLMErrorso a future rename cannot silently collide withError.python -m pytest tests/test_litellm/integrations/otel/ -qreports243 passed.Blast radius
Every v2 failure span funnels through
SpanEmitter.finish_span, so the fix coversLLM_CALL,GUARDRAIL,SERVICE,DB_CALL,MCP_TOOL_CALL, andMCP_LIST_TOOLSin one shot. No behavior change to success spans (the emitter's error branch is gated onerror and (error.error_type or error.message)), no removals, no renames, no changes to v1.Backward compatibility
Additive-only.
SpanError's three new fields are optional withNonedefaults, so every existingSpanError(...)call site keeps compiling untouched. The new semconv constants have values byte-identical to v1'sErrorAttributes, so any consumer already readinglabels.error_*from v1 spans reads the same key from v2 spans. Theexceptionevent,error.typeattribute, and span-status description continue to emit exactly as beforeNote
Low Risk
Additive observability-only changes on the existing v2 error path; success spans and v1 integration are untouched, with regression tests for key parity and optional fields.
Overview
Restores v1-parity error detail on OpenTelemetry v2 failure spans so observability backends that index span attributes (Elastic
labels.error_*, Datadog tags) see the full error shape again, not onlyerror.type.SpanErrorand_parse_errornow carry optionalcode,stack_trace, andllm_providerfromerror_information.SpanEmitter.finish_spanstampserror.messageplus those fields viaError/LiteLLMErrorhelpers (detail keys only when set). The existingexceptionevent and ERROR status behavior are unchanged.Tests lock attribute keys against v1
ErrorAttributes, label-ingest behavior, message-only guardrail errors, and payload plumbing.Reviewed by Cursor Bugbot for commit 5c21928. Bugbot is set up for automated code reviews on this repo. Configure here.