openlit 1.33.19__py3-none-any.whl → 1.33.21__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.
- openlit/__helpers.py +64 -7
- openlit/__init__.py +3 -3
- openlit/evals/utils.py +7 -7
- openlit/guard/utils.py +7 -7
- openlit/instrumentation/ag2/ag2.py +24 -24
- openlit/instrumentation/ai21/ai21.py +3 -3
- openlit/instrumentation/ai21/async_ai21.py +3 -3
- openlit/instrumentation/ai21/utils.py +59 -59
- openlit/instrumentation/anthropic/anthropic.py +2 -2
- openlit/instrumentation/anthropic/async_anthropic.py +2 -2
- openlit/instrumentation/anthropic/utils.py +34 -34
- openlit/instrumentation/assemblyai/assemblyai.py +24 -24
- openlit/instrumentation/astra/astra.py +3 -3
- openlit/instrumentation/astra/async_astra.py +3 -3
- openlit/instrumentation/astra/utils.py +39 -39
- openlit/instrumentation/azure_ai_inference/async_azure_ai_inference.py +2 -2
- openlit/instrumentation/azure_ai_inference/azure_ai_inference.py +2 -2
- openlit/instrumentation/azure_ai_inference/utils.py +36 -36
- openlit/instrumentation/bedrock/bedrock.py +2 -2
- openlit/instrumentation/bedrock/utils.py +35 -35
- openlit/instrumentation/chroma/chroma.py +57 -57
- openlit/instrumentation/cohere/async_cohere.py +88 -88
- openlit/instrumentation/cohere/cohere.py +88 -88
- openlit/instrumentation/controlflow/controlflow.py +15 -15
- openlit/instrumentation/crawl4ai/async_crawl4ai.py +14 -14
- openlit/instrumentation/crawl4ai/crawl4ai.py +14 -14
- openlit/instrumentation/crewai/crewai.py +22 -22
- openlit/instrumentation/dynamiq/dynamiq.py +19 -19
- openlit/instrumentation/elevenlabs/async_elevenlabs.py +24 -25
- openlit/instrumentation/elevenlabs/elevenlabs.py +23 -25
- openlit/instrumentation/embedchain/embedchain.py +15 -15
- openlit/instrumentation/firecrawl/firecrawl.py +10 -10
- openlit/instrumentation/google_ai_studio/async_google_ai_studio.py +33 -33
- openlit/instrumentation/google_ai_studio/google_ai_studio.py +33 -33
- openlit/instrumentation/gpt4all/gpt4all.py +78 -78
- openlit/instrumentation/gpu/__init__.py +8 -8
- openlit/instrumentation/groq/async_groq.py +74 -74
- openlit/instrumentation/groq/groq.py +74 -74
- openlit/instrumentation/haystack/haystack.py +6 -6
- openlit/instrumentation/julep/async_julep.py +14 -14
- openlit/instrumentation/julep/julep.py +14 -14
- openlit/instrumentation/langchain/async_langchain.py +39 -39
- openlit/instrumentation/langchain/langchain.py +39 -39
- openlit/instrumentation/letta/letta.py +26 -26
- openlit/instrumentation/litellm/async_litellm.py +94 -94
- openlit/instrumentation/litellm/litellm.py +94 -94
- openlit/instrumentation/llamaindex/llamaindex.py +7 -7
- openlit/instrumentation/mem0/mem0.py +13 -13
- openlit/instrumentation/milvus/milvus.py +47 -47
- openlit/instrumentation/mistral/async_mistral.py +88 -88
- openlit/instrumentation/mistral/mistral.py +88 -88
- openlit/instrumentation/multion/async_multion.py +21 -21
- openlit/instrumentation/multion/multion.py +21 -21
- openlit/instrumentation/ollama/__init__.py +47 -34
- openlit/instrumentation/ollama/async_ollama.py +7 -5
- openlit/instrumentation/ollama/ollama.py +7 -5
- openlit/instrumentation/ollama/utils.py +58 -54
- openlit/instrumentation/openai/async_openai.py +225 -225
- openlit/instrumentation/openai/openai.py +225 -225
- openlit/instrumentation/openai_agents/openai_agents.py +11 -11
- openlit/instrumentation/phidata/phidata.py +15 -15
- openlit/instrumentation/pinecone/pinecone.py +43 -43
- openlit/instrumentation/premai/premai.py +86 -86
- openlit/instrumentation/qdrant/async_qdrant.py +95 -95
- openlit/instrumentation/qdrant/qdrant.py +99 -99
- openlit/instrumentation/reka/async_reka.py +33 -33
- openlit/instrumentation/reka/reka.py +33 -33
- openlit/instrumentation/together/async_together.py +90 -90
- openlit/instrumentation/together/together.py +90 -90
- openlit/instrumentation/transformers/__init__.py +11 -7
- openlit/instrumentation/transformers/transformers.py +32 -168
- openlit/instrumentation/transformers/utils.py +183 -0
- openlit/instrumentation/vertexai/async_vertexai.py +64 -64
- openlit/instrumentation/vertexai/vertexai.py +64 -64
- openlit/instrumentation/vllm/vllm.py +24 -24
- openlit/otel/metrics.py +11 -11
- openlit/semcov/__init__.py +3 -3
- {openlit-1.33.19.dist-info → openlit-1.33.21.dist-info}/METADATA +8 -8
- openlit-1.33.21.dist-info/RECORD +132 -0
- {openlit-1.33.19.dist-info → openlit-1.33.21.dist-info}/WHEEL +1 -1
- openlit-1.33.19.dist-info/RECORD +0 -131
- {openlit-1.33.19.dist-info → openlit-1.33.21.dist-info}/LICENSE +0 -0
@@ -15,7 +15,7 @@ from openlit.__helpers import (
|
|
15
15
|
create_metrics_attributes,
|
16
16
|
set_server_address_and_port
|
17
17
|
)
|
18
|
-
from openlit.semcov import
|
18
|
+
from openlit.semcov import SemanticConvention
|
19
19
|
|
20
20
|
# Initialize logger for logging potential issues and operations
|
21
21
|
logger = logging.getLogger(__name__)
|
@@ -157,49 +157,49 @@ def async_chat(version, environment, application_name,
|
|
157
157
|
|
158
158
|
# Set Span attributes (OTel Semconv)
|
159
159
|
self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
160
|
-
self._span.set_attribute(
|
161
|
-
|
162
|
-
self._span.set_attribute(
|
163
|
-
|
164
|
-
self._span.set_attribute(
|
160
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
161
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
162
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
163
|
+
SemanticConvention.GEN_AI_SYSTEM_GROQ)
|
164
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
165
165
|
request_model)
|
166
|
-
self._span.set_attribute(
|
166
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED,
|
167
167
|
self._kwargs.get("seed", ""))
|
168
|
-
self._span.set_attribute(
|
168
|
+
self._span.set_attribute(SemanticConvention.SERVER_PORT,
|
169
169
|
self._server_port)
|
170
|
-
self._span.set_attribute(
|
170
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
171
171
|
self._kwargs.get("frequency_penalty", 0.0))
|
172
|
-
self._span.set_attribute(
|
172
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
173
173
|
self._kwargs.get("max_completion_tokens", -1))
|
174
|
-
self._span.set_attribute(
|
174
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
175
175
|
self._kwargs.get("presence_penalty", 0.0))
|
176
|
-
self._span.set_attribute(
|
176
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
177
177
|
self._kwargs.get("stop", []))
|
178
|
-
self._span.set_attribute(
|
178
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
179
179
|
self._kwargs.get("temperature", 1.0))
|
180
|
-
self._span.set_attribute(
|
180
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
181
181
|
self._kwargs.get("top_p", 1.0))
|
182
|
-
self._span.set_attribute(
|
182
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON,
|
183
183
|
[self._finish_reason])
|
184
|
-
self._span.set_attribute(
|
184
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
185
185
|
self._response_id)
|
186
|
-
self._span.set_attribute(
|
186
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
187
187
|
self._response_model)
|
188
|
-
self._span.set_attribute(
|
188
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
189
189
|
self._input_tokens)
|
190
|
-
self._span.set_attribute(
|
190
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
191
191
|
self._output_tokens)
|
192
|
-
self._span.set_attribute(
|
192
|
+
self._span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
193
193
|
self._server_address)
|
194
|
-
self._span.set_attribute(
|
194
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SERVICE_TIER,
|
195
195
|
self._kwargs.get("service_tier", "on_demand"))
|
196
|
-
self._span.set_attribute(
|
196
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT,
|
197
197
|
self._system_fingerprint)
|
198
198
|
if isinstance(self._llmresponse, str):
|
199
|
-
self._span.set_attribute(
|
199
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
200
200
|
"text")
|
201
201
|
else:
|
202
|
-
self._span.set_attribute(
|
202
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
203
203
|
"json")
|
204
204
|
|
205
205
|
# Set Span attributes (Extra)
|
@@ -207,31 +207,31 @@ def async_chat(version, environment, application_name,
|
|
207
207
|
environment)
|
208
208
|
self._span.set_attribute(SERVICE_NAME,
|
209
209
|
application_name)
|
210
|
-
self._span.set_attribute(
|
210
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
211
211
|
self._kwargs.get("user", ""))
|
212
|
-
self._span.set_attribute(
|
212
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
213
213
|
True)
|
214
|
-
self._span.set_attribute(
|
214
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
215
215
|
self._input_tokens + self._output_tokens)
|
216
|
-
self._span.set_attribute(
|
216
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
217
217
|
cost)
|
218
|
-
self._span.set_attribute(
|
218
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TBT,
|
219
219
|
self._tbt)
|
220
|
-
self._span.set_attribute(
|
220
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
221
221
|
self._ttft)
|
222
|
-
self._span.set_attribute(
|
222
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
223
223
|
version)
|
224
224
|
if capture_message_content:
|
225
225
|
self._span.add_event(
|
226
|
-
name=
|
226
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
227
227
|
attributes={
|
228
|
-
|
228
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
229
229
|
},
|
230
230
|
)
|
231
231
|
self._span.add_event(
|
232
|
-
name=
|
232
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
233
233
|
attributes={
|
234
|
-
|
234
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: self._llmresponse,
|
235
235
|
},
|
236
236
|
)
|
237
237
|
self._span.set_status(Status(StatusCode.OK))
|
@@ -240,8 +240,8 @@ def async_chat(version, environment, application_name,
|
|
240
240
|
attributes = create_metrics_attributes(
|
241
241
|
service_name=application_name,
|
242
242
|
deployment_environment=environment,
|
243
|
-
operation=
|
244
|
-
system=
|
243
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
244
|
+
system=SemanticConvention.GEN_AI_SYSTEM_GROQ,
|
245
245
|
request_model=request_model,
|
246
246
|
server_address=self._server_address,
|
247
247
|
server_port=self._server_port,
|
@@ -294,7 +294,7 @@ def async_chat(version, environment, application_name,
|
|
294
294
|
server_address, server_port = set_server_address_and_port(instance, "api.groq.com", 443)
|
295
295
|
request_model = kwargs.get("model", "gpt-4o")
|
296
296
|
|
297
|
-
span_name = f"{
|
297
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
298
298
|
|
299
299
|
# pylint: disable=no-else-return
|
300
300
|
if streaming:
|
@@ -342,41 +342,41 @@ def async_chat(version, environment, application_name,
|
|
342
342
|
|
343
343
|
# Set base span attribues (OTel Semconv)
|
344
344
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
345
|
-
span.set_attribute(
|
346
|
-
|
347
|
-
span.set_attribute(
|
348
|
-
|
349
|
-
span.set_attribute(
|
345
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
346
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
347
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
348
|
+
SemanticConvention.GEN_AI_SYSTEM_GROQ)
|
349
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
350
350
|
request_model)
|
351
|
-
span.set_attribute(
|
351
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED,
|
352
352
|
kwargs.get("seed", ""))
|
353
|
-
span.set_attribute(
|
353
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
354
354
|
server_port)
|
355
|
-
span.set_attribute(
|
355
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
356
356
|
kwargs.get("frequency_penalty", 0.0))
|
357
|
-
span.set_attribute(
|
357
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
358
358
|
kwargs.get("max_completion_tokens", -1))
|
359
|
-
span.set_attribute(
|
359
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
360
360
|
kwargs.get("presence_penalty", 0.0))
|
361
|
-
span.set_attribute(
|
361
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
362
362
|
kwargs.get("stop", []))
|
363
|
-
span.set_attribute(
|
363
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
364
364
|
kwargs.get("temperature", 1.0))
|
365
|
-
span.set_attribute(
|
365
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
366
366
|
kwargs.get("top_p", 1.0))
|
367
|
-
span.set_attribute(
|
367
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
368
368
|
response_dict.get("id"))
|
369
|
-
span.set_attribute(
|
369
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
370
370
|
response_dict.get('model'))
|
371
|
-
span.set_attribute(
|
371
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
372
372
|
input_tokens)
|
373
|
-
span.set_attribute(
|
373
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
374
374
|
output_tokens)
|
375
|
-
span.set_attribute(
|
375
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
376
376
|
server_address)
|
377
|
-
span.set_attribute(
|
377
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SERVICE_TIER,
|
378
378
|
kwargs.get("service_tier", "on_demand"))
|
379
|
-
span.set_attribute(
|
379
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT,
|
380
380
|
response_dict.get('system_fingerprint'))
|
381
381
|
|
382
382
|
# Set base span attribues (Extras)
|
@@ -384,46 +384,46 @@ def async_chat(version, environment, application_name,
|
|
384
384
|
environment)
|
385
385
|
span.set_attribute(SERVICE_NAME,
|
386
386
|
application_name)
|
387
|
-
span.set_attribute(
|
387
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
388
388
|
kwargs.get("user", ""))
|
389
|
-
span.set_attribute(
|
389
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
390
390
|
False)
|
391
|
-
span.set_attribute(
|
391
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
392
392
|
input_tokens + output_tokens)
|
393
|
-
span.set_attribute(
|
393
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
394
394
|
cost)
|
395
|
-
span.set_attribute(
|
395
|
+
span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
396
396
|
end_time - start_time)
|
397
|
-
span.set_attribute(
|
397
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
398
398
|
version)
|
399
399
|
if capture_message_content:
|
400
400
|
span.add_event(
|
401
|
-
name=
|
401
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
402
402
|
attributes={
|
403
|
-
|
403
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
404
404
|
},
|
405
405
|
)
|
406
406
|
|
407
407
|
for i in range(kwargs.get('n',1)):
|
408
|
-
span.set_attribute(
|
408
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON,
|
409
409
|
[response_dict.get('choices')[i].get('finish_reason')])
|
410
410
|
if capture_message_content:
|
411
411
|
span.add_event(
|
412
|
-
name=
|
412
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
413
413
|
attributes={
|
414
414
|
# pylint: disable=line-too-long
|
415
|
-
|
415
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: str(response_dict.get('choices')[i].get('message').get('content')),
|
416
416
|
},
|
417
417
|
)
|
418
418
|
if kwargs.get('tools'):
|
419
|
-
span.set_attribute(
|
419
|
+
span.set_attribute(SemanticConvention.GEN_AI_TOOL_CALLS,
|
420
420
|
str(response_dict.get('choices')[i].get('message').get('tool_calls')))
|
421
421
|
|
422
422
|
if isinstance(response_dict.get('choices')[i].get('message').get('content'), str):
|
423
|
-
span.set_attribute(
|
423
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
424
424
|
"text")
|
425
425
|
elif response_dict.get('choices')[i].get('message').get('content') is not None:
|
426
|
-
span.set_attribute(
|
426
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
427
427
|
"json")
|
428
428
|
|
429
429
|
span.set_status(Status(StatusCode.OK))
|
@@ -432,8 +432,8 @@ def async_chat(version, environment, application_name,
|
|
432
432
|
attributes = create_metrics_attributes(
|
433
433
|
service_name=application_name,
|
434
434
|
deployment_environment=environment,
|
435
|
-
operation=
|
436
|
-
system=
|
435
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
436
|
+
system=SemanticConvention.GEN_AI_SYSTEM_GROQ,
|
437
437
|
request_model=request_model,
|
438
438
|
server_address=server_address,
|
439
439
|
server_port=server_port,
|
@@ -15,7 +15,7 @@ from openlit.__helpers import (
|
|
15
15
|
create_metrics_attributes,
|
16
16
|
set_server_address_and_port
|
17
17
|
)
|
18
|
-
from openlit.semcov import
|
18
|
+
from openlit.semcov import SemanticConvention
|
19
19
|
|
20
20
|
# Initialize logger for logging potential issues and operations
|
21
21
|
logger = logging.getLogger(__name__)
|
@@ -157,49 +157,49 @@ def chat(version, environment, application_name,
|
|
157
157
|
|
158
158
|
# Set Span attributes (OTel Semconv)
|
159
159
|
self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
160
|
-
self._span.set_attribute(
|
161
|
-
|
162
|
-
self._span.set_attribute(
|
163
|
-
|
164
|
-
self._span.set_attribute(
|
160
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
161
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
162
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
163
|
+
SemanticConvention.GEN_AI_SYSTEM_GROQ)
|
164
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
165
165
|
request_model)
|
166
|
-
self._span.set_attribute(
|
166
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED,
|
167
167
|
self._kwargs.get("seed", ""))
|
168
|
-
self._span.set_attribute(
|
168
|
+
self._span.set_attribute(SemanticConvention.SERVER_PORT,
|
169
169
|
self._server_port)
|
170
|
-
self._span.set_attribute(
|
170
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
171
171
|
self._kwargs.get("frequency_penalty", 0.0))
|
172
|
-
self._span.set_attribute(
|
172
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
173
173
|
self._kwargs.get("max_completion_tokens", -1))
|
174
|
-
self._span.set_attribute(
|
174
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
175
175
|
self._kwargs.get("presence_penalty", 0.0))
|
176
|
-
self._span.set_attribute(
|
176
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
177
177
|
self._kwargs.get("stop", []))
|
178
|
-
self._span.set_attribute(
|
178
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
179
179
|
self._kwargs.get("temperature", 1.0))
|
180
|
-
self._span.set_attribute(
|
180
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
181
181
|
self._kwargs.get("top_p", 1.0))
|
182
|
-
self._span.set_attribute(
|
182
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON,
|
183
183
|
[self._finish_reason])
|
184
|
-
self._span.set_attribute(
|
184
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
185
185
|
self._response_id)
|
186
|
-
self._span.set_attribute(
|
186
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
187
187
|
self._response_model)
|
188
|
-
self._span.set_attribute(
|
188
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
189
189
|
self._input_tokens)
|
190
|
-
self._span.set_attribute(
|
190
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
191
191
|
self._output_tokens)
|
192
|
-
self._span.set_attribute(
|
192
|
+
self._span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
193
193
|
self._server_address)
|
194
|
-
self._span.set_attribute(
|
194
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SERVICE_TIER,
|
195
195
|
self._kwargs.get("service_tier", "on_demand"))
|
196
|
-
self._span.set_attribute(
|
196
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT,
|
197
197
|
self._system_fingerprint)
|
198
198
|
if isinstance(self._llmresponse, str):
|
199
|
-
self._span.set_attribute(
|
199
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
200
200
|
"text")
|
201
201
|
else:
|
202
|
-
self._span.set_attribute(
|
202
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
203
203
|
"json")
|
204
204
|
|
205
205
|
# Set Span attributes (Extra)
|
@@ -207,31 +207,31 @@ def chat(version, environment, application_name,
|
|
207
207
|
environment)
|
208
208
|
self._span.set_attribute(SERVICE_NAME,
|
209
209
|
application_name)
|
210
|
-
self._span.set_attribute(
|
210
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
211
211
|
self._kwargs.get("user", ""))
|
212
|
-
self._span.set_attribute(
|
212
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
213
213
|
True)
|
214
|
-
self._span.set_attribute(
|
214
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
215
215
|
self._input_tokens + self._output_tokens)
|
216
|
-
self._span.set_attribute(
|
216
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
217
217
|
cost)
|
218
|
-
self._span.set_attribute(
|
218
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TBT,
|
219
219
|
self._tbt)
|
220
|
-
self._span.set_attribute(
|
220
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
221
221
|
self._ttft)
|
222
|
-
self._span.set_attribute(
|
222
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
223
223
|
version)
|
224
224
|
if capture_message_content:
|
225
225
|
self._span.add_event(
|
226
|
-
name=
|
226
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
227
227
|
attributes={
|
228
|
-
|
228
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
229
229
|
},
|
230
230
|
)
|
231
231
|
self._span.add_event(
|
232
|
-
name=
|
232
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
233
233
|
attributes={
|
234
|
-
|
234
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: self._llmresponse,
|
235
235
|
},
|
236
236
|
)
|
237
237
|
self._span.set_status(Status(StatusCode.OK))
|
@@ -240,8 +240,8 @@ def chat(version, environment, application_name,
|
|
240
240
|
attributes = create_metrics_attributes(
|
241
241
|
service_name=application_name,
|
242
242
|
deployment_environment=environment,
|
243
|
-
operation=
|
244
|
-
system=
|
243
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
244
|
+
system=SemanticConvention.GEN_AI_SYSTEM_GROQ,
|
245
245
|
request_model=request_model,
|
246
246
|
server_address=self._server_address,
|
247
247
|
server_port=self._server_port,
|
@@ -294,7 +294,7 @@ def chat(version, environment, application_name,
|
|
294
294
|
server_address, server_port = set_server_address_and_port(instance, "api.groq.com", 443)
|
295
295
|
request_model = kwargs.get("model", "gpt-4o")
|
296
296
|
|
297
|
-
span_name = f"{
|
297
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
298
298
|
|
299
299
|
# pylint: disable=no-else-return
|
300
300
|
if streaming:
|
@@ -342,41 +342,41 @@ def chat(version, environment, application_name,
|
|
342
342
|
|
343
343
|
# Set base span attribues (OTel Semconv)
|
344
344
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
345
|
-
span.set_attribute(
|
346
|
-
|
347
|
-
span.set_attribute(
|
348
|
-
|
349
|
-
span.set_attribute(
|
345
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
346
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
347
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
348
|
+
SemanticConvention.GEN_AI_SYSTEM_GROQ)
|
349
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
350
350
|
request_model)
|
351
|
-
span.set_attribute(
|
351
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED,
|
352
352
|
kwargs.get("seed", ""))
|
353
|
-
span.set_attribute(
|
353
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
354
354
|
server_port)
|
355
|
-
span.set_attribute(
|
355
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
356
356
|
kwargs.get("frequency_penalty", 0.0))
|
357
|
-
span.set_attribute(
|
357
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
358
358
|
kwargs.get("max_completion_tokens", -1))
|
359
|
-
span.set_attribute(
|
359
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
360
360
|
kwargs.get("presence_penalty", 0.0))
|
361
|
-
span.set_attribute(
|
361
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
362
362
|
kwargs.get("stop", []))
|
363
|
-
span.set_attribute(
|
363
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
364
364
|
kwargs.get("temperature", 1.0))
|
365
|
-
span.set_attribute(
|
365
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
366
366
|
kwargs.get("top_p", 1.0))
|
367
|
-
span.set_attribute(
|
367
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
368
368
|
response_dict.get("id"))
|
369
|
-
span.set_attribute(
|
369
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
370
370
|
response_dict.get('model'))
|
371
|
-
span.set_attribute(
|
371
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
372
372
|
input_tokens)
|
373
|
-
span.set_attribute(
|
373
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
374
374
|
output_tokens)
|
375
|
-
span.set_attribute(
|
375
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
376
376
|
server_address)
|
377
|
-
span.set_attribute(
|
377
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SERVICE_TIER,
|
378
378
|
kwargs.get("service_tier", "on_demand"))
|
379
|
-
span.set_attribute(
|
379
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT,
|
380
380
|
response_dict.get('system_fingerprint'))
|
381
381
|
|
382
382
|
# Set base span attribues (Extras)
|
@@ -384,46 +384,46 @@ def chat(version, environment, application_name,
|
|
384
384
|
environment)
|
385
385
|
span.set_attribute(SERVICE_NAME,
|
386
386
|
application_name)
|
387
|
-
span.set_attribute(
|
387
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
388
388
|
kwargs.get("user", ""))
|
389
|
-
span.set_attribute(
|
389
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
390
390
|
False)
|
391
|
-
span.set_attribute(
|
391
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
392
392
|
input_tokens + output_tokens)
|
393
|
-
span.set_attribute(
|
393
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
394
394
|
cost)
|
395
|
-
span.set_attribute(
|
395
|
+
span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
396
396
|
end_time - start_time)
|
397
|
-
span.set_attribute(
|
397
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
398
398
|
version)
|
399
399
|
if capture_message_content:
|
400
400
|
span.add_event(
|
401
|
-
name=
|
401
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
402
402
|
attributes={
|
403
|
-
|
403
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
404
404
|
},
|
405
405
|
)
|
406
406
|
|
407
407
|
for i in range(kwargs.get('n',1)):
|
408
|
-
span.set_attribute(
|
408
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON,
|
409
409
|
[response_dict.get('choices')[i].get('finish_reason')])
|
410
410
|
if capture_message_content:
|
411
411
|
span.add_event(
|
412
|
-
name=
|
412
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
413
413
|
attributes={
|
414
414
|
# pylint: disable=line-too-long
|
415
|
-
|
415
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: str(response_dict.get('choices')[i].get('message').get('content')),
|
416
416
|
},
|
417
417
|
)
|
418
418
|
if kwargs.get('tools'):
|
419
|
-
span.set_attribute(
|
419
|
+
span.set_attribute(SemanticConvention.GEN_AI_TOOL_CALLS,
|
420
420
|
str(response_dict.get('choices')[i].get('message').get('tool_calls')))
|
421
421
|
|
422
422
|
if isinstance(response_dict.get('choices')[i].get('message').get('content'), str):
|
423
|
-
span.set_attribute(
|
423
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
424
424
|
"text")
|
425
425
|
elif response_dict.get('choices')[i].get('message').get('content') is not None:
|
426
|
-
span.set_attribute(
|
426
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
427
427
|
"json")
|
428
428
|
|
429
429
|
span.set_status(Status(StatusCode.OK))
|
@@ -432,8 +432,8 @@ def chat(version, environment, application_name,
|
|
432
432
|
attributes = create_metrics_attributes(
|
433
433
|
service_name=application_name,
|
434
434
|
deployment_environment=environment,
|
435
|
-
operation=
|
436
|
-
system=
|
435
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
436
|
+
system=SemanticConvention.GEN_AI_SYSTEM_GROQ,
|
437
437
|
request_model=request_model,
|
438
438
|
server_address=server_address,
|
439
439
|
server_port=server_port,
|
@@ -7,7 +7,7 @@ import logging
|
|
7
7
|
from opentelemetry.trace import SpanKind, Status, StatusCode
|
8
8
|
from opentelemetry.sdk.resources import SERVICE_NAME, TELEMETRY_SDK_NAME, DEPLOYMENT_ENVIRONMENT
|
9
9
|
from openlit.__helpers import handle_exception
|
10
|
-
from openlit.semcov import
|
10
|
+
from openlit.semcov import SemanticConvention
|
11
11
|
|
12
12
|
# Initialize logger for logging potential issues and operations
|
13
13
|
logger = logging.getLogger(__name__)
|
@@ -59,14 +59,14 @@ def join_data(gen_ai_endpoint, version, environment, application_name,
|
|
59
59
|
|
60
60
|
try:
|
61
61
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
62
|
-
span.set_attribute(
|
63
|
-
|
64
|
-
span.set_attribute(
|
62
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
63
|
+
SemanticConvention.GEN_AI_SYSTEM_HAYSTACK)
|
64
|
+
span.set_attribute(SemanticConvention.GEN_AI_ENDPOINT,
|
65
65
|
gen_ai_endpoint)
|
66
66
|
span.set_attribute(DEPLOYMENT_ENVIRONMENT,
|
67
67
|
environment)
|
68
|
-
span.set_attribute(
|
69
|
-
|
68
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
69
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_FRAMEWORK)
|
70
70
|
span.set_attribute(SERVICE_NAME,
|
71
71
|
application_name)
|
72
72
|
span.set_status(Status(StatusCode.OK))
|