openlit 1.32.4__tar.gz → 1.32.7__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 (112) hide show
  1. {openlit-1.32.4 → openlit-1.32.7}/PKG-INFO +3 -2
  2. {openlit-1.32.4 → openlit-1.32.7}/README.md +2 -1
  3. {openlit-1.32.4 → openlit-1.32.7}/pyproject.toml +1 -1
  4. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/__helpers.py +5 -2
  5. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/__init__.py +6 -0
  6. openlit-1.32.7/src/openlit/instrumentation/assemblyai/__init__.py +43 -0
  7. openlit-1.32.7/src/openlit/instrumentation/assemblyai/assemblyai.py +127 -0
  8. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/bedrock/bedrock.py +2 -6
  9. openlit-1.32.7/src/openlit/instrumentation/controlflow/__init__.py +56 -0
  10. openlit-1.32.7/src/openlit/instrumentation/controlflow/controlflow.py +113 -0
  11. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/openai/openai.py +9 -6
  12. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/semcov/__init__.py +3 -0
  13. {openlit-1.32.4 → openlit-1.32.7}/LICENSE +0 -0
  14. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/evals/__init__.py +0 -0
  15. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/evals/all.py +0 -0
  16. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/evals/bias_detection.py +0 -0
  17. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/evals/hallucination.py +0 -0
  18. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/evals/toxicity.py +0 -0
  19. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/evals/utils.py +0 -0
  20. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/guard/__init__.py +0 -0
  21. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/guard/all.py +0 -0
  22. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/guard/prompt_injection.py +0 -0
  23. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/guard/restrict_topic.py +0 -0
  24. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/guard/sensitive_topic.py +0 -0
  25. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/guard/utils.py +0 -0
  26. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/ag2/__init__.py +0 -0
  27. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/ag2/ag2.py +0 -0
  28. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/ai21/__init__.py +0 -0
  29. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/ai21/ai21.py +0 -0
  30. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/ai21/async_ai21.py +0 -0
  31. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/anthropic/__init__.py +0 -0
  32. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/anthropic/anthropic.py +0 -0
  33. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/anthropic/async_anthropic.py +0 -0
  34. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/astra/__init__.py +0 -0
  35. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/astra/astra.py +0 -0
  36. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/astra/async_astra.py +0 -0
  37. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/azure_ai_inference/__init__.py +0 -0
  38. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +0 -0
  39. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +0 -0
  40. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/bedrock/__init__.py +0 -0
  41. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/chroma/__init__.py +0 -0
  42. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/chroma/chroma.py +0 -0
  43. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/cohere/__init__.py +0 -0
  44. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/cohere/cohere.py +0 -0
  45. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/crewai/__init__.py +0 -0
  46. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/crewai/crewai.py +0 -0
  47. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/dynamiq/__init__.py +0 -0
  48. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/dynamiq/dynamiq.py +0 -0
  49. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/elevenlabs/__init__.py +0 -0
  50. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/elevenlabs/async_elevenlabs.py +0 -0
  51. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/elevenlabs/elevenlabs.py +0 -0
  52. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/embedchain/__init__.py +0 -0
  53. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/embedchain/embedchain.py +0 -0
  54. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/google_ai_studio/__init__.py +0 -0
  55. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +0 -0
  56. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/google_ai_studio/google_ai_studio.py +0 -0
  57. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/gpt4all/__init__.py +0 -0
  58. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/gpt4all/gpt4all.py +0 -0
  59. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/gpu/__init__.py +0 -0
  60. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/groq/__init__.py +0 -0
  61. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/groq/async_groq.py +0 -0
  62. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/groq/groq.py +0 -0
  63. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/haystack/__init__.py +0 -0
  64. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/haystack/haystack.py +0 -0
  65. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/julep/__init__.py +0 -0
  66. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/julep/async_julep.py +0 -0
  67. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/julep/julep.py +0 -0
  68. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/langchain/__init__.py +0 -0
  69. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/langchain/langchain.py +0 -0
  70. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/litellm/__init__.py +0 -0
  71. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/litellm/async_litellm.py +0 -0
  72. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/litellm/litellm.py +0 -0
  73. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/llamaindex/__init__.py +0 -0
  74. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/llamaindex/llamaindex.py +0 -0
  75. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/mem0/__init__.py +0 -0
  76. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/mem0/mem0.py +0 -0
  77. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/milvus/__init__.py +0 -0
  78. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/milvus/milvus.py +0 -0
  79. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/mistral/__init__.py +0 -0
  80. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/mistral/async_mistral.py +0 -0
  81. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/mistral/mistral.py +0 -0
  82. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/multion/__init__.py +0 -0
  83. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/multion/async_multion.py +0 -0
  84. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/multion/multion.py +0 -0
  85. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/ollama/__init__.py +0 -0
  86. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/ollama/async_ollama.py +0 -0
  87. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/ollama/ollama.py +0 -0
  88. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/openai/__init__.py +0 -0
  89. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/openai/async_azure_openai.py +0 -0
  90. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/openai/async_openai.py +0 -0
  91. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/openai/azure_openai.py +0 -0
  92. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/phidata/__init__.py +0 -0
  93. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/phidata/phidata.py +0 -0
  94. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/pinecone/__init__.py +0 -0
  95. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/pinecone/pinecone.py +0 -0
  96. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/premai/__init__.py +0 -0
  97. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/premai/premai.py +0 -0
  98. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/qdrant/__init__.py +0 -0
  99. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/qdrant/async_qdrant.py +0 -0
  100. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/qdrant/qdrant.py +0 -0
  101. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/reka/__init__.py +0 -0
  102. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/reka/async_reka.py +0 -0
  103. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/reka/reka.py +0 -0
  104. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/transformers/__init__.py +0 -0
  105. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/transformers/transformers.py +0 -0
  106. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/vertexai/__init__.py +0 -0
  107. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/vertexai/async_vertexai.py +0 -0
  108. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/vertexai/vertexai.py +0 -0
  109. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/vllm/__init__.py +0 -0
  110. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/instrumentation/vllm/vllm.py +0 -0
  111. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/otel/metrics.py +0 -0
  112. {openlit-1.32.4 → openlit-1.32.7}/src/openlit/otel/tracing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: openlit
3
- Version: 1.32.4
3
+ Version: 1.32.7
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
  Home-page: https://github.com/openlit/openlit/tree/main/openlit/python
6
6
  Keywords: OpenTelemetry,otel,otlp,llm,tracing,openai,anthropic,claude,cohere,llm monitoring,observability,monitoring,gpt,Generative AI,chatGPT,gpu
@@ -79,7 +79,7 @@ This project proudly follows and maintains the [Semantic Conventions](https://gi
79
79
  | [✅ AI21](https://docs.openlit.io/latest/integrations/ai21) | | [✅ mem0](https://docs.openlit.io/latest/integrations/mem0) | |
80
80
  | [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai) | | [✅ MultiOn](https://docs.openlit.io/latest/integrations/multion) | |
81
81
  | [✅ Groq](https://docs.openlit.io/latest/integrations/groq) | | [✅ Julep AI](https://docs.openlit.io/latest/integrations/julep-ai) | |
82
- | [✅ ElevenLabs](https://docs.openlit.io/latest/integrations/elevenlabs) | | | |
82
+ | [✅ ElevenLabs](https://docs.openlit.io/latest/integrations/elevenlabs) | | [✅ ControlFlow](https://docs.openlit.io/latest/integrations/controlflow) | |
83
83
  | [✅ vLLM](https://docs.openlit.io/latest/integrations/vllm) | | | |
84
84
  | [✅ OLA Krutrim](https://docs.openlit.io/latest/integrations/krutrim) | | | |
85
85
  | [✅ Google AI Studio](https://docs.openlit.io/latest/integrations/google-ai-studio) | | | |
@@ -88,6 +88,7 @@ This project proudly follows and maintains the [Semantic Conventions](https://gi
88
88
  | [✅ Reka AI](https://docs.openlit.io/latest/integrations/reka) | | | |
89
89
  | [✅ xAI](https://docs.openlit.io/latest/integrations/xai) | | | |
90
90
  | [✅ Prem AI](https://docs.openlit.io/latest/integrations/premai) | | | |
91
+ | [✅ Assembly AI](https://docs.openlit.io/latest/integrations/assemblyai) | | | |
91
92
 
92
93
  ## Supported Destinations
93
94
  - [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
@@ -48,7 +48,7 @@ This project proudly follows and maintains the [Semantic Conventions](https://gi
48
48
  | [✅ AI21](https://docs.openlit.io/latest/integrations/ai21) | | [✅ mem0](https://docs.openlit.io/latest/integrations/mem0) | |
49
49
  | [✅ Vertex AI](https://docs.openlit.io/latest/integrations/vertexai) | | [✅ MultiOn](https://docs.openlit.io/latest/integrations/multion) | |
50
50
  | [✅ Groq](https://docs.openlit.io/latest/integrations/groq) | | [✅ Julep AI](https://docs.openlit.io/latest/integrations/julep-ai) | |
51
- | [✅ ElevenLabs](https://docs.openlit.io/latest/integrations/elevenlabs) | | | |
51
+ | [✅ ElevenLabs](https://docs.openlit.io/latest/integrations/elevenlabs) | | [✅ ControlFlow](https://docs.openlit.io/latest/integrations/controlflow) | |
52
52
  | [✅ vLLM](https://docs.openlit.io/latest/integrations/vllm) | | | |
53
53
  | [✅ OLA Krutrim](https://docs.openlit.io/latest/integrations/krutrim) | | | |
54
54
  | [✅ Google AI Studio](https://docs.openlit.io/latest/integrations/google-ai-studio) | | | |
@@ -57,6 +57,7 @@ This project proudly follows and maintains the [Semantic Conventions](https://gi
57
57
  | [✅ Reka AI](https://docs.openlit.io/latest/integrations/reka) | | | |
58
58
  | [✅ xAI](https://docs.openlit.io/latest/integrations/xai) | | | |
59
59
  | [✅ Prem AI](https://docs.openlit.io/latest/integrations/premai) | | | |
60
+ | [✅ Assembly AI](https://docs.openlit.io/latest/integrations/assemblyai) | | | |
60
61
 
61
62
  ## Supported Destinations
62
63
  - [✅ OpenTelemetry Collector](https://docs.openlit.io/latest/connections/otelcol)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "openlit"
3
- version = "1.32.4"
3
+ version = "1.32.7"
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
  repository = "https://github.com/openlit/openlit/tree/main/openlit/python"
@@ -133,7 +133,7 @@ def get_image_model_cost(model, pricing_info, size, quality):
133
133
  cost = 0
134
134
  return cost
135
135
 
136
- def get_audio_model_cost(model, pricing_info, prompt):
136
+ def get_audio_model_cost(model, pricing_info, prompt, duration=None):
137
137
  """
138
138
  Retrieve the cost of processing for a given model based on prompt.
139
139
 
@@ -146,7 +146,10 @@ def get_audio_model_cost(model, pricing_info, prompt):
146
146
  float: The calculated cost for the operation.
147
147
  """
148
148
  try:
149
- cost = (len(prompt) / 1000) * pricing_info["audio"][model]
149
+ if prompt:
150
+ cost = (len(prompt) / 1000) * pricing_info["audio"][model]
151
+ else:
152
+ cost = duration * pricing_info["audio"][model]
150
153
  except:
151
154
  cost = 0
152
155
  return cost
@@ -38,6 +38,7 @@ from openlit.instrumentation.vllm import VLLMInstrumentor
38
38
  from openlit.instrumentation.google_ai_studio import GoogleAIStudioInstrumentor
39
39
  from openlit.instrumentation.reka import RekaInstrumentor
40
40
  from openlit.instrumentation.premai import PremAIInstrumentor
41
+ from openlit.instrumentation.assemblyai import AssemblyAIInstrumentor
41
42
  from openlit.instrumentation.azure_ai_inference import AzureAIInferenceInstrumentor
42
43
  from openlit.instrumentation.langchain import LangChainInstrumentor
43
44
  from openlit.instrumentation.llamaindex import LlamaIndexInstrumentor
@@ -58,6 +59,7 @@ from openlit.instrumentation.dynamiq import DynamiqInstrumentor
58
59
  from openlit.instrumentation.phidata import PhidataInstrumentor
59
60
  from openlit.instrumentation.julep import JulepInstrumentor
60
61
  from openlit.instrumentation.ai21 import AI21Instrumentor
62
+ from openlit.instrumentation.controlflow import ControlFlowInstrumentor
61
63
  from openlit.instrumentation.gpu import GPUInstrumentor
62
64
  import openlit.guard
63
65
  import openlit.evals
@@ -254,6 +256,8 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
254
256
  "julep": "julep",
255
257
  "astra": "astrapy",
256
258
  "ai21": "ai21",
259
+ "controlflow": "controlflow",
260
+ "assemblyai": "assemblyai",
257
261
  }
258
262
 
259
263
  invalid_instrumentors = [
@@ -345,6 +349,8 @@ def init(environment="default", application_name="default", tracer=None, otlp_en
345
349
  "julep": JulepInstrumentor(),
346
350
  "astra": AstraInstrumentor(),
347
351
  "ai21": AI21Instrumentor(),
352
+ "controlflow": ControlFlowInstrumentor(),
353
+ "assemblyai": AssemblyAIInstrumentor(),
348
354
  }
349
355
 
350
356
  # Initialize and instrument only the enabled instrumentors
@@ -0,0 +1,43 @@
1
+ # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
+ """Initializer of Auto Instrumentation of AssemblyAI Functions"""
3
+
4
+ from typing import Collection
5
+ import importlib.metadata
6
+ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
7
+ from wrapt import wrap_function_wrapper
8
+
9
+ from openlit.instrumentation.assemblyai.assemblyai import (
10
+ transcribe
11
+ )
12
+
13
+ _instruments = ("assemblyai >= 0.35.1",)
14
+
15
+ class AssemblyAIInstrumentor(BaseInstrumentor):
16
+ """
17
+ An instrumentor for AssemblyAI's client library.
18
+ """
19
+
20
+ def instrumentation_dependencies(self) -> Collection[str]:
21
+ return _instruments
22
+
23
+ def _instrument(self, **kwargs):
24
+ application_name = kwargs.get("application_name", "default")
25
+ environment = kwargs.get("environment", "default")
26
+ tracer = kwargs.get("tracer")
27
+ metrics = kwargs.get("metrics_dict")
28
+ pricing_info = kwargs.get("pricing_info", {})
29
+ trace_content = kwargs.get("trace_content", False)
30
+ disable_metrics = kwargs.get("disable_metrics")
31
+ version = importlib.metadata.version("assemblyai")
32
+
33
+ # sync transcribe
34
+ wrap_function_wrapper(
35
+ "assemblyai.transcriber",
36
+ "Transcriber.transcribe",
37
+ transcribe("assemblyai.transcribe", version, environment, application_name,
38
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
39
+ )
40
+
41
+ def _uninstrument(self, **kwargs):
42
+ # Proper uninstrumentation logic to revert patched methods
43
+ pass
@@ -0,0 +1,127 @@
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, possibly-used-before-assignment
2
+ """
3
+ Module for monitoring Assembly AI API calls.
4
+ """
5
+
6
+ import logging
7
+ from opentelemetry.trace import SpanKind, Status, StatusCode
8
+ from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
9
+ from openlit.__helpers import get_audio_model_cost
10
+ from openlit.__helpers import handle_exception
11
+ from openlit.semcov import SemanticConvetion
12
+
13
+ # Initialize logger for logging potential issues and operations
14
+ logger = logging.getLogger(__name__)
15
+
16
+ def transcribe(gen_ai_endpoint, version, environment, application_name,
17
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
18
+ """
19
+ Generates a telemetry wrapper for creating speech audio to collect metrics.
20
+
21
+ Args:
22
+ gen_ai_endpoint: Endpoint identifier for logging and tracing.
23
+ version: Version of the monitoring package.
24
+ environment: Deployment environment (e.g., production, staging).
25
+ application_name: Name of the application using the Assembly AI API.
26
+ tracer: OpenTelemetry tracer for creating spans.
27
+ pricing_info: Information used for calculating the cost of generating speech audio.
28
+ trace_content: Flag indicating whether to trace the input text and generated audio.
29
+
30
+ Returns:
31
+ A function that wraps the speech audio creation method to add telemetry.
32
+ """
33
+
34
+ def wrapper(wrapped, instance, args, kwargs):
35
+ """
36
+ Wraps the 'generate' API call to add telemetry.
37
+
38
+ This collects metrics such as execution time, cost, and handles errors
39
+ gracefully, adding details to the trace for observability.
40
+
41
+ Args:
42
+ wrapped: The original 'generate' method to be wrapped.
43
+ instance: The instance of the class where the original method is defined.
44
+ args: Positional arguments for the 'generate' method.
45
+ kwargs: Keyword arguments for the 'generate' method.
46
+
47
+ Returns:
48
+ The response from the original 'transcribe' method.
49
+ """
50
+
51
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
52
+ response = wrapped(*args, **kwargs)
53
+
54
+ try:
55
+ llm_model = response.speech_model if response.speech_model else "best"
56
+
57
+ # Calculate cost of the operation
58
+ cost = get_audio_model_cost(llm_model,
59
+ pricing_info, None, response.audio_duration)
60
+
61
+ # Set Span attributes
62
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
63
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
64
+ SemanticConvetion.GEN_AI_SYSTEM_ASSEMBLYAI)
65
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
66
+ SemanticConvetion.GEN_AI_TYPE_AUDIO)
67
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
68
+ gen_ai_endpoint)
69
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
70
+ environment)
71
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
72
+ application_name)
73
+ span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
74
+ response.id)
75
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
76
+ llm_model)
77
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_AUDIO_DURATION,
78
+ response.audio_duration)
79
+ span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
80
+ cost)
81
+
82
+ if trace_content:
83
+ span.add_event(
84
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
85
+ attributes={
86
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: response.audio_url,
87
+ },
88
+ )
89
+ span.add_event(
90
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
91
+ attributes={
92
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.text,
93
+ },
94
+ )
95
+
96
+ span.set_status(Status(StatusCode.OK))
97
+
98
+ if disable_metrics is False:
99
+ attributes = {
100
+ TELEMETRY_SDK_NAME:
101
+ "openlit",
102
+ SemanticConvetion.GEN_AI_APPLICATION_NAME:
103
+ application_name,
104
+ SemanticConvetion.GEN_AI_SYSTEM:
105
+ SemanticConvetion.GEN_AI_SYSTEM_ASSEMBLYAI,
106
+ SemanticConvetion.GEN_AI_ENVIRONMENT:
107
+ environment,
108
+ SemanticConvetion.GEN_AI_TYPE:
109
+ SemanticConvetion.GEN_AI_TYPE_AUDIO,
110
+ SemanticConvetion.GEN_AI_REQUEST_MODEL:
111
+ llm_model,
112
+ }
113
+
114
+ metrics["genai_requests"].add(1, attributes)
115
+ metrics["genai_cost"].record(cost, attributes)
116
+
117
+ # Return original response
118
+ return response
119
+
120
+ except Exception as e:
121
+ handle_exception(span, e)
122
+ logger.error("Error in trace creation: %s", e)
123
+
124
+ # Return original response
125
+ return response
126
+
127
+ return wrapper
@@ -102,12 +102,8 @@ def converse(gen_ai_endpoint, version, environment, application_name, tracer,
102
102
  content = message["content"]
103
103
 
104
104
  if isinstance(content, list):
105
- content_str = ", ".join(
106
- # pylint: disable=line-too-long
107
- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'
108
- if "type" in item else f'text: {item["text"]}'
109
- for item in content
110
- )
105
+ # pylint: disable=line-too-long
106
+ content_str = ", ".join(f'text: {item["text"]}' for item in content if "text" in item)
111
107
  formatted_messages.append(f"{role}: {content_str}")
112
108
  else:
113
109
  formatted_messages.append(f"{role}: {content}")
@@ -0,0 +1,56 @@
1
+ # pylint: disable=useless-return, bad-staticmethod-argument, disable=duplicate-code
2
+ """Initializer of Auto Instrumentation of controlflow Functions"""
3
+
4
+ from typing import Collection
5
+ import importlib.metadata
6
+ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
7
+ from wrapt import wrap_function_wrapper
8
+
9
+ from openlit.instrumentation.controlflow.controlflow import (
10
+ wrap_controlflow
11
+ )
12
+
13
+ _instruments = ("controlflow >= 0.3.2",)
14
+
15
+ class ControlFlowInstrumentor(BaseInstrumentor):
16
+ """
17
+ An instrumentor for controlflow's client library.
18
+ """
19
+
20
+ def instrumentation_dependencies(self) -> Collection[str]:
21
+ return _instruments
22
+
23
+ def _instrument(self, **kwargs):
24
+ application_name = kwargs.get("application_name", "default_application")
25
+ environment = kwargs.get("environment", "default_environment")
26
+ tracer = kwargs.get("tracer")
27
+ metrics = kwargs.get("metrics_dict")
28
+ pricing_info = kwargs.get("pricing_info", {})
29
+ trace_content = kwargs.get("trace_content", False)
30
+ disable_metrics = kwargs.get("disable_metrics")
31
+ version = importlib.metadata.version("controlflow")
32
+
33
+ wrap_function_wrapper(
34
+ "controlflow.agents.agent",
35
+ "Agent.__init__",
36
+ wrap_controlflow("controlflow.create_agent", version, environment, application_name,
37
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
38
+ )
39
+
40
+ wrap_function_wrapper(
41
+ "controlflow.tasks.task",
42
+ "Task.__init__",
43
+ wrap_controlflow("controlflow.create_task", version, environment, application_name,
44
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
45
+ )
46
+
47
+ wrap_function_wrapper(
48
+ "controlflow",
49
+ "run",
50
+ wrap_controlflow("controlflow.run", version, environment, application_name,
51
+ tracer, pricing_info, trace_content, metrics, disable_metrics),
52
+ )
53
+
54
+ def _uninstrument(self, **kwargs):
55
+ # Proper uninstrumentation logic to revert patched methods
56
+ pass
@@ -0,0 +1,113 @@
1
+ # pylint: disable=duplicate-code, broad-exception-caught, too-many-statements, unused-argument, bare-except
2
+ """
3
+ Module for monitoring controlflow.
4
+ """
5
+
6
+ import logging
7
+ from opentelemetry.trace import SpanKind, Status, StatusCode
8
+ from opentelemetry.sdk.resources import TELEMETRY_SDK_NAME
9
+ from openlit.__helpers import handle_exception
10
+ from openlit.semcov import SemanticConvetion
11
+
12
+ # Initialize logger for logging potential issues and operations
13
+ logger = logging.getLogger(__name__)
14
+
15
+ def wrap_controlflow(gen_ai_endpoint, version, environment, application_name,
16
+ tracer, pricing_info, trace_content, metrics, disable_metrics):
17
+ """
18
+ Creates a wrapper around a function call to trace and log its execution metrics.
19
+
20
+ This function wraps any given function to measure its execution time,
21
+ log its operation, and trace its execution using OpenTelemetry.
22
+
23
+ Parameters:
24
+ - gen_ai_endpoint (str): A descriptor or name for the endpoint being traced.
25
+ - version (str): The version of the Langchain application.
26
+ - environment (str): The deployment environment (e.g., 'production', 'development').
27
+ - application_name (str): Name of the Langchain application.
28
+ - tracer (opentelemetry.trace.Tracer): The tracer object used for OpenTelemetry tracing.
29
+ - pricing_info (dict): Information about the pricing for internal metrics (currently not used).
30
+ - trace_content (bool): Flag indicating whether to trace the content of the response.
31
+
32
+ Returns:
33
+ - function: A higher-order function that takes a function 'wrapped' and returns
34
+ a new function that wraps 'wrapped' with additional tracing and logging.
35
+ """
36
+
37
+ def wrapper(wrapped, instance, args, kwargs):
38
+ """
39
+ An inner wrapper function that executes the wrapped function, measures execution
40
+ time, and records trace data using OpenTelemetry.
41
+
42
+ Parameters:
43
+ - wrapped (Callable): The original function that this wrapper will execute.
44
+ - instance (object): The instance to which the wrapped function belongs. This
45
+ is used for instance methods. For static and classmethods,
46
+ this may be None.
47
+ - args (tuple): Positional arguments passed to the wrapped function.
48
+ - kwargs (dict): Keyword arguments passed to the wrapped function.
49
+
50
+ Returns:
51
+ - The result of the wrapped function call.
52
+
53
+ The wrapper initiates a span with the provided tracer, sets various attributes
54
+ on the span based on the function's execution and response, and ensures
55
+ errors are handled and logged appropriately.
56
+ """
57
+
58
+ with tracer.start_as_current_span(gen_ai_endpoint, kind= SpanKind.CLIENT) as span:
59
+ response = wrapped(*args, **kwargs)
60
+
61
+ try:
62
+ span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
63
+ span.set_attribute(SemanticConvetion.GEN_AI_ENDPOINT,
64
+ gen_ai_endpoint)
65
+ span.set_attribute(SemanticConvetion.GEN_AI_SYSTEM,
66
+ SemanticConvetion.GEN_AI_SYSTEM_CONTROLFLOW)
67
+ span.set_attribute(SemanticConvetion.GEN_AI_ENVIRONMENT,
68
+ environment)
69
+ span.set_attribute(SemanticConvetion.GEN_AI_APPLICATION_NAME,
70
+ application_name)
71
+ span.set_attribute(SemanticConvetion.GEN_AI_TYPE,
72
+ SemanticConvetion.GEN_AI_TYPE_AGENT)
73
+
74
+ if gen_ai_endpoint == "controlflow.create_agent":
75
+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_ROLE,
76
+ instance.name)
77
+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_INSTRUCTIONS,
78
+ kwargs.get("instructions", ""))
79
+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_TOOLS,
80
+ str(kwargs.get("tools", "")))
81
+
82
+ try:
83
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
84
+ instance.model.model_name)
85
+ except:
86
+ span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
87
+ kwargs.get("model", "openai/gpt-4o-mini"))
88
+
89
+ elif gen_ai_endpoint == "controlflow.create_task":
90
+ if kwargs.get("objective","") == "":
91
+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_GOAL,
92
+ str(args[0]))
93
+ else:
94
+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_GOAL,
95
+ kwargs.get("objective",""))
96
+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_INSTRUCTIONS,
97
+ kwargs.get("instructions", ""))
98
+ span.set_attribute(SemanticConvetion.GEN_AI_AGENT_CONTEXT,
99
+ str(kwargs.get("context", "")))
100
+
101
+ span.set_status(Status(StatusCode.OK))
102
+
103
+ # Return original response
104
+ return response
105
+
106
+ except Exception as e:
107
+ handle_exception(span, e)
108
+ logger.error("Error in trace creation: %s", e)
109
+
110
+ # Return original response
111
+ return response
112
+
113
+ return wrapper
@@ -103,12 +103,15 @@ def chat_completions(gen_ai_endpoint, version, environment, application_name,
103
103
  content = message["content"]
104
104
 
105
105
  if isinstance(content, list):
106
- content_str = ", ".join(
107
- # pylint: disable=line-too-long
108
- f'{item["type"]}: {item["text"] if "text" in item else item["image_url"]}'
109
- if "type" in item else f'text: {item["text"]}'
110
- for item in content
111
- )
106
+ content_str_list = []
107
+ for item in content:
108
+ if item["type"] == "text":
109
+ content_str_list.append(f'text: {item["text"]}')
110
+ elif (item["type"] == "image_url" and
111
+ not item["image_url"]["url"].startswith("data:")):
112
+ # pylint: disable=line-too-long
113
+ content_str_list.append(f'image_url: {item["image_url"]["url"]}')
114
+ content_str = ", ".join(content_str_list)
112
115
  formatted_messages.append(f"{role}: {content_str}")
113
116
  else:
114
117
  formatted_messages.append(f"{role}: {content}")
@@ -46,6 +46,7 @@ class SemanticConvetion:
46
46
  GEN_AI_REQUEST_AUDIO_RESPONSE_FORMAT = "gen_ai.request.audio_response_format"
47
47
  GEN_AI_REQUEST_AUDIO_SPEED = "gen_ai.request.audio_speed"
48
48
  GEN_AI_REQUEST_AUDIO_SETTINGS = "gen_ai.request.audio_settings"
49
+ GEN_AI_REQUEST_AUDIO_DURATION = "gen_ai.request.audio_duration"
49
50
  GEN_AI_REQUEST_FINETUNE_STATUS = "gen_ai.request.fine_tune_status"
50
51
  GEN_AI_REQUEST_FINETUNE_MODEL_SUFFIX = "gen_ai.request.fine_tune_model_suffix"
51
52
  GEN_AI_REQUEST_FINETUNE_MODEL_EPOCHS = "gen_ai.request.fine_tune_n_epochs"
@@ -128,6 +129,8 @@ class SemanticConvetion:
128
129
  GEN_AI_SYSTEM_PHIDATA = "phidata"
129
130
  GEN_AI_SYSTEM_JULEP = "julep"
130
131
  GEN_AI_SYSTEM_AI21 = "ai21"
132
+ GEN_AI_SYSTEM_CONTROLFLOW = "controlflow"
133
+ GEN_AI_SYSTEM_ASSEMBLYAI = "assemblyai"
131
134
 
132
135
  # Vector DB
133
136
  DB_OPERATION_API_ENDPOINT = "db.operation.api_endpoint"
File without changes