openlit 1.34.30__py3-none-any.whl → 1.34.31__py3-none-any.whl

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 (168) hide show
  1. openlit/__helpers.py +235 -86
  2. openlit/__init__.py +16 -13
  3. openlit/_instrumentors.py +2 -1
  4. openlit/evals/all.py +50 -21
  5. openlit/evals/bias_detection.py +47 -20
  6. openlit/evals/hallucination.py +53 -22
  7. openlit/evals/toxicity.py +50 -21
  8. openlit/evals/utils.py +54 -30
  9. openlit/guard/all.py +61 -19
  10. openlit/guard/prompt_injection.py +34 -14
  11. openlit/guard/restrict_topic.py +46 -15
  12. openlit/guard/sensitive_topic.py +34 -14
  13. openlit/guard/utils.py +58 -22
  14. openlit/instrumentation/ag2/__init__.py +24 -8
  15. openlit/instrumentation/ag2/ag2.py +34 -13
  16. openlit/instrumentation/ag2/async_ag2.py +34 -13
  17. openlit/instrumentation/ag2/utils.py +133 -30
  18. openlit/instrumentation/ai21/__init__.py +43 -14
  19. openlit/instrumentation/ai21/ai21.py +47 -21
  20. openlit/instrumentation/ai21/async_ai21.py +47 -21
  21. openlit/instrumentation/ai21/utils.py +299 -78
  22. openlit/instrumentation/anthropic/__init__.py +21 -4
  23. openlit/instrumentation/anthropic/anthropic.py +28 -17
  24. openlit/instrumentation/anthropic/async_anthropic.py +28 -17
  25. openlit/instrumentation/anthropic/utils.py +145 -35
  26. openlit/instrumentation/assemblyai/__init__.py +11 -2
  27. openlit/instrumentation/assemblyai/assemblyai.py +15 -4
  28. openlit/instrumentation/assemblyai/utils.py +120 -25
  29. openlit/instrumentation/astra/__init__.py +43 -10
  30. openlit/instrumentation/astra/astra.py +28 -5
  31. openlit/instrumentation/astra/async_astra.py +28 -5
  32. openlit/instrumentation/astra/utils.py +151 -55
  33. openlit/instrumentation/azure_ai_inference/__init__.py +43 -10
  34. openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +53 -21
  35. openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +53 -21
  36. openlit/instrumentation/azure_ai_inference/utils.py +307 -83
  37. openlit/instrumentation/bedrock/__init__.py +21 -4
  38. openlit/instrumentation/bedrock/bedrock.py +63 -25
  39. openlit/instrumentation/bedrock/utils.py +139 -30
  40. openlit/instrumentation/chroma/__init__.py +89 -16
  41. openlit/instrumentation/chroma/chroma.py +28 -6
  42. openlit/instrumentation/chroma/utils.py +167 -51
  43. openlit/instrumentation/cohere/__init__.py +63 -18
  44. openlit/instrumentation/cohere/async_cohere.py +63 -24
  45. openlit/instrumentation/cohere/cohere.py +63 -24
  46. openlit/instrumentation/cohere/utils.py +286 -73
  47. openlit/instrumentation/controlflow/__init__.py +35 -9
  48. openlit/instrumentation/controlflow/controlflow.py +66 -33
  49. openlit/instrumentation/crawl4ai/__init__.py +25 -10
  50. openlit/instrumentation/crawl4ai/async_crawl4ai.py +78 -31
  51. openlit/instrumentation/crawl4ai/crawl4ai.py +78 -31
  52. openlit/instrumentation/crewai/__init__.py +40 -15
  53. openlit/instrumentation/crewai/async_crewai.py +32 -7
  54. openlit/instrumentation/crewai/crewai.py +32 -7
  55. openlit/instrumentation/crewai/utils.py +159 -56
  56. openlit/instrumentation/dynamiq/__init__.py +46 -12
  57. openlit/instrumentation/dynamiq/dynamiq.py +74 -33
  58. openlit/instrumentation/elevenlabs/__init__.py +23 -4
  59. openlit/instrumentation/elevenlabs/async_elevenlabs.py +16 -4
  60. openlit/instrumentation/elevenlabs/elevenlabs.py +16 -4
  61. openlit/instrumentation/elevenlabs/utils.py +128 -25
  62. openlit/instrumentation/embedchain/__init__.py +11 -2
  63. openlit/instrumentation/embedchain/embedchain.py +68 -35
  64. openlit/instrumentation/firecrawl/__init__.py +24 -7
  65. openlit/instrumentation/firecrawl/firecrawl.py +46 -20
  66. openlit/instrumentation/google_ai_studio/__init__.py +45 -10
  67. openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +67 -44
  68. openlit/instrumentation/google_ai_studio/google_ai_studio.py +67 -44
  69. openlit/instrumentation/google_ai_studio/utils.py +180 -67
  70. openlit/instrumentation/gpt4all/__init__.py +22 -7
  71. openlit/instrumentation/gpt4all/gpt4all.py +67 -29
  72. openlit/instrumentation/gpt4all/utils.py +285 -61
  73. openlit/instrumentation/gpu/__init__.py +128 -47
  74. openlit/instrumentation/groq/__init__.py +21 -4
  75. openlit/instrumentation/groq/async_groq.py +33 -21
  76. openlit/instrumentation/groq/groq.py +33 -21
  77. openlit/instrumentation/groq/utils.py +192 -55
  78. openlit/instrumentation/haystack/__init__.py +70 -24
  79. openlit/instrumentation/haystack/async_haystack.py +28 -6
  80. openlit/instrumentation/haystack/haystack.py +28 -6
  81. openlit/instrumentation/haystack/utils.py +196 -74
  82. openlit/instrumentation/julep/__init__.py +69 -19
  83. openlit/instrumentation/julep/async_julep.py +53 -27
  84. openlit/instrumentation/julep/julep.py +53 -28
  85. openlit/instrumentation/langchain/__init__.py +74 -63
  86. openlit/instrumentation/langchain/callback_handler.py +1100 -0
  87. openlit/instrumentation/langchain_community/__init__.py +13 -2
  88. openlit/instrumentation/langchain_community/async_langchain_community.py +23 -5
  89. openlit/instrumentation/langchain_community/langchain_community.py +23 -5
  90. openlit/instrumentation/langchain_community/utils.py +35 -9
  91. openlit/instrumentation/letta/__init__.py +68 -15
  92. openlit/instrumentation/letta/letta.py +99 -54
  93. openlit/instrumentation/litellm/__init__.py +43 -14
  94. openlit/instrumentation/litellm/async_litellm.py +51 -26
  95. openlit/instrumentation/litellm/litellm.py +51 -26
  96. openlit/instrumentation/litellm/utils.py +304 -102
  97. openlit/instrumentation/llamaindex/__init__.py +267 -90
  98. openlit/instrumentation/llamaindex/async_llamaindex.py +28 -6
  99. openlit/instrumentation/llamaindex/llamaindex.py +28 -6
  100. openlit/instrumentation/llamaindex/utils.py +204 -91
  101. openlit/instrumentation/mem0/__init__.py +11 -2
  102. openlit/instrumentation/mem0/mem0.py +50 -29
  103. openlit/instrumentation/milvus/__init__.py +10 -2
  104. openlit/instrumentation/milvus/milvus.py +31 -6
  105. openlit/instrumentation/milvus/utils.py +166 -67
  106. openlit/instrumentation/mistral/__init__.py +63 -18
  107. openlit/instrumentation/mistral/async_mistral.py +63 -24
  108. openlit/instrumentation/mistral/mistral.py +63 -24
  109. openlit/instrumentation/mistral/utils.py +277 -69
  110. openlit/instrumentation/multion/__init__.py +69 -19
  111. openlit/instrumentation/multion/async_multion.py +57 -26
  112. openlit/instrumentation/multion/multion.py +57 -26
  113. openlit/instrumentation/ollama/__init__.py +39 -18
  114. openlit/instrumentation/ollama/async_ollama.py +57 -26
  115. openlit/instrumentation/ollama/ollama.py +57 -26
  116. openlit/instrumentation/ollama/utils.py +226 -50
  117. openlit/instrumentation/openai/__init__.py +156 -32
  118. openlit/instrumentation/openai/async_openai.py +147 -67
  119. openlit/instrumentation/openai/openai.py +150 -67
  120. openlit/instrumentation/openai/utils.py +657 -185
  121. openlit/instrumentation/openai_agents/__init__.py +5 -1
  122. openlit/instrumentation/openai_agents/processor.py +110 -90
  123. openlit/instrumentation/phidata/__init__.py +13 -5
  124. openlit/instrumentation/phidata/phidata.py +67 -32
  125. openlit/instrumentation/pinecone/__init__.py +48 -9
  126. openlit/instrumentation/pinecone/async_pinecone.py +27 -5
  127. openlit/instrumentation/pinecone/pinecone.py +27 -5
  128. openlit/instrumentation/pinecone/utils.py +153 -47
  129. openlit/instrumentation/premai/__init__.py +22 -7
  130. openlit/instrumentation/premai/premai.py +51 -26
  131. openlit/instrumentation/premai/utils.py +246 -59
  132. openlit/instrumentation/pydantic_ai/__init__.py +49 -22
  133. openlit/instrumentation/pydantic_ai/pydantic_ai.py +69 -16
  134. openlit/instrumentation/pydantic_ai/utils.py +89 -24
  135. openlit/instrumentation/qdrant/__init__.py +19 -4
  136. openlit/instrumentation/qdrant/async_qdrant.py +33 -7
  137. openlit/instrumentation/qdrant/qdrant.py +33 -7
  138. openlit/instrumentation/qdrant/utils.py +228 -93
  139. openlit/instrumentation/reka/__init__.py +23 -10
  140. openlit/instrumentation/reka/async_reka.py +17 -11
  141. openlit/instrumentation/reka/reka.py +17 -11
  142. openlit/instrumentation/reka/utils.py +138 -36
  143. openlit/instrumentation/together/__init__.py +44 -12
  144. openlit/instrumentation/together/async_together.py +50 -27
  145. openlit/instrumentation/together/together.py +50 -27
  146. openlit/instrumentation/together/utils.py +301 -71
  147. openlit/instrumentation/transformers/__init__.py +2 -1
  148. openlit/instrumentation/transformers/transformers.py +13 -3
  149. openlit/instrumentation/transformers/utils.py +139 -36
  150. openlit/instrumentation/vertexai/__init__.py +81 -16
  151. openlit/instrumentation/vertexai/async_vertexai.py +33 -15
  152. openlit/instrumentation/vertexai/utils.py +123 -27
  153. openlit/instrumentation/vertexai/vertexai.py +33 -15
  154. openlit/instrumentation/vllm/__init__.py +12 -5
  155. openlit/instrumentation/vllm/utils.py +121 -31
  156. openlit/instrumentation/vllm/vllm.py +16 -10
  157. openlit/otel/events.py +35 -10
  158. openlit/otel/metrics.py +32 -24
  159. openlit/otel/tracing.py +24 -9
  160. openlit/semcov/__init__.py +72 -6
  161. {openlit-1.34.30.dist-info → openlit-1.34.31.dist-info}/METADATA +2 -1
  162. openlit-1.34.31.dist-info/RECORD +166 -0
  163. openlit/instrumentation/langchain/async_langchain.py +0 -102
  164. openlit/instrumentation/langchain/langchain.py +0 -102
  165. openlit/instrumentation/langchain/utils.py +0 -252
  166. openlit-1.34.30.dist-info/RECORD +0 -168
  167. {openlit-1.34.30.dist-info → openlit-1.34.31.dist-info}/LICENSE +0 -0
  168. {openlit-1.34.30.dist-info → openlit-1.34.31.dist-info}/WHEEL +0 -0
