openlit 1.34.30__py3-none-any.whl → 1.34.32__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 +19 -14
  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 +113 -6
  15. openlit/instrumentation/ag2/ag2.py +459 -17
  16. openlit/instrumentation/ag2/async_ag2.py +459 -17
  17. openlit/instrumentation/ag2/utils.py +475 -31
  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 +82 -6
  161. {openlit-1.34.30.dist-info → openlit-1.34.32.dist-info}/METADATA +2 -1
  162. openlit-1.34.32.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.32.dist-info}/LICENSE +0 -0
  168. {openlit-1.34.30.dist-info → openlit-1.34.32.dist-info}/WHEEL +0 -0
@@ -5,13 +5,18 @@ from typing import Collection, Iterable
5
5
  import logging
6
6
  from functools import partial
7
7
  from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
8
- from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
8
+ from opentelemetry.sdk.resources import (
9
+ SERVICE_NAME,
10
+ TELEMETRY_SDK_NAME,
11
+ DEPLOYMENT_ENVIRONMENT,
12
+ )
9
13
  from opentelemetry.metrics import get_meter, CallbackOptions, Observation
10
14
  from openlit.semcov import SemanticConvention
11
15
 
12
16
  # Initialize logger for logging potential issues and operations
13
17
  logger = logging.getLogger(__name__)
14
18
 
19
+
15
20
  class GPUInstrumentor(BaseInstrumentor):
