Skip to content

Commit 8d4c769

Browse files
committed
fix: ensure litellm async calls with stream reports token usage and span status
1 parent dc9b1ae commit 8d4c769

File tree

1 file changed

+5
-2
lines changed
  • python/instrumentation/openinference-instrumentation-litellm/src/openinference/instrumentation/litellm

1 file changed

+5
-2
lines changed

python/instrumentation/openinference-instrumentation-litellm/src/openinference/instrumentation/litellm/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from enum import Enum
22
from functools import wraps
3+
from types import SimpleNamespace
34
from typing import (
45
Any,
56
Callable,
@@ -512,7 +513,7 @@ def _finalize_sync_streaming_span(span: trace_api.Span, stream: CustomStreamWrap
512513
)
513514

514515
if usage_stats:
515-
_set_token_counts_from_usage(span, usage_stats)
516+
_set_token_counts_from_usage(span, SimpleNamespace(usage=usage_stats))
516517
except Exception as e:
517518
span.record_exception(e)
518519
raise
@@ -553,10 +554,12 @@ async def _finalize_streaming_span(span: trace_api.Span, stream: CustomStreamWra
553554
span, f"{SpanAttributes.LLM_OUTPUT_MESSAGES}.{idx}.{key}", value
554555
)
555556
if usage_stats:
556-
_set_token_counts_from_usage(span, usage_stats)
557+
_set_token_counts_from_usage(span, SimpleNamespace(usage=usage_stats))
557558
except Exception as e:
558559
span.record_exception(e)
559560
raise
561+
else:
562+
_set_span_status(span, aggregated_output)
560563
finally:
561564
span.end()
562565

0 commit comments

Comments
 (0)