@@ -1,6 +1,7 @@
1
1
  """
2
2
  ChromaDB OpenTelemetry instrumentation utility functions
3
3
  """
4
+
4
5
  import time
5
6
  from urllib.parse import urlparse
6
7
  from opentelemetry.trace import Status, StatusCode
@@ -23,12 +24,14 @@ DB_OPERATION_MAP = {
23
24
  "chroma.delete": SemanticConvention.DB_OPERATION_DELETE,
24
25
  }
25
26
 
27
+
26
28
  def object_count(obj):
27
29
  """
28
30
  Counts length of object if it exists, else returns 0.
29
31
  """
30
32
  return len(obj) if obj else 0
31
33
 
34
+
32
35
  def set_server_address_and_port(instance):
33
36
  """
34
37
  Extracts server address and port from ChromaDB client instance.
@@ -74,8 +77,18 @@ def set_server_address_and_port(instance):
74
77
 
75
78
  return server_address, server_port
76
79
 
77
- def common_vectordb_logic(scope, environment, application_name,
78
- metrics, capture_message_content, disable_metrics, version, instance=None, endpoint=None):
80
+
81
+ def common_vectordb_logic(
82
+ scope,
83
+ environment,
84
+ application_name,
85
+ metrics,
86
+ capture_message_content,
87
+ disable_metrics,
88
+ version,
89
+ instance=None,
90
+ endpoint=None,
91
+ ):
79
92
  """
80
93
  Process vector database request and generate telemetry.
81
94
  """
@@ -83,12 +96,22 @@ def common_vectordb_logic(scope, environment, application_name,
83
96
  scope._end_time = time.time()
84
97
 
85
98
  # Set common database span attributes using helper
86
- common_db_span_attributes(scope, SemanticConvention.DB_SYSTEM_CHROMA, scope._server_address, scope._server_port,
87
- environment, application_name, version)
99
+ common_db_span_attributes(
100
+ scope,
101
+ SemanticConvention.DB_SYSTEM_CHROMA,
102
+ scope._server_address,
103
+ scope._server_port,
104
+ environment,
105
+ application_name,
106
+ version,
107
+ )
88
108
 
89
109
  # Set DB operation specific attributes
90
110
  scope._span.set_attribute(SemanticConvention.DB_OPERATION_NAME, scope._db_operation)
91
- scope._span.set_attribute(SemanticConvention.DB_CLIENT_OPERATION_DURATION, scope._end_time - scope._start_time)
111
+ scope._span.set_attribute(
112
+ SemanticConvention.DB_CLIENT_OPERATION_DURATION,
113
+ scope._end_time - scope._start_time,
114
+ )
92
115
 
93
116
  # Set collection name from instance
94
117
  if hasattr(instance, "name"):
@@ -97,13 +120,19 @@ def common_vectordb_logic(scope, environment, application_name,
97
120
  # Set Create Collection operation specific attributes
98
121
  if scope._db_operation == SemanticConvention.DB_OPERATION_CREATE_COLLECTION:
99
122
  # Standard database attributes
100
- collection_name = scope._kwargs.get("name") or (scope._args[0] if scope._args else "unknown")
101
- scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
123
+ collection_name = scope._kwargs.get("name") or (
124
+ scope._args[0] if scope._args else "unknown"
125
+ )
126
+ scope._span.set_attribute(
127
+ SemanticConvention.DB_COLLECTION_NAME, collection_name
128
+ )
102
129
 
103
130
  # Vector database specific attributes (extensions)
104
131
  metadata = scope._kwargs.get("metadata", {})
105
132
  if metadata:
106
- scope._span.set_attribute(SemanticConvention.DB_COLLECTION_METADATA, str(metadata))
133
+ scope._span.set_attribute(
134
+ SemanticConvention.DB_COLLECTION_METADATA, str(metadata)
135
+ )
107
136
 
108
137
  elif scope._db_operation == SemanticConvention.DB_OPERATION_INSERT:
109
138
  collection_name = getattr(instance, "name", "unknown")
@@ -111,14 +140,20 @@ def common_vectordb_logic(scope, environment, application_name,
111
140
 
112
141
  # Standard database attributes
113
142
  scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
114
- scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
115
- scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(query))
143
+ scope._span.set_attribute(
144
+ SemanticConvention.DB_COLLECTION_NAME, collection_name
145
+ )
146
+ scope._span.set_attribute(
147
+ SemanticConvention.DB_VECTOR_COUNT, object_count(query)
148
+ )
116
149
 
117
150
  # Vector database specific attributes (extensions)
118
- scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
151
+ scope._span.set_attribute(
152
+ SemanticConvention.DB_QUERY_SUMMARY,
119
153
  f"{scope._db_operation} {collection_name} "
120
154
  f"ids={query} "
121
- f"documents={scope._kwargs.get('documents', [])}")
155
+ f"documents={scope._kwargs.get('documents', [])}",
156
+ )
122
157
 
123
158
  elif scope._db_operation == SemanticConvention.DB_OPERATION_GET:
124
159
  collection_name = getattr(instance, "name", "unknown")
@@ -130,17 +165,25 @@ def common_vectordb_logic(scope, environment, application_name,
130
165
 
131
166
  # Standard database attributes
132
167
  scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
133
- scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
134
- scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(query))
168
+ scope._span.set_attribute(
169
+ SemanticConvention.DB_COLLECTION_NAME, collection_name
170
+ )
171
+ scope._span.set_attribute(
172
+ SemanticConvention.DB_VECTOR_COUNT, object_count(query)
173
+ )
135
174
 
136
175
  # Vector database specific attributes (extensions)
137
- scope._span.set_attribute(SemanticConvention.DB_FILTER, str(scope._kwargs.get("where", "")))
176
+ scope._span.set_attribute(
177
+ SemanticConvention.DB_FILTER, str(scope._kwargs.get("where", ""))
178
+ )
138
179
 
139
- scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
180
+ scope._span.set_attribute(
181
+ SemanticConvention.DB_QUERY_SUMMARY,
140
182
  f"{scope._db_operation} {collection_name} "
141
183
  f"ids={query} "
142
184
  f"limit={scope._kwargs.get('limit', 'None')} "
143
- f"offset={scope._kwargs.get('offset', 'None')}")
185
+ f"offset={scope._kwargs.get('offset', 'None')}",
186
+ )
144
187
 
145
188
  elif endpoint == "chroma.query":
146
189
  query_texts = scope._kwargs.get("query_texts", [])
@@ -156,24 +199,39 @@ def common_vectordb_logic(scope, environment, application_name,
156
199
 
157
200
  # Standard database attributes
158
201
  scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, query_content)
159
- scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
202
+ scope._span.set_attribute(
203
+ SemanticConvention.DB_COLLECTION_NAME, collection_name
204
+ )
160
205
 
161
206
  # Vector database specific attributes (extensions)
162
- scope._span.set_attribute(SemanticConvention.DB_VECTOR_QUERY_TOP_K, scope._kwargs.get("n_results", 10))
163
- scope._span.set_attribute(SemanticConvention.DB_FILTER, str(scope._kwargs.get("where", "")))
207
+ scope._span.set_attribute(
208
+ SemanticConvention.DB_VECTOR_QUERY_TOP_K,
209
+ scope._kwargs.get("n_results", 10),
210
+ )
211
+ scope._span.set_attribute(
212
+ SemanticConvention.DB_FILTER, str(scope._kwargs.get("where", ""))
213
+ )
164
214
 
165
215
  # Extract response metrics if available
166
216
  if scope._response:
167
217
  # Get number of results returned
168
218
  if hasattr(scope._response, "get") and scope._response.get("ids"):
169
- returned_rows = object_count(scope._response["ids"][0]) if scope._response["ids"] else 0
170
- scope._span.set_attribute(SemanticConvention.DB_RESPONSE_RETURNED_ROWS, returned_rows)
171
-
172
- scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
219
+ returned_rows = (
220
+ object_count(scope._response["ids"][0])
221
+ if scope._response["ids"]
222
+ else 0
223
+ )
224
+ scope._span.set_attribute(
225
+ SemanticConvention.DB_RESPONSE_RETURNED_ROWS, returned_rows
226
+ )
227
+
228
+ scope._span.set_attribute(
229
+ SemanticConvention.DB_QUERY_SUMMARY,
173
230
  f"{scope._db_operation} {collection_name} "
174
231
  f"n_results={scope._kwargs.get('n_results', 10)} "
175
232
  f"{query_content} "
176
- f"filter={scope._kwargs.get('where', 'None')}")
233
+ f"filter={scope._kwargs.get('where', 'None')}",
234
+ )
177
235
 
178
236
  elif scope._db_operation == SemanticConvention.DB_OPERATION_UPDATE:
179
237
  collection_name = getattr(instance, "name", "unknown")
@@ -181,16 +239,22 @@ def common_vectordb_logic(scope, environment, application_name,
181
239
 
182
240
  # Standard database attributes
183
241
  scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
184
- scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
185
- scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(query))
242
+ scope._span.set_attribute(
243
+ SemanticConvention.DB_COLLECTION_NAME, collection_name
244
+ )
245
+ scope._span.set_attribute(
246
+ SemanticConvention.DB_VECTOR_COUNT, object_count(query)
247
+ )
186
248
 
187
249
  # Vector database specific attributes (extensions)
188
- scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
250
+ scope._span.set_attribute(
251
+ SemanticConvention.DB_QUERY_SUMMARY,
189
252
  f"{scope._db_operation} {collection_name} "
190
253
  f"ids={query} "
191
254
  f"embeddings={scope._kwargs.get('embeddings', 'None')} "
192
255
  f"metadatas={scope._kwargs.get('metadatas', 'None')} "
193
- f"documents={scope._kwargs.get('documents', 'None')}")
256
+ f"documents={scope._kwargs.get('documents', 'None')}",
257
+ )
194
258
 
195
259
  elif scope._db_operation == SemanticConvention.DB_OPERATION_UPSERT:
196
260
  collection_name = getattr(instance, "name", "unknown")
@@ -198,16 +262,22 @@ def common_vectordb_logic(scope, environment, application_name,
198
262
 
199
263
  # Standard database attributes
200
264
  scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
201
- scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
202
- scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(query))
265
+ scope._span.set_attribute(
266
+ SemanticConvention.DB_COLLECTION_NAME, collection_name
267
+ )
268
+ scope._span.set_attribute(
269
+ SemanticConvention.DB_VECTOR_COUNT, object_count(query)
270
+ )
203
271
 
204
272
  # Vector database specific attributes (extensions)
205
- scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
273
+ scope._span.set_attribute(
274
+ SemanticConvention.DB_QUERY_SUMMARY,
206
275
  f"{scope._db_operation} {collection_name} "
207
276
  f"ids={query} "
208
277
  f"embeddings={scope._kwargs.get('embeddings', 'None')} "
209
278
  f"metadatas={scope._kwargs.get('metadatas', 'None')} "
210
- f"documents={scope._kwargs.get('documents', 'None')}")
279
+ f"documents={scope._kwargs.get('documents', 'None')}",
280
+ )
211
281
 
212
282
  elif scope._db_operation == SemanticConvention.DB_OPERATION_DELETE:
213
283
  collection_name = getattr(instance, "name", "unknown")
@@ -215,16 +285,24 @@ def common_vectordb_logic(scope, environment, application_name,
215
285
 
216
286
  # Standard database attributes
217
287
  scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, str(query))
218
- scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
219
- scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, object_count(query))
288
+ scope._span.set_attribute(
289
+ SemanticConvention.DB_COLLECTION_NAME, collection_name
290
+ )
291
+ scope._span.set_attribute(
292
+ SemanticConvention.DB_VECTOR_COUNT, object_count(query)
293
+ )
220
294
 
221
295
  # Vector database specific attributes (extensions)
222
- scope._span.set_attribute(SemanticConvention.DB_FILTER, str(scope._kwargs.get("where", "")))
223
- scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
296
+ scope._span.set_attribute(
297
+ SemanticConvention.DB_FILTER, str(scope._kwargs.get("where", ""))
298
+ )
299
+ scope._span.set_attribute(
300
+ SemanticConvention.DB_QUERY_SUMMARY,
224
301
  f"{scope._db_operation} {collection_name} "
225
302
  f"ids={query} "
226
303
  f"filter={scope._kwargs.get('where', 'None')} "
227
- f"delete_all={scope._kwargs.get('delete_all', False)}")
304
+ f"delete_all={scope._kwargs.get('delete_all', False)}",
305
+ )
228
306
 
229
307
  elif scope._db_operation == SemanticConvention.DB_OPERATION_PEEK:
230
308
  collection_name = getattr(instance, "name", "unknown")
@@ -232,25 +310,54 @@ def common_vectordb_logic(scope, environment, application_name,
232
310
 
233
311
  # Standard database attributes
234
312
  scope._span.set_attribute(SemanticConvention.DB_QUERY_TEXT, query)
235
- scope._span.set_attribute(SemanticConvention.DB_COLLECTION_NAME, collection_name)
236
- scope._span.set_attribute(SemanticConvention.DB_VECTOR_COUNT, scope._kwargs.get("limit", ""))
313
+ scope._span.set_attribute(
314
+ SemanticConvention.DB_COLLECTION_NAME, collection_name
315
+ )
316
+ scope._span.set_attribute(
317
+ SemanticConvention.DB_VECTOR_COUNT, scope._kwargs.get("limit", "")
318
+ )
237
319
 
238
320
  # Vector database specific attributes (extensions)
239
- scope._span.set_attribute(SemanticConvention.DB_QUERY_SUMMARY,
321
+ scope._span.set_attribute(
322
+ SemanticConvention.DB_QUERY_SUMMARY,
240
323
  f"{scope._db_operation} {collection_name} "
241
- f"limit={scope._kwargs.get('limit', 'None')}")
324
+ f"limit={scope._kwargs.get('limit', 'None')}",
325
+ )
242
326
 
243
327
  scope._span.set_status(Status(StatusCode.OK))
244
328
 
245
329
  # Record metrics using helper
246
330
  if not disable_metrics:
247
- record_db_metrics(metrics, SemanticConvention.DB_SYSTEM_CHROMA, scope._server_address, scope._server_port,
248
- environment, application_name, scope._start_time, scope._end_time)
249
-
250
- def process_vectordb_response(response, db_operation, server_address, server_port,
251
- environment, application_name, metrics, start_time, span,
252
- capture_message_content=False, disable_metrics=False,
253
- version="1.0.0", instance=None, args=None, endpoint=None, **kwargs):
331
+ record_db_metrics(
332
+ metrics,
333
+ SemanticConvention.DB_SYSTEM_CHROMA,
334
+ scope._server_address,
335
+ scope._server_port,
336
+ environment,
337
+ application_name,
338
+ scope._start_time,
339
+ scope._end_time,
340
+ )
341
+
342
+
343
+ def process_vectordb_response(
344
+ response,
345
+ db_operation,
346
+ server_address,
347
+ server_port,
348
+ environment,
349
+ application_name,
350
+ metrics,
351
+ start_time,
352
+ span,
353
+ capture_message_content=False,
354
+ disable_metrics=False,
355
+ version="1.0.0",
356
+ instance=None,
357
+ args=None,
358
+ endpoint=None,
359
+ **kwargs,
360
+ ):
254
361
  """