16
21
  """
17
22
  An instrumentor for collecting GPU metrics.
@@ -55,8 +60,14 @@ class GPUInstrumentor(BaseInstrumentor):
55
60
  for semantic_name, internal_name in metric_names:
56
61
  meter.create_observable_gauge(
57
62
  name=getattr(SemanticConvention, semantic_name),
58
- callbacks=[partial(self._collect_metric,
59
- environment, application_name, internal_name)],
63
+ callbacks=[
64
+ partial(
65
+ self._collect_metric,
66
+ environment,
67
+ application_name,
68
+ internal_name,
69
+ )
70
+ ],
60
71
  description=f"GPU {internal_name.replace('_', ' ').title()}",
61
72
  )
62
73
 
@@ -67,32 +78,38 @@ class GPUInstrumentor(BaseInstrumentor):
67
78
  def _get_gpu_type(self) -> str:
68
79
  try:
69
80
  import pynvml
81
+
70
82
  pynvml.nvmlInit()
71
83
  return "nvidia"
72
84
  except Exception:
73
85
  try:
74
86
  import amdsmi
87
+
75
88
  amdsmi.amdsmi_init()
76
89
  return "amd"
77
90
  except Exception:
78
91
  return None
79
92
 
80
-
81
- def _collect_metric(self, environment, application_name,
82
- metric_name,
83
- options: CallbackOptions) -> Iterable[Observation]:
93
+ def _collect_metric(
94
+ self, environment, application_name, metric_name, options: CallbackOptions
95
+ ) -> Iterable[Observation]:
84
96
  # pylint: disable=no-else-return
85
97
  if self.gpu_type == "nvidia":
86
- return self._collect_nvidia_metrics(environment, application_name, metric_name, options)
98
+ return self._collect_nvidia_metrics(
99
+ environment, application_name, metric_name, options
100
+ )
87
101
  elif self.gpu_type == "amd":
88
- return self._collect_amd_metrics(environment, application_name, metric_name, options)
102
+ return self._collect_amd_metrics(
103
+ environment, application_name, metric_name, options
104
+ )
89
105
  return []
90
106
 
91
- def _collect_nvidia_metrics(self, environment, application_name,
92
- metric_name,
93
- options: CallbackOptions) -> Iterable[Observation]:
107
+ def _collect_nvidia_metrics(
108
+ self, environment, application_name, metric_name, options: CallbackOptions
109
+ ) -> Iterable[Observation]:
94
110
  try:
95
111
  import pynvml
112
+
96
113
  gpu_count = pynvml.nvmlDeviceGetCount()
97
114
  mega_bytes = 1024 * 1024
98
115
  gpu_index = 0
@@ -103,8 +120,9 @@ class GPUInstrumentor(BaseInstrumentor):
103
120
  try:
104
121
  # pylint: disable=no-else-return
105
122
  if metric_name == "temperature":
106
- return pynvml.nvmlDeviceGetTemperature(handle,
107
- pynvml.NVML_TEMPERATURE_GPU)
123
+ return pynvml.nvmlDeviceGetTemperature(
124
+ handle, pynvml.NVML_TEMPERATURE_GPU
125
+ )
108
126
  elif metric_name == "utilization":
109
127
  return pynvml.nvmlDeviceGetUtilizationRates(handle).gpu
110
128
  elif metric_name == "utilization_enc":
@@ -115,26 +133,43 @@ class GPUInstrumentor(BaseInstrumentor):
115
133
  return 0
116
134
  elif metric_name == "memory_available":
117
135
  memory_info = pynvml.nvmlDeviceGetMemoryInfo(handle)
118
- return (memory_info.free // mega_bytes) # Assuming reserved memory is 0
136
+ return (
137
+ memory_info.free // mega_bytes
138
+ ) # Assuming reserved memory is 0
119
139
  elif metric_name == "memory_total":
120
- return (pynvml.nvmlDeviceGetMemoryInfo(handle).total // mega_bytes)
140
+ return (
141
+ pynvml.nvmlDeviceGetMemoryInfo(handle).total
142
+ // mega_bytes
143
+ )
121
144
  elif metric_name == "memory_used":
122
- return (pynvml.nvmlDeviceGetMemoryInfo(handle).used // mega_bytes)
145
+ return (
146
+ pynvml.nvmlDeviceGetMemoryInfo(handle).used
147
+ // mega_bytes
148
+ )
123
149
  elif metric_name == "memory_free":
124
- return (pynvml.nvmlDeviceGetMemoryInfo(handle).free // mega_bytes)
150
+ return (
151
+ pynvml.nvmlDeviceGetMemoryInfo(handle).free
152
+ // mega_bytes
153
+ )
125
154
  elif metric_name == "power_draw":
126
- return (pynvml.nvmlDeviceGetPowerUsage(handle) // 1000.0)
155
+ return pynvml.nvmlDeviceGetPowerUsage(handle) // 1000.0
127
156
  elif metric_name == "power_limit":
128
- return (pynvml.nvmlDeviceGetEnforcedPowerLimit(handle) // 1000.0)
157
+ return (
158
+ pynvml.nvmlDeviceGetEnforcedPowerLimit(handle) // 1000.0
159
+ )
129
160
  except Exception as e:
130
161
  # pylint: disable=cell-var-from-loop
131
- logger.error("Error collecting metric %s for GPU %d: %s", metric_name,
132
- gpu_index, e)
162
+ logger.error(
163
+ "Error collecting metric %s for GPU %d: %s",
164
+ metric_name,
165
+ gpu_index,
166
+ e,
167
+ )
133
168
  return 0
134
169
 
135
170
  def safe_decode(byte_string):
136
171
  if isinstance(byte_string, bytes):
137
- return byte_string.decode('utf-8')
172
+ return byte_string.decode("utf-8")
138
173
  return byte_string
139
174
 
140
175
  attributes = {
@@ -142,19 +177,24 @@ class GPUInstrumentor(BaseInstrumentor):
142
177
  SERVICE_NAME: application_name,
143
178
  DEPLOYMENT_ENVIRONMENT: environment,
144
179
  SemanticConvention.GPU_INDEX: str(gpu_index),
145
- SemanticConvention.GPU_UUID: safe_decode(pynvml.nvmlDeviceGetUUID(handle)),
146
- SemanticConvention.GPU_NAME: safe_decode(pynvml.nvmlDeviceGetName(handle))
180
+ SemanticConvention.GPU_UUID: safe_decode(
181
+ pynvml.nvmlDeviceGetUUID(handle)
182
+ ),
183
+ SemanticConvention.GPU_NAME: safe_decode(
184
+ pynvml.nvmlDeviceGetName(handle)
185
+ ),
147
186
  }
148
187
  yield Observation(get_metric_value(handle, metric_name), attributes)
149
188
 
150
189
  except Exception as e:
151
190
  logger.error("Error in GPU metrics collection: %s", e)
152
191
 
153
- def _collect_amd_metrics(self, environment, application_name,
154
- metric_name,
155
- options: CallbackOptions) -> Iterable[Observation]:
192
+ def _collect_amd_metrics(
193
+ self, environment, application_name, metric_name, options: CallbackOptions
194
+ ) -> Iterable[Observation]:
156
195
  try:
157
196
  import amdsmi
197
+
158
198
  # Get the number of AMD GPUs
159
199
  devices = amdsmi.amdsmi_get_processor_handles()
160
200
  mega_bytes = 1024 * 1024
@@ -165,36 +205,69 @@ class GPUInstrumentor(BaseInstrumentor):
165
205
  # pylint: disable=no-else-return
166
206
  if metric_name == "temperature":
167
207
  # pylint: disable=line-too-long
168
- return amdsmi.amdsmi_get_temp_metric(device_handle,
169
- amdsmi.AmdSmiTemperatureType.EDGE,
170
- amdsmi.AmdSmiTemperatureMetric.CURRENT)
208
+ return amdsmi.amdsmi_get_temp_metric(
209
+ device_handle,
210
+ amdsmi.AmdSmiTemperatureType.EDGE,
211
+ amdsmi.AmdSmiTemperatureMetric.CURRENT,
212
+ )
171
213
  elif metric_name == "utilization":
172
214
  # pylint: disable=line-too-long
173
- return amdsmi.amdsmi_get_utilization_count(device_handle,
174
- amdsmi.AmdSmiUtilizationCounterType.COARSE_GRAIN_GFX_ACTIVITY)
215
+ return amdsmi.amdsmi_get_utilization_count(
216
+ device_handle,
217
+ amdsmi.AmdSmiUtilizationCounterType.COARSE_GRAIN_GFX_ACTIVITY,
218
+ )
175
219
  elif metric_name in ["utilization_enc", "utilization_dec"]:
176
220
  return 0 # Placeholder if unsupported
177
221
  elif metric_name == "fan_speed":
178
222
  return amdsmi.amdsmi_get_gpu_fan_speed(device_handle, 0)
179
223
  elif metric_name == "memory_available":
180
- return (amdsmi.amdsmi_get_gpu_memory_total(device_handle) // mega_bytes)
224
+ return (
225
+ amdsmi.amdsmi_get_gpu_memory_total(device_handle)
226
+ // mega_bytes
227
+ )
181
228
  elif metric_name == "memory_total":
182
- return (amdsmi.amdsmi_get_gpu_memory_total(device_handle) // mega_bytes)
229
+ return (
230
+ amdsmi.amdsmi_get_gpu_memory_total(device_handle)
231
+ // mega_bytes
232
+ )
183
233
  elif metric_name == "memory_used":
184
- return (amdsmi.amdsmi_get_gpu_memory_usage(device_handle) // mega_bytes)
234
+ return (
235
+ amdsmi.amdsmi_get_gpu_memory_usage(device_handle)
236
+ // mega_bytes
237
+ )
185
238
  elif metric_name == "memory_free":
186
- total_mem = (amdsmi.amdsmi_get_gpu_memory_total(device_handle) // mega_bytes)
187
- used_mem = (amdsmi.amdsmi_get_gpu_memory_usage(device_handle) // mega_bytes)
188
- return (total_mem - used_mem)
239
+ total_mem = (
240
+ amdsmi.amdsmi_get_gpu_memory_total(device_handle)
241
+ // mega_bytes
242
+ )
243
+ used_mem = (
244
+ amdsmi.amdsmi_get_gpu_memory_usage(device_handle)
245
+ // mega_bytes
246
+ )
247
+ return total_mem - used_mem
189
248
  elif metric_name == "power_draw":
190
249
  # pylint: disable=line-too-long
191
- return (amdsmi.amdsmi_get_power_info(device_handle)['average_socket_power'] // 1000.0)
250
+ return (
251
+ amdsmi.amdsmi_get_power_info(device_handle)[
252
+ "average_socket_power"
253
+ ]
254
+ // 1000.0
255
+ )
192
256
  elif metric_name == "power_limit":
193
257
  # pylint: disable=line-too-long
194
- return (amdsmi.amdsmi_get_power_info(device_handle)['power_limit'] // 1000.0)
258
+ return (
259
+ amdsmi.amdsmi_get_power_info(device_handle)[
260
+ "power_limit"
261
+ ]
262
+ // 1000.0
263
+ )
195
264
  except Exception as e:
196
- logger.error("Error collecting metric %s for AMD GPU %d: %s", metric_name,
197
- amdsmi.amdsmi_get_xgmi_info(device_handle)['index'], e)
265
+ logger.error(
266
+ "Error collecting metric %s for AMD GPU %d: %s",
267
+ metric_name,
268
+ amdsmi.amdsmi_get_xgmi_info(device_handle)["index"],
269
+ e,
270
+ )
198
271
  return 0
199
272
 
200
273
  attributes = {
@@ -202,12 +275,20 @@ class GPUInstrumentor(BaseInstrumentor):
202
275
  SERVICE_NAME: application_name,
203
276
  DEPLOYMENT_ENVIRONMENT: environment,
204
277
  # pylint: disable=line-too-long
205
- SemanticConvention.GPU_INDEX: amdsmi.amdsmi_get_xgmi_info(device_handle)['index'],
278
+ SemanticConvention.GPU_INDEX: amdsmi.amdsmi_get_xgmi_info(
279
+ device_handle
280
+ )["index"],
206
281
  # pylint: disable=line-too-long
207
- SemanticConvention.GPU_UUID: amdsmi.amdsmi_get_gpu_asic_info(device_handle)['market_name'],
208
- SemanticConvention.GPU_NAME: amdsmi.amdsmi_get_device_name(device_handle)
282
+ SemanticConvention.GPU_UUID: amdsmi.amdsmi_get_gpu_asic_info(
283
+ device_handle
284
+ )["market_name"],
285
+ SemanticConvention.GPU_NAME: amdsmi.amdsmi_get_device_name(
286
+ device_handle
287
+ ),
209
288
  }
210
- yield Observation(get_metric_value(device_handle, metric_name), attributes)
289
+ yield Observation(
290
+ get_metric_value(device_handle, metric_name), attributes
291
+ )
211
292
 
212
293
  except Exception as e:
213
294
  logger.error("Error in AMD GPU metrics collection: %s", e)
@@ -10,6 +10,7 @@ from openlit.instrumentation.groq.async_groq import async_chat
10
10
 
11
11
  _instruments = ("groq >= 0.5.0",)
12
12
 
13
+
13
14
  class GroqInstrumentor(BaseInstrumentor):
14
15
  """
