openlit 1.34.14__tar.gz → 1.34.15__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {openlit-1.34.14 → openlit-1.34.15}/PKG-INFO +1 -1
- {openlit-1.34.14 → openlit-1.34.15}/pyproject.toml +1 -1
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/litellm/__init__.py +7 -6
- openlit-1.34.15/src/openlit/instrumentation/litellm/async_litellm.py +188 -0
- openlit-1.34.15/src/openlit/instrumentation/litellm/litellm.py +188 -0
- openlit-1.34.15/src/openlit/instrumentation/litellm/utils.py +288 -0
- openlit-1.34.14/src/openlit/instrumentation/litellm/async_litellm.py +0 -592
- openlit-1.34.14/src/openlit/instrumentation/litellm/litellm.py +0 -592
- {openlit-1.34.14 → openlit-1.34.15}/LICENSE +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/README.md +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/__helpers.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/evals/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/evals/all.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/evals/bias_detection.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/evals/hallucination.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/evals/toxicity.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/evals/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/guard/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/guard/all.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/guard/prompt_injection.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/guard/restrict_topic.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/guard/sensitive_topic.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/guard/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ag2/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ag2/ag2.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ai21/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ai21/ai21.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ai21/async_ai21.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ai21/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/anthropic/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/anthropic/anthropic.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/anthropic/async_anthropic.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/anthropic/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/assemblyai/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/assemblyai/assemblyai.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/assemblyai/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/astra/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/astra/astra.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/astra/async_astra.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/astra/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/azure_ai_inference/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/azure_ai_inference/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/bedrock/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/bedrock/bedrock.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/bedrock/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/chroma/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/chroma/chroma.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/cohere/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/cohere/async_cohere.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/cohere/cohere.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/controlflow/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/controlflow/controlflow.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/crawl4ai/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/crawl4ai/async_crawl4ai.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/crawl4ai/crawl4ai.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/crewai/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/crewai/crewai.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/dynamiq/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/dynamiq/dynamiq.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/elevenlabs/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/elevenlabs/async_elevenlabs.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/elevenlabs/elevenlabs.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/elevenlabs/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/embedchain/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/embedchain/embedchain.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/firecrawl/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/firecrawl/firecrawl.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/google_ai_studio/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/google_ai_studio/google_ai_studio.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/google_ai_studio/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/gpt4all/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/gpt4all/gpt4all.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/gpt4all/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/gpu/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/groq/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/groq/async_groq.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/groq/groq.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/groq/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/haystack/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/haystack/haystack.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/julep/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/julep/async_julep.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/julep/julep.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/langchain/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/langchain/async_langchain.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/langchain/langchain.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/letta/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/letta/letta.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/llamaindex/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/llamaindex/llamaindex.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/mem0/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/mem0/mem0.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/milvus/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/milvus/milvus.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/mistral/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/mistral/async_mistral.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/mistral/mistral.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/multion/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/multion/async_multion.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/multion/multion.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ollama/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ollama/async_ollama.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ollama/ollama.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ollama/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/openai/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/openai/async_openai.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/openai/openai.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/openai_agents/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/openai_agents/openai_agents.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/phidata/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/phidata/phidata.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/pinecone/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/pinecone/pinecone.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/premai/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/premai/premai.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/premai/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/pydantic_ai/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/pydantic_ai/pydantic_ai.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/pydantic_ai/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/qdrant/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/qdrant/async_qdrant.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/qdrant/qdrant.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/reka/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/reka/async_reka.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/reka/reka.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/reka/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/together/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/together/async_together.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/together/together.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/together/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/transformers/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/transformers/transformers.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/transformers/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/vertexai/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/vertexai/async_vertexai.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/vertexai/vertexai.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/vllm/__init__.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/vllm/utils.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/vllm/vllm.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/otel/events.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/otel/metrics.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/otel/tracing.py +0 -0
- {openlit-1.34.14 → openlit-1.34.15}/src/openlit/semcov/__init__.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: openlit
|
3
|
-
Version: 1.34.
|
3
|
+
Version: 1.34.15
|
4
4
|
Summary: OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects
|
5
5
|
License: Apache-2.0
|
6
6
|
Keywords: OpenTelemetry,otel,otlp,llm,tracing,openai,anthropic,claude,cohere,llm monitoring,observability,monitoring,gpt,Generative AI,chatGPT,gpu
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[tool.poetry]
|
2
2
|
name = "openlit"
|
3
|
-
version = "1.34.
|
3
|
+
version = "1.34.15"
|
4
4
|
description = "OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications and GPUs, facilitating the integration of observability into your GenAI-driven projects"
|
5
5
|
authors = ["OpenLIT"]
|
6
6
|
license = "Apache-2.0"
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
|
2
1
|
"""Initializer of Auto Instrumentation of LiteLLM Functions"""
|
3
2
|
|
4
3
|
from typing import Collection
|
@@ -17,15 +16,15 @@ _instruments = ("litellm >= 1.52.6",)
|
|
17
16
|
|
18
17
|
class LiteLLMInstrumentor(BaseInstrumentor):
|
19
18
|
"""
|
20
|
-
An instrumentor for LiteLLM
|
19
|
+
An instrumentor for LiteLLM client library.
|
21
20
|
"""
|
22
21
|
|
23
22
|
def instrumentation_dependencies(self) -> Collection[str]:
|
24
23
|
return _instruments
|
25
24
|
|
26
25
|
def _instrument(self, **kwargs):
|
27
|
-
application_name = kwargs.get("application_name", "
|
28
|
-
environment = kwargs.get("environment", "
|
26
|
+
application_name = kwargs.get("application_name", "default")
|
27
|
+
environment = kwargs.get("environment", "default")
|
29
28
|
tracer = kwargs.get("tracer")
|
30
29
|
metrics = kwargs.get("metrics_dict")
|
31
30
|
pricing_info = kwargs.get("pricing_info", {})
|
@@ -33,7 +32,7 @@ class LiteLLMInstrumentor(BaseInstrumentor):
|
|
33
32
|
disable_metrics = kwargs.get("disable_metrics")
|
34
33
|
version = importlib.metadata.version("litellm")
|
35
34
|
|
36
|
-
#
|
35
|
+
# Chat completions
|
37
36
|
wrap_function_wrapper(
|
38
37
|
"litellm",
|
39
38
|
"completion",
|
@@ -41,6 +40,7 @@ class LiteLLMInstrumentor(BaseInstrumentor):
|
|
41
40
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
42
41
|
)
|
43
42
|
|
43
|
+
# Async chat completions
|
44
44
|
wrap_function_wrapper(
|
45
45
|
"litellm",
|
46
46
|
"acompletion",
|
@@ -48,6 +48,7 @@ class LiteLLMInstrumentor(BaseInstrumentor):
|
|
48
48
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
49
49
|
)
|
50
50
|
|
51
|
+
# Embeddings
|
51
52
|
wrap_function_wrapper(
|
52
53
|
"litellm",
|
53
54
|
"embedding",
|
@@ -55,6 +56,7 @@ class LiteLLMInstrumentor(BaseInstrumentor):
|
|
55
56
|
tracer, pricing_info, capture_message_content, metrics, disable_metrics),
|
56
57
|
)
|
57
58
|
|
59
|
+
# Async embeddings
|
58
60
|
wrap_function_wrapper(
|
59
61
|
"litellm",
|
60
62
|
"aembedding",
|
@@ -63,5 +65,4 @@ class LiteLLMInstrumentor(BaseInstrumentor):
|
|
63
65
|
)
|
64
66
|
|
65
67
|
def _uninstrument(self, **kwargs):
|
66
|
-
# Proper uninstrumentation logic to revert patched methods
|
67
68
|
pass
|
@@ -0,0 +1,188 @@
|
|
1
|
+
"""
|
2
|
+
Module for monitoring LiteLLM API calls (async version).
|
3
|
+
"""
|
4
|
+
|
5
|
+
import time
|
6
|
+
from opentelemetry.trace import SpanKind
|
7
|
+
from openlit.__helpers import (
|
8
|
+
handle_exception,
|
9
|
+
set_server_address_and_port
|
10
|
+
)
|
11
|
+
from openlit.instrumentation.litellm.utils import (
|
12
|
+
process_chunk,
|
13
|
+
process_streaming_chat_response,
|
14
|
+
process_chat_response,
|
15
|
+
process_embedding_response
|
16
|
+
)
|
17
|
+
from openlit.semcov import SemanticConvention
|
18
|
+
|
19
|
+
def acompletion(version, environment, application_name, tracer, pricing_info,
|
20
|
+
capture_message_content, metrics, disable_metrics):
|
21
|
+
"""
|
22
|
+
Generates a telemetry wrapper for GenAI function call
|
23
|
+
"""
|
24
|
+
|
25
|
+
class TracedAsyncStream:
|
26
|
+
"""
|
27
|
+
Wrapper for async streaming responses to collect telemetry.
|
28
|
+
"""
|
29
|
+
|
30
|
+
def __init__(
|
31
|
+
self,
|
32
|
+
wrapped,
|
33
|
+
span,
|
34
|
+
span_name,
|
35
|
+
kwargs,
|
36
|
+
server_address,
|
37
|
+
server_port,
|
38
|
+
**args,
|
39
|
+
):
|
40
|
+
self.__wrapped__ = wrapped
|
41
|
+
self._span = span
|
42
|
+
self._span_name = span_name
|
43
|
+
self._llmresponse = ""
|
44
|
+
self._response_id = ""
|
45
|
+
self._response_model = ""
|
46
|
+
self._finish_reason = ""
|
47
|
+
self._response_service_tier = ""
|
48
|
+
self._tools = None
|
49
|
+
self._input_tokens = 0
|
50
|
+
self._output_tokens = 0
|
51
|
+
self._args = args
|
52
|
+
self._kwargs = kwargs
|
53
|
+
self._start_time = time.time()
|
54
|
+
self._end_time = None
|
55
|
+
self._timestamps = []
|
56
|
+
self._ttft = 0
|
57
|
+
self._tbt = 0
|
58
|
+
self._server_address = server_address
|
59
|
+
self._server_port = server_port
|
60
|
+
|
61
|
+
async def __aenter__(self):
|
62
|
+
await self.__wrapped__.__aenter__()
|
63
|
+
return self
|
64
|
+
|
65
|
+
async def __aexit__(self, exc_type, exc_value, traceback):
|
66
|
+
await self.__wrapped__.__aexit__(exc_type, exc_value, traceback)
|
67
|
+
|
68
|
+
def __aiter__(self):
|
69
|
+
return self
|
70
|
+
|
71
|
+
def __getattr__(self, name):
|
72
|
+
"""Delegate attribute access to the wrapped object."""
|
73
|
+
return getattr(self.__wrapped__, name)
|
74
|
+
|
75
|
+
async def __anext__(self):
|
76
|
+
try:
|
77
|
+
chunk = await self.__wrapped__.__anext__()
|
78
|
+
process_chunk(self, chunk)
|
79
|
+
return chunk
|
80
|
+
except StopAsyncIteration:
|
81
|
+
try:
|
82
|
+
with tracer.start_as_current_span(self._span_name, kind=SpanKind.CLIENT) as self._span:
|
83
|
+
process_streaming_chat_response(
|
84
|
+
self,
|
85
|
+
pricing_info=pricing_info,
|
86
|
+
environment=environment,
|
87
|
+
application_name=application_name,
|
88
|
+
metrics=metrics,
|
89
|
+
capture_message_content=capture_message_content,
|
90
|
+
disable_metrics=disable_metrics,
|
91
|
+
version=version
|
92
|
+
)
|
93
|
+
|
94
|
+
except Exception as e:
|
95
|
+
handle_exception(self._span, e)
|
96
|
+
|
97
|
+
raise
|
98
|
+
|
99
|
+
async def wrapper(wrapped, instance, args, kwargs):
|
100
|
+
"""
|
101
|
+
Wraps the GenAI function call.
|
102
|
+
"""
|
103
|
+
# Check if streaming is enabled for the API call
|
104
|
+
streaming = kwargs.get("stream", False)
|
105
|
+
server_address, server_port = set_server_address_and_port(instance, "NOT_FOUND", "NOT_FOUND")
|
106
|
+
request_model = kwargs.get("model", "openai/gpt-4o")
|
107
|
+
|
108
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
109
|
+
|
110
|
+
if streaming:
|
111
|
+
# Special handling for streaming response
|
112
|
+
awaited_wrapped = await wrapped(*args, **kwargs)
|
113
|
+
span = tracer.start_span(span_name, kind=SpanKind.CLIENT)
|
114
|
+
return TracedAsyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)
|
115
|
+
else:
|
116
|
+
# Handling for non-streaming responses
|
117
|
+
with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
|
118
|
+
start_time = time.time()
|
119
|
+
response = await wrapped(*args, **kwargs)
|
120
|
+
|
121
|
+
try:
|
122
|
+
response = process_chat_response(
|
123
|
+
response=response,
|
124
|
+
request_model=request_model,
|
125
|
+
pricing_info=pricing_info,
|
126
|
+
server_port=server_port,
|
127
|
+
server_address=server_address,
|
128
|
+
environment=environment,
|
129
|
+
application_name=application_name,
|
130
|
+
metrics=metrics,
|
131
|
+
start_time=start_time,
|
132
|
+
span=span,
|
133
|
+
capture_message_content=capture_message_content,
|
134
|
+
disable_metrics=disable_metrics,
|
135
|
+
version=version,
|
136
|
+
**kwargs
|
137
|
+
)
|
138
|
+
|
139
|
+
except Exception as e:
|
140
|
+
handle_exception(span, e)
|
141
|
+
|
142
|
+
return response
|
143
|
+
|
144
|
+
return wrapper
|
145
|
+
|
146
|
+
def aembedding(version, environment, application_name, tracer, pricing_info,
|
147
|
+
capture_message_content, metrics, disable_metrics):
|
148
|
+
"""
|
149
|
+
Generates a telemetry wrapper for GenAI embedding function call
|
150
|
+
"""
|
151
|
+
|
152
|
+
async def wrapper(wrapped, instance, args, kwargs):
|
153
|
+
"""
|
154
|
+
Wraps the GenAI embedding function call.
|
155
|
+
"""
|
156
|
+
server_address, server_port = set_server_address_and_port(instance, "NOT_FOUND", "NOT_FOUND")
|
157
|
+
request_model = kwargs.get("model", "text-embedding-ada-002")
|
158
|
+
|
159
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_EMBEDDING} {request_model}"
|
160
|
+
|
161
|
+
with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
|
162
|
+
start_time = time.time()
|
163
|
+
response = await wrapped(*args, **kwargs)
|
164
|
+
|
165
|
+
try:
|
166
|
+
response = process_embedding_response(
|
167
|
+
response=response,
|
168
|
+
request_model=request_model,
|
169
|
+
pricing_info=pricing_info,
|
170
|
+
server_port=server_port,
|
171
|
+
server_address=server_address,
|
172
|
+
environment=environment,
|
173
|
+
application_name=application_name,
|
174
|
+
metrics=metrics,
|
175
|
+
start_time=start_time,
|
176
|
+
span=span,
|
177
|
+
capture_message_content=capture_message_content,
|
178
|
+
disable_metrics=disable_metrics,
|
179
|
+
version=version,
|
180
|
+
**kwargs
|
181
|
+
)
|
182
|
+
|
183
|
+
except Exception as e:
|
184
|
+
handle_exception(span, e)
|
185
|
+
|
186
|
+
return response
|
187
|
+
|
188
|
+
return wrapper
|
@@ -0,0 +1,188 @@
|
|
1
|
+
"""
|
2
|
+
Module for monitoring LiteLLM API calls.
|
3
|
+
"""
|
4
|
+
|
5
|
+
import time
|
6
|
+
from opentelemetry.trace import SpanKind
|
7
|
+
from openlit.__helpers import (
|
8
|
+
handle_exception,
|
9
|
+
set_server_address_and_port
|
10
|
+
)
|
11
|
+
from openlit.instrumentation.litellm.utils import (
|
12
|
+
process_chunk,
|
13
|
+
process_streaming_chat_response,
|
14
|
+
process_chat_response,
|
15
|
+
process_embedding_response
|
16
|
+
)
|
17
|
+
from openlit.semcov import SemanticConvention
|
18
|
+
|
19
|
+
def completion(version, environment, application_name, tracer, pricing_info,
|
20
|
+
capture_message_content, metrics, disable_metrics):
|
21
|
+
"""
|
22
|
+
Generates a telemetry wrapper for GenAI function call
|
23
|
+
"""
|
24
|
+
|
25
|
+
class TracedSyncStream:
|
26
|
+
"""
|
27
|
+
Wrapper for streaming responses to collect telemetry.
|
28
|
+
"""
|
29
|
+
|
30
|
+
def __init__(
|
31
|
+
self,
|
32
|
+
wrapped,
|
33
|
+
span,
|
34
|
+
span_name,
|
35
|
+
kwargs,
|
36
|
+
server_address,
|
37
|
+
server_port,
|
38
|
+
**args,
|
39
|
+
):
|
40
|
+
self.__wrapped__ = wrapped
|
41
|
+
self._span = span
|
42
|
+
self._span_name = span_name
|
43
|
+
self._llmresponse = ""
|
44
|
+
self._response_id = ""
|
45
|
+
self._response_model = ""
|
46
|
+
self._finish_reason = ""
|
47
|
+
self._response_service_tier = ""
|
48
|
+
self._tools = None
|
49
|
+
self._input_tokens = 0
|
50
|
+
self._output_tokens = 0
|
51
|
+
self._args = args
|
52
|
+
self._kwargs = kwargs
|
53
|
+
self._start_time = time.time()
|
54
|
+
self._end_time = None
|
55
|
+
self._timestamps = []
|
56
|
+
self._ttft = 0
|
57
|
+
self._tbt = 0
|
58
|
+
self._server_address = server_address
|
59
|
+
self._server_port = server_port
|
60
|
+
|
61
|
+
def __enter__(self):
|
62
|
+
self.__wrapped__.__enter__()
|
63
|
+
return self
|
64
|
+
|
65
|
+
def __exit__(self, exc_type, exc_value, traceback):
|
66
|
+
self.__wrapped__.__exit__(exc_type, exc_value, traceback)
|
67
|
+
|
68
|
+
def __iter__(self):
|
69
|
+
return self
|
70
|
+
|
71
|
+
def __getattr__(self, name):
|
72
|
+
"""Delegate attribute access to the wrapped object."""
|
73
|
+
return getattr(self.__wrapped__, name)
|
74
|
+
|
75
|
+
def __next__(self):
|
76
|
+
try:
|
77
|
+
chunk = self.__wrapped__.__next__()
|
78
|
+
process_chunk(self, chunk)
|
79
|
+
return chunk
|
80
|
+
except StopIteration:
|
81
|
+
try:
|
82
|
+
with tracer.start_as_current_span(self._span_name, kind=SpanKind.CLIENT) as self._span:
|
83
|
+
process_streaming_chat_response(
|
84
|
+
self,
|
85
|
+
pricing_info=pricing_info,
|
86
|
+
environment=environment,
|
87
|
+
application_name=application_name,
|
88
|
+
metrics=metrics,
|
89
|
+
capture_message_content=capture_message_content,
|
90
|
+
disable_metrics=disable_metrics,
|
91
|
+
version=version
|
92
|
+
)
|
93
|
+
|
94
|
+
except Exception as e:
|
95
|
+
handle_exception(self._span, e)
|
96
|
+
|
97
|
+
raise
|
98
|
+
|
99
|
+
def wrapper(wrapped, instance, args, kwargs):
|
100
|
+
"""
|
101
|
+
Wraps the GenAI function call.
|
102
|
+
"""
|
103
|
+
# Check if streaming is enabled for the API call
|
104
|
+
streaming = kwargs.get("stream", False)
|
105
|
+
server_address, server_port = set_server_address_and_port(instance, "NOT_FOUND", "NOT_FOUND")
|
106
|
+
request_model = kwargs.get("model", "openai/gpt-4o")
|
107
|
+
|
108
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
109
|
+
|
110
|
+
if streaming:
|
111
|
+
# Special handling for streaming response
|
112
|
+
awaited_wrapped = wrapped(*args, **kwargs)
|
113
|
+
span = tracer.start_span(span_name, kind=SpanKind.CLIENT)
|
114
|
+
return TracedSyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)
|
115
|
+
else:
|
116
|
+
# Handling for non-streaming responses
|
117
|
+
with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
|
118
|
+
start_time = time.time()
|
119
|
+
response = wrapped(*args, **kwargs)
|
120
|
+
|
121
|
+
try:
|
122
|
+
response = process_chat_response(
|
123
|
+
response=response,
|
124
|
+
request_model=request_model,
|
125
|
+
pricing_info=pricing_info,
|
126
|
+
server_port=server_port,
|
127
|
+
server_address=server_address,
|
128
|
+
environment=environment,
|
129
|
+
application_name=application_name,
|
130
|
+
metrics=metrics,
|
131
|
+
start_time=start_time,
|
132
|
+
span=span,
|
133
|
+
capture_message_content=capture_message_content,
|
134
|
+
disable_metrics=disable_metrics,
|
135
|
+
version=version,
|
136
|
+
**kwargs
|
137
|
+
)
|
138
|
+
|
139
|
+
except Exception as e:
|
140
|
+
handle_exception(span, e)
|
141
|
+
|
142
|
+
return response
|
143
|
+
|
144
|
+
return wrapper
|
145
|
+
|
146
|
+
def embedding(version, environment, application_name, tracer, pricing_info,
|
147
|
+
capture_message_content, metrics, disable_metrics):
|
148
|
+
"""
|
149
|
+
Generates a telemetry wrapper for GenAI embedding function call
|
150
|
+
"""
|
151
|
+
|
152
|
+
def wrapper(wrapped, instance, args, kwargs):
|
153
|
+
"""
|
154
|
+
Wraps the GenAI embedding function call.
|
155
|
+
"""
|
156
|
+
server_address, server_port = set_server_address_and_port(instance, "NOT_FOUND", "NOT_FOUND")
|
157
|
+
request_model = kwargs.get("model", "text-embedding-ada-002")
|
158
|
+
|
159
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_EMBEDDING} {request_model}"
|
160
|
+
|
161
|
+
with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
|
162
|
+
start_time = time.time()
|
163
|
+
response = wrapped(*args, **kwargs)
|
164
|
+
|
165
|
+
try:
|
166
|
+
response = process_embedding_response(
|
167
|
+
response=response,
|
168
|
+
request_model=request_model,
|
169
|
+
pricing_info=pricing_info,
|
170
|
+
server_port=server_port,
|
171
|
+
server_address=server_address,
|
172
|
+
environment=environment,
|
173
|
+
application_name=application_name,
|
174
|
+
metrics=metrics,
|
175
|
+
start_time=start_time,
|
176
|
+
span=span,
|
177
|
+
capture_message_content=capture_message_content,
|
178
|
+
disable_metrics=disable_metrics,
|
179
|
+
version=version,
|
180
|
+
**kwargs
|
181
|
+
)
|
182
|
+
|
183
|
+
except Exception as e:
|
184
|
+
handle_exception(span, e)
|
185
|
+
|
186
|
+
return response
|
187
|
+
|
188
|
+
return wrapper
|