255
362
  Process vector database response and generate telemetry following OpenTelemetry conventions.
256
363
  """
@@ -266,7 +373,16 @@ def process_vectordb_response(response, db_operation, server_address, server_por
266
373
  scope._server_address = server_address
267
374
  scope._server_port = server_port
268
375
 
269
- common_vectordb_logic(scope, environment, application_name,
270
- metrics, capture_message_content, disable_metrics, version, instance, endpoint)
376
+ common_vectordb_logic(
377
+ scope,
378
+ environment,
379
+ application_name,
380
+ metrics,
381
+ capture_message_content,
382
+ disable_metrics,
383
+ version,
384
+ instance,
385
+ endpoint,
386
+ )
271
387
 
272
388
  return response
@@ -5,19 +5,16 @@ import importlib.metadata
5
5
  from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
6
6
  from wrapt import wrap_function_wrapper
7
7
 
8
- from openlit.instrumentation.cohere.cohere import (
9
- chat,
10
- chat_stream,
11
- embed
12
- )
8
+ from openlit.instrumentation.cohere.cohere import chat, chat_stream, embed
13
9
  from openlit.instrumentation.cohere.async_cohere import (
14
10
  async_chat,
15
11
  async_chat_stream,
16
- async_embed
12
+ async_embed,
17
13
  )
18
14
 
19
15
  _instruments = ("cohere >= 5.14.0",)
20
16
 
17
+
21
18
  class CohereInstrumentor(BaseInstrumentor):
22
19
  """