15
16
  An instrumentor for Groq client library.
@@ -32,16 +33,32 @@ class GroqInstrumentor(BaseInstrumentor):
32
33
  wrap_function_wrapper(
33
34
  "groq.resources.chat.completions",
34
35
  "Completions.create",
35
- chat(version, environment, application_name,
36
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
36
+ chat(
37
+ version,
38
+ environment,
39
+ application_name,
40
+ tracer,
41
+ pricing_info,
42
+ capture_message_content,
43
+ metrics,
44
+ disable_metrics,
45
+ ),
37
46
  )
38
47
 
39
48
  # Chat completions
40
49
  wrap_function_wrapper(
41
50
  "groq.resources.chat.completions",
42
51
  "AsyncCompletions.create",
43
- async_chat(version, environment, application_name,
44
- tracer, pricing_info, capture_message_content, metrics, disable_metrics),
52
+ async_chat(
53
+ version,
54
+ environment,
55
+ application_name,
56
+ tracer,
57
+ pricing_info,
58
+ capture_message_content,
59
+ metrics,
60
+ disable_metrics,
61
+ ),
45
62
  )
46
63
 
47
64
  def _uninstrument(self, **kwargs):
@@ -4,19 +4,25 @@ Module for monitoring Groq API calls (async version).
4
4
 
5
5
  import time
6
6
  from opentelemetry.trace import SpanKind
7
- from openlit.__helpers import (
8
- handle_exception,
9
- set_server_address_and_port
10
- )
7
+ from openlit.__helpers import handle_exception, set_server_address_and_port
11
8
  from openlit.instrumentation.groq.utils import (
12
9
  process_chunk,
13
10
  process_streaming_chat_response,
14
- process_chat_response
11
+ process_chat_response,
15
12
  )
16
13
  from openlit.semcov import SemanticConvention
17
14
 
18
- def async_chat(version, environment, application_name, tracer, pricing_info,
19
- capture_message_content, metrics, disable_metrics):
15
+
16
+ def async_chat(
17
+ version,
18
+ environment,
19
+ application_name,
20
+ tracer,
21
+ pricing_info,
22
+ capture_message_content,
23
+ metrics,
24
+ disable_metrics,
25
+ ):
20
26
  """
21
27
  Generates a telemetry wrapper for GenAI function call
22
28
  """
@@ -27,15 +33,15 @@ def async_chat(version, environment, application_name, tracer, pricing_info,
27
33
  """
28
34
 
29
35
  def __init__(
30
- self,
31
- wrapped,
32
- span,
33
- span_name,
34
- kwargs,
35
- server_address,
36
- server_port,
37
- **args,
38
- ):
36
+ self,
37
+ wrapped,
38
+ span,
39
+ span_name,
40
+ kwargs,
41
+ server_address,
42
+ server_port,
43
+ **args,
44
+ ):
39
45
  self.__wrapped__ = wrapped
40
46
  self._span = span
41
47
  self._span_name = span_name
@@ -78,7 +84,9 @@ def async_chat(version, environment, application_name, tracer, pricing_info,
78
84
  return chunk
79
85
  except StopAsyncIteration:
80
86
  try:
81
- with tracer.start_as_current_span(self._span_name, kind= SpanKind.CLIENT) as self._span:
87
+ with tracer.start_as_current_span(
88
+ self._span_name, kind=SpanKind.CLIENT
89
+ ) as self._span:
82
90
  process_streaming_chat_response(
83
91
  self,
84
92
  pricing_info=pricing_info,
@@ -87,7 +95,7 @@ def async_chat(version, environment, application_name, tracer, pricing_info,
87
95
  metrics=metrics,
88
96
  capture_message_content=capture_message_content,
89
97
  disable_metrics=disable_metrics,
90
- version=version
98
+ version=version,
91
99
  )
92
100
 
93
101
  except Exception as e:
@@ -101,7 +109,9 @@ def async_chat(version, environment, application_name, tracer, pricing_info,
101
109
  """
102
110
  # Check if streaming is enabled for the API call
103
111
  streaming = kwargs.get("stream", False)
104
- server_address, server_port = set_server_address_and_port(instance, "api.groq.com", 443)
112
+ server_address, server_port = set_server_address_and_port(
113
+ instance, "api.groq.com", 443
114
+ )
105
115
  request_model = kwargs.get("model", "mixtral-8x7b-32768")
106
116
 
107
117
  span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
@@ -110,7 +120,9 @@ def async_chat(version, environment, application_name, tracer, pricing_info,
110
120
  # Special handling for streaming response
111
121
  awaited_wrapped = await wrapped(*args, **kwargs)
112
122
  span = tracer.start_span(span_name, kind=SpanKind.CLIENT)
113
- return TracedAsyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)
123
+ return TracedAsyncStream(
124
+ awaited_wrapped, span, span_name, kwargs, server_address, server_port
125
+ )
114
126
  else:
115
127
  # Handling for non-streaming responses
116
128
  with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
@@ -132,7 +144,7 @@ def async_chat(version, environment, application_name, tracer, pricing_info,
132
144
  capture_message_content=capture_message_content,
133
145
  disable_metrics=disable_metrics,
134
146
  version=version,
135
- **kwargs
147
+ **kwargs,
136
148
  )
137
149
 
138
150
  except Exception as e:
@@ -4,19 +4,25 @@ Module for monitoring Groq API calls.
4
4
 
5
5
  import time
6
6
  from opentelemetry.trace import SpanKind
7
- from openlit.__helpers import (
8
- handle_exception,
9
- set_server_address_and_port
10
- )
7
+ from openlit.__helpers import handle_exception, set_server_address_and_port
11
8
  from openlit.instrumentation.groq.utils import (
12
9
  process_chunk,
13
10
  process_streaming_chat_response,
14
- process_chat_response
11
+ process_chat_response,
15
12
  )
16
13
  from openlit.semcov import SemanticConvention
17
14
 
18
- def chat(version, environment, application_name, tracer, pricing_info,
19
- capture_message_content, metrics, disable_metrics):
15
+
16
+ def chat(
17
+ version,
18
+ environment,
19
+ application_name,
20
+ tracer,
21
+ pricing_info,
22
+ capture_message_content,
23
+ metrics,
24
+ disable_metrics,
25
+ ):
20
26
  """
21
27
  Generates a telemetry wrapper for GenAI function call
22
28
  """
@@ -27,15 +33,15 @@ def chat(version, environment, application_name, tracer, pricing_info,
27
33
  """
28
34
 
29
35
  def __init__(
30
- self,
31
- wrapped,
32
- span,
33
- span_name,
34
- kwargs,
35
- server_address,
36
- server_port,
37
- **args,
38
- ):
36
+ self,
37
+ wrapped,
38
+ span,
39
+ span_name,
40
+ kwargs,
41
+ server_address,
42
+ server_port,
43
+ **args,
44
+ ):
39
45
  self.__wrapped__ = wrapped
40
46
  self._span = span
41
47
  self._span_name = span_name
@@ -78,7 +84,9 @@ def chat(version, environment, application_name, tracer, pricing_info,
78
84
  return chunk
79
85
  except StopIteration:
80
86
  try:
81
- with tracer.start_as_current_span(self._span_name, kind= SpanKind.CLIENT) as self._span:
87
+ with tracer.start_as_current_span(
88
+ self._span_name, kind=SpanKind.CLIENT
89
+ ) as self._span:
82
90
  process_streaming_chat_response(
83
91
  self,
84
92
  pricing_info=pricing_info,
@@ -87,7 +95,7 @@ def chat(version, environment, application_name, tracer, pricing_info,
87
95
  metrics=metrics,
88
96
  capture_message_content=capture_message_content,
89
97
  disable_metrics=disable_metrics,
90
- version=version
98
+ version=version,
91
99
  )
92
100
 
93
101
  except Exception as e:
@@ -101,7 +109,9 @@ def chat(version, environment, application_name, tracer, pricing_info,
101
109
  """
102
110
  # Check if streaming is enabled for the API call
103
111
  streaming = kwargs.get("stream", False)
104
- server_address, server_port = set_server_address_and_port(instance, "api.groq.com", 443)
112
+ server_address, server_port = set_server_address_and_port(
113
+ instance, "api.groq.com", 443
114
+ )
105
115
  request_model = kwargs.get("model", "mixtral-8x7b-32768")
106
116
 
107
117
  span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
@@ -110,7 +120,9 @@ def chat(version, environment, application_name, tracer, pricing_info,
110
120
  # Special handling for streaming response
111
121
  awaited_wrapped = wrapped(*args, **kwargs)
112
122
  span = tracer.start_span(span_name, kind=SpanKind.CLIENT)
113
- return TracedSyncStream(awaited_wrapped, span, span_name, kwargs, server_address, server_port)
123
+ return TracedSyncStream(
124
+ awaited_wrapped, span, span_name, kwargs, server_address, server_port
125
+ )
114
126
  else:
115
127
  # Handling for non-streaming responses
116
128
  with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
@@ -132,7 +144,7 @@ def chat(version, environment, application_name, tracer, pricing_info,
132
144
  capture_message_content=capture_message_content,
133
145
  disable_metrics=disable_metrics,
134
146
  version=version,
135
- **kwargs
147
+ **kwargs,
136
148
  )
137
149
 
138
150
  except Exception as e: