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.
Files changed (147) hide show
  1. {openlit-1.34.14 → openlit-1.34.15}/PKG-INFO +1 -1
  2. {openlit-1.34.14 → openlit-1.34.15}/pyproject.toml +1 -1
  3. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/litellm/__init__.py +7 -6
  4. openlit-1.34.15/src/openlit/instrumentation/litellm/async_litellm.py +188 -0
  5. openlit-1.34.15/src/openlit/instrumentation/litellm/litellm.py +188 -0
  6. openlit-1.34.15/src/openlit/instrumentation/litellm/utils.py +288 -0
  7. openlit-1.34.14/src/openlit/instrumentation/litellm/async_litellm.py +0 -592
  8. openlit-1.34.14/src/openlit/instrumentation/litellm/litellm.py +0 -592
  9. {openlit-1.34.14 → openlit-1.34.15}/LICENSE +0 -0
  10. {openlit-1.34.14 → openlit-1.34.15}/README.md +0 -0
  11. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/__helpers.py +0 -0
  12. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/__init__.py +0 -0
  13. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/evals/__init__.py +0 -0
  14. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/evals/all.py +0 -0
  15. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/evals/bias_detection.py +0 -0
  16. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/evals/hallucination.py +0 -0
  17. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/evals/toxicity.py +0 -0
  18. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/evals/utils.py +0 -0
  19. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/guard/__init__.py +0 -0
  20. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/guard/all.py +0 -0
  21. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/guard/prompt_injection.py +0 -0
  22. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/guard/restrict_topic.py +0 -0
  23. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/guard/sensitive_topic.py +0 -0
  24. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/guard/utils.py +0 -0
  25. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ag2/__init__.py +0 -0
  26. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ag2/ag2.py +0 -0
  27. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ai21/__init__.py +0 -0
  28. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ai21/ai21.py +0 -0
  29. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ai21/async_ai21.py +0 -0
  30. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ai21/utils.py +0 -0
  31. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/anthropic/__init__.py +0 -0
  32. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/anthropic/anthropic.py +0 -0
  33. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/anthropic/async_anthropic.py +0 -0
  34. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/anthropic/utils.py +0 -0
  35. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/assemblyai/__init__.py +0 -0
  36. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/assemblyai/assemblyai.py +0 -0
  37. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/assemblyai/utils.py +0 -0
  38. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/astra/__init__.py +0 -0
  39. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/astra/astra.py +0 -0
  40. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/astra/async_astra.py +0 -0
  41. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/astra/utils.py +0 -0
  42. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/azure_ai_inference/__init__.py +0 -0
  43. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +0 -0
  44. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +0 -0
  45. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/azure_ai_inference/utils.py +0 -0
  46. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/bedrock/__init__.py +0 -0
  47. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/bedrock/bedrock.py +0 -0
  48. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/bedrock/utils.py +0 -0
  49. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/chroma/__init__.py +0 -0
  50. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/chroma/chroma.py +0 -0
  51. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/cohere/__init__.py +0 -0
  52. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/cohere/async_cohere.py +0 -0
  53. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/cohere/cohere.py +0 -0
  54. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/controlflow/__init__.py +0 -0
  55. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/controlflow/controlflow.py +0 -0
  56. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/crawl4ai/__init__.py +0 -0
  57. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/crawl4ai/async_crawl4ai.py +0 -0
  58. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/crawl4ai/crawl4ai.py +0 -0
  59. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/crewai/__init__.py +0 -0
  60. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/crewai/crewai.py +0 -0
  61. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/dynamiq/__init__.py +0 -0
  62. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/dynamiq/dynamiq.py +0 -0
  63. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/elevenlabs/__init__.py +0 -0
  64. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/elevenlabs/async_elevenlabs.py +0 -0
  65. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/elevenlabs/elevenlabs.py +0 -0
  66. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/elevenlabs/utils.py +0 -0
  67. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/embedchain/__init__.py +0 -0
  68. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/embedchain/embedchain.py +0 -0
  69. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/firecrawl/__init__.py +0 -0
  70. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/firecrawl/firecrawl.py +0 -0
  71. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/google_ai_studio/__init__.py +0 -0
  72. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +0 -0
  73. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/google_ai_studio/google_ai_studio.py +0 -0
  74. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/google_ai_studio/utils.py +0 -0
  75. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/gpt4all/__init__.py +0 -0
  76. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/gpt4all/gpt4all.py +0 -0
  77. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/gpt4all/utils.py +0 -0
  78. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/gpu/__init__.py +0 -0
  79. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/groq/__init__.py +0 -0
  80. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/groq/async_groq.py +0 -0
  81. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/groq/groq.py +0 -0
  82. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/groq/utils.py +0 -0
  83. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/haystack/__init__.py +0 -0
  84. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/haystack/haystack.py +0 -0
  85. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/julep/__init__.py +0 -0
  86. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/julep/async_julep.py +0 -0
  87. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/julep/julep.py +0 -0
  88. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/langchain/__init__.py +0 -0
  89. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/langchain/async_langchain.py +0 -0
  90. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/langchain/langchain.py +0 -0
  91. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/letta/__init__.py +0 -0
  92. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/letta/letta.py +0 -0
  93. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/llamaindex/__init__.py +0 -0
  94. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/llamaindex/llamaindex.py +0 -0
  95. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/mem0/__init__.py +0 -0
  96. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/mem0/mem0.py +0 -0
  97. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/milvus/__init__.py +0 -0
  98. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/milvus/milvus.py +0 -0
  99. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/mistral/__init__.py +0 -0
  100. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/mistral/async_mistral.py +0 -0
  101. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/mistral/mistral.py +0 -0
  102. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/multion/__init__.py +0 -0
  103. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/multion/async_multion.py +0 -0
  104. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/multion/multion.py +0 -0
  105. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ollama/__init__.py +0 -0
  106. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ollama/async_ollama.py +0 -0
  107. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ollama/ollama.py +0 -0
  108. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/ollama/utils.py +0 -0
  109. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/openai/__init__.py +0 -0
  110. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/openai/async_openai.py +0 -0
  111. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/openai/openai.py +0 -0
  112. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/openai_agents/__init__.py +0 -0
  113. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/openai_agents/openai_agents.py +0 -0
  114. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/phidata/__init__.py +0 -0
  115. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/phidata/phidata.py +0 -0
  116. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/pinecone/__init__.py +0 -0
  117. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/pinecone/pinecone.py +0 -0
  118. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/premai/__init__.py +0 -0
  119. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/premai/premai.py +0 -0
  120. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/premai/utils.py +0 -0
  121. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/pydantic_ai/__init__.py +0 -0
  122. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/pydantic_ai/pydantic_ai.py +0 -0
  123. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/pydantic_ai/utils.py +0 -0
  124. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/qdrant/__init__.py +0 -0
  125. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/qdrant/async_qdrant.py +0 -0
  126. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/qdrant/qdrant.py +0 -0
  127. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/reka/__init__.py +0 -0
  128. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/reka/async_reka.py +0 -0
  129. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/reka/reka.py +0 -0
  130. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/reka/utils.py +0 -0
  131. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/together/__init__.py +0 -0
  132. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/together/async_together.py +0 -0
  133. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/together/together.py +0 -0
  134. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/together/utils.py +0 -0
  135. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/transformers/__init__.py +0 -0
  136. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/transformers/transformers.py +0 -0
  137. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/transformers/utils.py +0 -0
  138. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/vertexai/__init__.py +0 -0
  139. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/vertexai/async_vertexai.py +0 -0
  140. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/vertexai/vertexai.py +0 -0
  141. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/vllm/__init__.py +0 -0
  142. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/vllm/utils.py +0 -0
  143. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/instrumentation/vllm/vllm.py +0 -0
  144. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/otel/events.py +0 -0
  145. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/otel/metrics.py +0 -0
  146. {openlit-1.34.14 → openlit-1.34.15}/src/openlit/otel/tracing.py +0 -0
  147. {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.14
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.14"
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's client library.
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", "default_application")
28
- environment = kwargs.get("environment", "default_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
- # completion
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