Commit 0b67b64
Fix OTEL span redundancy, orphaned guardrail traces, and missing response IDs
Addresses 4 critical OpenTelemetry span issues in LiteLLM:
Issue #3: Remove redundant attributes from raw_gen_ai_request spans
- Removed self.set_attributes() call that was duplicating all parent span
attributes (gen_ai.*, metadata.*) onto the raw span
- Raw span now only contains provider-specific llm.{provider}.* attributes
- Reduces storage and eliminates search confusion from duplicate data
Issue #4: Prevent attribute duplication on litellm_proxy_request parent span
- When litellm_request child span exists, removed redundant
set_attributes() call on the parent proxy span
- Child span already carries all attributes; parent duplication doubles
storage and complicates search
Issue #5: Fix orphaned guardrail traces
- Guardrail spans were created with context=None when no parent proxy span
existed, resulting in orphaned root spans (separate trace_id)
- Added _resolve_guardrail_context() helper to ensure guardrails always
have a valid parent (litellm_request or proxy span)
- Applied fix to both _handle_success and _handle_failure paths
Issue #8: Add gen_ai.response.id for embeddings and image generation
- EmbeddingResponse and ImageResponse types don't have provider response IDs
- Added fallback to standard_logging_payload["id"] (litellm call ID) for
correlation across LiteLLM UI, Phoenix traces, and provider logs
- Completions still use provider ID (e.g. "chatcmpl-xxx") when available
Tests added:
- TestRawSpanAttributeIsolation: Verify raw span has no gen_ai/metadata attrs
- TestNoParentSpanDuplication: Verify parent span doesn't get duplicated attrs
- TestGuardrailSpanParenting: Verify guardrails are children (not orphaned)
- TestResponseIdFallback: Verify response ID set for all call types
All existing OTEL tests pass (73 passed, 14 pre-existing protocol failures).
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>1 parent 3a2cba4 commit 0b67b64
2 files changed
Lines changed: 390 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
735 | 735 | | |
736 | 736 | | |
737 | 737 | | |
738 | | - | |
739 | | - | |
740 | | - | |
741 | | - | |
742 | | - | |
743 | | - | |
744 | | - | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
745 | 742 | | |
746 | 743 | | |
747 | 744 | | |
| |||
757 | 754 | | |
758 | 755 | | |
759 | 756 | | |
760 | | - | |
761 | | - | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
762 | 763 | | |
763 | 764 | | |
764 | 765 | | |
| |||
1145 | 1146 | | |
1146 | 1147 | | |
1147 | 1148 | | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
1148 | 1170 | | |
1149 | 1171 | | |
1150 | 1172 | | |
| |||
1250 | 1272 | | |
1251 | 1273 | | |
1252 | 1274 | | |
| 1275 | + | |
1253 | 1276 | | |
1254 | 1277 | | |
1255 | 1278 | | |
| |||
1275 | 1298 | | |
1276 | 1299 | | |
1277 | 1300 | | |
1278 | | - | |
1279 | | - | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
1280 | 1306 | | |
1281 | 1307 | | |
1282 | 1308 | | |
| |||
1579 | 1605 | | |
1580 | 1606 | | |
1581 | 1607 | | |
1582 | | - | |
1583 | | - | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
1584 | 1618 | | |
1585 | 1619 | | |
1586 | 1620 | | |
1587 | | - | |
| 1621 | + | |
1588 | 1622 | | |
1589 | 1623 | | |
1590 | 1624 | | |
| |||
1808 | 1842 | | |
1809 | 1843 | | |
1810 | 1844 | | |
1811 | | - | |
1812 | | - | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
1813 | 1849 | | |
1814 | 1850 | | |
1815 | 1851 | | |
| |||
0 commit comments