Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.
TypeScript agent-harnessagent-harness-engineeringai-engineeringai-observabilityamd-gpuclaude-codeclickhousecodexcoding-agentcoding-agentscursorgenaigpu-monitoringllm-observabilityllmopsnvidia-smiobservabilityopen-sourceopenaiopentelemetry
[Fix]: Incorrect start time in spans when streaming and encoding key in LiteLLM (#883)
Patcher262c763a3748
diff --git a/sdk/python/pyproject.toml b/sdk/python/pyproject.tomlindex 66203d4a..25321411 100644--- a/sdk/python/pyproject.toml+++ b/sdk/python/pyproject.toml@@ -1,6 +1,6 @@[tool.poetry]name = "openlit"-version = "1.35.3"+version = "1.35.4"description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects"authors = ["OpenLIT"]license = "Apache-2.0"diff --git a/sdk/python/src/openlit/instrumentation/litellm/async_litellm.py b/sdk/python/src/openlit/instrumentation/litellm/async_litellm.pyindex 241f9cf8..64cfffd2 100644--- a/sdk/python/src/openlit/instrumentation/litellm/async_litellm.py+++ b/sdk/python/src/openlit/instrumentation/litellm/async_litellm.py@@ -85,22 +85,23 @@ def acompletion(return chunkexcept StopAsyncIteration:try:- with tracer.start_as_current_span(- self._span_name, kind=SpanKind.CLIENT- ) as self._span:- process_streaming_chat_response(- self,- pricing_info=pricing_info,- environment=environment,- application_name=application_name,- metrics=metrics,- capture_message_content=capture_message_content,- disable_metrics=disable_metrics,- version=version,- )+ # Use the existing span that was started when the stream began+ process_streaming_chat_response(+ self,+ pricing_info=pricing_info,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version,+ )+ # End the span after processing+ self._span.end()except Exception as e:handle_exception(self._span, e)+ self._span.end()raisediff --git a/sdk/python/src/openlit/instrumentation/litellm/litellm.py b/sdk/python/src/openlit/instrumentation/litellm/litellm.pyindex 4afeb1ec..1a99383c 100644--- a/sdk/python/src/openlit/instrumentation/litellm/litellm.py+++ b/sdk/python/src/openlit/instrumentation/litellm/litellm.py@@ -85,22 +85,23 @@ def completion(return chunkexcept StopIteration:try:- with tracer.start_as_current_span(- self._span_name, kind=SpanKind.CLIENT- ) as self._span:- process_streaming_chat_response(- self,- pricing_info=pricing_info,- environment=environment,- application_name=application_name,- metrics=metrics,- capture_message_content=capture_message_content,- disable_metrics=disable_metrics,- version=version,- )+ # Use the existing span that was started when the stream began+ process_streaming_chat_response(+ self,+ pricing_info=pricing_info,+ environment=environment,+ application_name=application_name,+ metrics=metrics,+ capture_message_content=capture_message_content,+ disable_metrics=disable_metrics,+ version=version,+ )+ # End the span after processing+ self._span.end()except Exception as e:handle_exception(self._span, e)+ self._span.end()raisediff --git a/sdk/python/src/openlit/instrumentation/litellm/utils.py b/sdk/python/src/openlit/instrumentation/litellm/utils.pyindex 68982554..c99cd8ff 100644--- a/sdk/python/src/openlit/instrumentation/litellm/utils.py+++ b/sdk/python/src/openlit/instrumentation/litellm/utils.py@@ -100,7 +100,10 @@ def process_chunk(scope, chunk):scope._output_tokens = chunked.get("usage").get("completion_tokens", 0)scope._response_id = chunked.get("id")scope._response_model = chunked.get("model")- scope._finish_reason = chunked.get("choices", [{}])[0].get("finish_reason")+ finish_reason = chunked.get("choices", [{}])[0].get("finish_reason")+ # Only update finish_reason if it's not None (preserve previous valid value)+ if finish_reason is not None:+ scope._finish_reason = finish_reasonscope._response_service_tier = str(chunked.get("system_fingerprint", ""))scope._end_time = time.time()@@ -189,7 +192,7 @@ def common_chat_logic(# Span Attributes for Response parametersscope._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID, scope._response_id)scope._span.set_attribute(- SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON, [scope._finish_reason]+ SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON, [scope._finish_reason or ""])scope._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_SERVICE_TIER, scope._response_service_tier