23
20
  An instrumentor for Cohere client library.
@@ -40,48 +37,96 @@ class CohereInstrumentor(BaseInstrumentor):
40
37
  wrap_function_wrapper(
41
38
  "cohere.client_v2",
42
39
  "ClientV2.chat",
43
- chat(version, environment, application_name,
44
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
40
+ chat(
41
+ version,
42
+ environment,
43
+ application_name,
44
+ tracer,
45
+ pricing_info,
46
+ capture_message_content,
47
+ metrics,
48
+ disable_metrics,
49
+ ),
45
50
  )
46
51
 
47
52
  # sync chat streaming
48
53
  wrap_function_wrapper(
49
54
  "cohere.client_v2",
50
55
  "ClientV2.chat_stream",
51
- chat_stream(version, environment, application_name,
52
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
56
+ chat_stream(
57
+ version,
58
+ environment,
59
+ application_name,
60
+ tracer,
61
+ pricing_info,
62
+ capture_message_content,
63
+ metrics,
64
+ disable_metrics,
65
+ ),
53
66
  )
54
67
 
55
68
  # sync embeddings
56
69
  wrap_function_wrapper(
57
70
  "cohere.client_v2",
58
71
  "ClientV2.embed",
59
- embed(version, environment, application_name,
60
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
72
+ embed(
73
+ version,
74
+ environment,
75
+ application_name,
76
+ tracer,
77
+ pricing_info,
78
+ capture_message_content,
79
+ metrics,
80
+ disable_metrics,
81
+ ),
61
82
  )
62
83
 
63
84
  # async chat completions
64
85
  wrap_function_wrapper(
65
86
  "cohere.client_v2",
66
87
  "AsyncClientV2.chat",
67
- async_chat(version, environment, application_name,
68
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
88
+ async_chat(
89
+ version,
90
+ environment,
91
+ application_name,
92
+ tracer,
93
+ pricing_info,
94
+ capture_message_content,
95
+ metrics,
96
+ disable_metrics,
97
+ ),
69
98
  )
70
99
 
71
100
  # async chat streaming
72
101
  wrap_function_wrapper(
73
102
  "cohere.client_v2",
74
103
  "AsyncClientV2.chat_stream",
75
- async_chat_stream(version, environment, application_name,
76
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
104
+ async_chat_stream(
105
+ version,
106
+ environment,
107
+ application_name,
108
+ tracer,
109
+ pricing_info,
110
+ capture_message_content,
111
+ metrics,
112
+ disable_metrics,
113
+ ),
77
114
  )
78
115
 
79
116
  # async embeddings
80
117
  wrap_function_wrapper(
81
118
  "cohere.client_v2",
82
119
  "AsyncClientV2.embed",
83
- async_embed(version, environment, application_name,
84
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
120
+ async_embed(
121
+ version,
122
+ environment,
123
+ application_name,
124
+ tracer,
125
+ pricing_info,
126
+ capture_message_content,
127
+ metrics,
128
+ disable_metrics,
129
+ ),
85
130
  )
86
131
 
87
132
  def _uninstrument(self, **kwargs):
@@ -16,8 +16,17 @@ from openlit.instrumentation.cohere.utils import (
16
16
  )
17
17
  from openlit.semcov import SemanticConvention
18
18
 
19
- def async_chat(version, environment, application_name,
20
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
19
+
20
+ def async_chat(
21
+ version,
22
+ environment,
23
+ application_name,
24
+ tracer,
25
+ pricing_info,
26
+ capture_message_content,
27
+ metrics,
28
+ disable_metrics,
29
+ ):
21
30
  """
22
31
  Generates a telemetry wrapper for GenAI chat function call
23
32
  """
@@ -27,7 +36,9 @@ def async_chat(version, environment, application_name,
27
36
  Wraps the GenAI chat function call.
28
37
  """
29
38
 
30
- server_address, server_port = set_server_address_and_port(instance, "api.cohere.com", 443)
39
+ server_address, server_port = set_server_address_and_port(
40
+ instance, "api.cohere.com", 443
41
+ )
31
42
  request_model = kwargs.get("model", "command-r-plus-08-2024")
32
43
 
33
44
  span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
@@ -49,15 +60,24 @@ def async_chat(version, environment, application_name,
49
60
  capture_message_content=capture_message_content,
50
61
  disable_metrics=disable_metrics,
51
62
  version=version,
52
- **kwargs
63
+ **kwargs,
53
64
  )
54
65
 
55
66
  return response
56
67
 
57
68
  return wrapper
58
69
 
59
- def async_chat_stream(version, environment, application_name,
60
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
70
+
71
+ def async_chat_stream(
72
+ version,
73
+ environment,
74
+ application_name,
75
+ tracer,
76
+ pricing_info,
77
+ capture_message_content,
78
+ metrics,
79
+ disable_metrics,
80
+ ):
61
81
  """
62
82
  Generates a telemetry wrapper for GenAI chat_stream function call
63
83
  """
@@ -68,15 +88,15 @@ def async_chat_stream(version, environment, application_name,
68
88
  """
69
89
 
70
90
  def __init__(
71
- self,
72
- wrapped,
73
- span,
74
- span_name,
75
- kwargs,
76
- server_address,
77
- server_port,
78
- **args,
79
- ):
91
+ self,
92
+ wrapped,
93
+ span,
94
+ span_name,
95
+ kwargs,
96
+ server_address,
97
+ server_port,
98
+ **args,
99
+ ):
80
100
  self.__wrapped__ = wrapped
81
101
  self._span = span
82
102
  self._span_name = span_name
@@ -120,7 +140,9 @@ def async_chat_stream(version, environment, application_name,
120
140
  return chunk
121
141
  except StopAsyncIteration:
122
142
  try:
123
- with tracer.start_as_current_span(self._span_name, kind= SpanKind.CLIENT) as self._span:
143
+ with tracer.start_as_current_span(
144
+ self._span_name, kind=SpanKind.CLIENT
145
+ ) as self._span:
124
146
  process_streaming_chat_response(
125
147
  self,
126
148
  pricing_info=pricing_info,
@@ -129,7 +151,7 @@ def async_chat_stream(version, environment, application_name,
129
151
  metrics=metrics,
130
152
  capture_message_content=capture_message_content,
131
153
  disable_metrics=disable_metrics,
132
- version=version
154
+ version=version,
133
155
  )
134
156
 
135
157
  except Exception as e:
@@ -142,7 +164,9 @@ def async_chat_stream(version, environment, application_name,
142
164
  Wraps the GenAI chat_stream function call.
143
165
  """
144
166
 
145
- server_address, server_port = set_server_address_and_port(instance, "api.cohere.com", 443)
167
+ server_address, server_port = set_server_address_and_port(
168
+ instance, "api.cohere.com", 443
169
+ )
146
170
  request_model = kwargs.get("model", "command-r-plus-08-2024")
147
171
 
148
172
  span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
@@ -151,12 +175,23 @@ def async_chat_stream(version, environment, application_name,
151
175
  awaited_wrapped = await wrapped(*args, **kwargs)
152
176
  span = tracer.start_span(span_name, kind=SpanKind.CLIENT)
153
177
 
154
- return TracedAsyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)
178
+ return TracedAsyncStream(
179
+ awaited_wrapped, span, span_name, kwargs, server_address, server_port
180
+ )
155
181
 
156
182
  return wrapper
157
183
 
158
- def async_embed(version, environment, application_name,
159
- tracer, pricing_info, capture_message_content, metrics, disable_metrics):
184
+
185
+ def async_embed(
186
+ version,
187
+ environment,
188
+ application_name,
189
+ tracer,
190
+ pricing_info,
191
+ capture_message_content,
192
+ metrics,
193
+ disable_metrics,
194
+ ):
160
195
  """
161
196
  Generates a telemetry wrapper for GenAI embedding function call
162
197
  """
@@ -166,10 +201,14 @@ def async_embed(version, environment, application_name,
166
201
  Wraps the GenAI embedding function call.
167
202
  """
168
203
 
169
- server_address, server_port = set_server_address_and_port(instance, "api.cohere.com", 443)
204
+ server_address, server_port = set_server_address_and_port(
205
+ instance, "api.cohere.com", 443
206
+ )
170
207
  request_model = kwargs.get("model", "embed-english-v3.0")
171
208
 
172
- span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_EMBEDDING} {request_model}"
209
+ span_name = (
210
+ f"{SemanticConvention.GEN_AI_OPERATION_TYPE_EMBEDDING} {request_model}"
211
+ )
173
212
 
174
213
  with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
175
214
  start_time = time.time()
@@ -190,7 +229,7 @@ def async_embed(version, environment, application_name,
190
229
  capture_message_content=capture_message_content,
191
230
  disable_metrics=disable_metrics,
192
231
  version=version,
193
- **kwargs
232
+ **kwargs,
194
233
  )
195
234
 
196
235
  except Exception as e: