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
@@ -21,7 +21,7 @@ from openlit.__helpers import (
|
|
21
21
|
create_metrics_attributes,
|
22
22
|
set_server_address_and_port
|
23
23
|
)
|
24
|
-
from openlit.semcov import
|
24
|
+
from openlit.semcov import SemanticConvention
|
25
25
|
|
26
26
|
# Initialize logger for logging potential issues and operations
|
27
27
|
logger = logging.getLogger(__name__)
|
@@ -141,41 +141,41 @@ def async_responses(version, environment, application_name,
|
|
141
141
|
|
142
142
|
# Set Span attributes (OTel Semconv)
|
143
143
|
self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
144
|
-
self._span.set_attribute(
|
145
|
-
|
146
|
-
self._span.set_attribute(
|
147
|
-
|
148
|
-
self._span.set_attribute(
|
144
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
145
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
146
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
147
|
+
SemanticConvention.GEN_AI_SYSTEM_OPENAI)
|
148
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
149
149
|
request_model)
|
150
|
-
self._span.set_attribute(
|
150
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED,
|
151
151
|
self._kwargs.get("seed", ""))
|
152
|
-
self._span.set_attribute(
|
152
|
+
self._span.set_attribute(SemanticConvention.SERVER_PORT,
|
153
153
|
self._server_port)
|
154
|
-
self._span.set_attribute(
|
154
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
155
155
|
self._kwargs.get("max_output_tokens", -1))
|
156
|
-
self._span.set_attribute(
|
156
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
157
157
|
self._kwargs.get("stop", []))
|
158
|
-
self._span.set_attribute(
|
158
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
159
159
|
self._kwargs.get("temperature", 1.0))
|
160
|
-
self._span.set_attribute(
|
160
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
161
161
|
self._kwargs.get("top_p", 1.0))
|
162
|
-
self._span.set_attribute(
|
162
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON,
|
163
163
|
[self._finish_reason])
|
164
|
-
self._span.set_attribute(
|
164
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
165
165
|
self._response_id)
|
166
|
-
self._span.set_attribute(
|
166
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
167
167
|
self._response_model)
|
168
|
-
self._span.set_attribute(
|
168
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
169
169
|
self._input_tokens)
|
170
|
-
self._span.set_attribute(
|
170
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
171
171
|
self._output_tokens)
|
172
|
-
self._span.set_attribute(
|
172
|
+
self._span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
173
173
|
self._server_address)
|
174
174
|
if isinstance(self._llmresponse, str):
|
175
|
-
self._span.set_attribute(
|
175
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
176
176
|
"text")
|
177
177
|
else:
|
178
|
-
self._span.set_attribute(
|
178
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
179
179
|
"json")
|
180
180
|
|
181
181
|
# Set Span attributes (Extra)
|
@@ -183,32 +183,32 @@ def async_responses(version, environment, application_name,
|
|
183
183
|
environment)
|
184
184
|
self._span.set_attribute(SERVICE_NAME,
|
185
185
|
application_name)
|
186
|
-
self._span.set_attribute(
|
186
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
187
187
|
self._kwargs.get("user", ""))
|
188
|
-
self._span.set_attribute(
|
188
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
189
189
|
True)
|
190
|
-
self._span.set_attribute(
|
190
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
191
191
|
self._input_tokens + self._output_tokens)
|
192
|
-
self._span.set_attribute(
|
192
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
193
193
|
cost)
|
194
|
-
self._span.set_attribute(
|
194
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TBT,
|
195
195
|
self._tbt)
|
196
|
-
self._span.set_attribute(
|
196
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
197
197
|
self._ttft)
|
198
|
-
self._span.set_attribute(
|
198
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
199
199
|
version)
|
200
200
|
|
201
201
|
if capture_message_content:
|
202
202
|
self._span.add_event(
|
203
|
-
name=
|
203
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
204
204
|
attributes={
|
205
|
-
|
205
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
206
206
|
},
|
207
207
|
)
|
208
208
|
self._span.add_event(
|
209
|
-
name=
|
209
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
210
210
|
attributes={
|
211
|
-
|
211
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: self._llmresponse,
|
212
212
|
},
|
213
213
|
)
|
214
214
|
self._span.set_status(Status(StatusCode.OK))
|
@@ -217,8 +217,8 @@ def async_responses(version, environment, application_name,
|
|
217
217
|
attributes = create_metrics_attributes(
|
218
218
|
service_name=application_name,
|
219
219
|
deployment_environment=environment,
|
220
|
-
operation=
|
221
|
-
system=
|
220
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
221
|
+
system=SemanticConvention.GEN_AI_SYSTEM_OPENAI,
|
222
222
|
request_model=request_model,
|
223
223
|
server_address=self._server_address,
|
224
224
|
server_port=self._server_port,
|
@@ -271,7 +271,7 @@ def async_responses(version, environment, application_name,
|
|
271
271
|
server_address, server_port = set_server_address_and_port(instance, "api.openai.com", 443)
|
272
272
|
request_model = kwargs.get("model", "gpt-4o")
|
273
273
|
|
274
|
-
span_name = f"{
|
274
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
275
275
|
|
276
276
|
# pylint: disable=no-else-return
|
277
277
|
if streaming:
|
@@ -307,33 +307,33 @@ def async_responses(version, environment, application_name,
|
|
307
307
|
|
308
308
|
# Set base span attribues (OTel Semconv)
|
309
309
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
310
|
-
span.set_attribute(
|
311
|
-
|
312
|
-
span.set_attribute(
|
313
|
-
|
314
|
-
span.set_attribute(
|
310
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
311
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
312
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
313
|
+
SemanticConvention.GEN_AI_SYSTEM_OPENAI)
|
314
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
315
315
|
request_model)
|
316
|
-
span.set_attribute(
|
316
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED,
|
317
317
|
kwargs.get("seed", ""))
|
318
|
-
span.set_attribute(
|
318
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
319
319
|
server_port)
|
320
|
-
span.set_attribute(
|
320
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
321
321
|
kwargs.get("max_output_tokens", -1))
|
322
|
-
span.set_attribute(
|
322
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
323
323
|
kwargs.get("stop", []))
|
324
|
-
span.set_attribute(
|
324
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
325
325
|
str(response_dict.get("temperature", 1.0)))
|
326
|
-
span.set_attribute(
|
326
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
327
327
|
str(response_dict.get("top_p", 1.0)))
|
328
|
-
span.set_attribute(
|
328
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
329
329
|
response_dict.get("id"))
|
330
|
-
span.set_attribute(
|
330
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
331
331
|
response_dict.get('model'))
|
332
|
-
span.set_attribute(
|
332
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
333
333
|
input_tokens)
|
334
|
-
span.set_attribute(
|
334
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
335
335
|
output_tokens)
|
336
|
-
span.set_attribute(
|
336
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
337
337
|
server_address)
|
338
338
|
|
339
339
|
# Set base span attribues (Extras)
|
@@ -341,29 +341,29 @@ def async_responses(version, environment, application_name,
|
|
341
341
|
environment)
|
342
342
|
span.set_attribute(SERVICE_NAME,
|
343
343
|
application_name)
|
344
|
-
span.set_attribute(
|
344
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
345
345
|
kwargs.get("user", ""))
|
346
|
-
span.set_attribute(
|
346
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
347
347
|
False)
|
348
|
-
span.set_attribute(
|
348
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
349
349
|
input_tokens + output_tokens)
|
350
|
-
span.set_attribute(
|
350
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
351
351
|
cost)
|
352
|
-
span.set_attribute(
|
352
|
+
span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
353
353
|
end_time - start_time)
|
354
|
-
span.set_attribute(
|
354
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
355
355
|
version)
|
356
356
|
|
357
357
|
if capture_message_content:
|
358
358
|
span.add_event(
|
359
|
-
name=
|
359
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
360
360
|
attributes={
|
361
|
-
|
361
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
362
362
|
},
|
363
363
|
)
|
364
364
|
|
365
365
|
for i in range(kwargs.get('n',1)):
|
366
|
-
span.set_attribute(
|
366
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON,
|
367
367
|
[response_dict.get('status')])
|
368
368
|
try:
|
369
369
|
llm_response = str(response_dict.get('output')[i].get('content')[0].get('text',''))
|
@@ -372,21 +372,21 @@ def async_responses(version, environment, application_name,
|
|
372
372
|
|
373
373
|
if capture_message_content:
|
374
374
|
span.add_event(
|
375
|
-
name=
|
375
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
376
376
|
attributes={
|
377
377
|
# pylint: disable=line-too-long
|
378
|
-
|
378
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: llm_response,
|
379
379
|
},
|
380
380
|
)
|
381
381
|
if kwargs.get('tools'):
|
382
|
-
span.set_attribute(
|
382
|
+
span.set_attribute(SemanticConvention.GEN_AI_TOOL_CALLS,
|
383
383
|
str(response_dict.get('tools')))
|
384
384
|
|
385
385
|
if isinstance(llm_response, str):
|
386
|
-
span.set_attribute(
|
386
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
387
387
|
"text")
|
388
388
|
elif llm_response is not None:
|
389
|
-
span.set_attribute(
|
389
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
390
390
|
"json")
|
391
391
|
|
392
392
|
span.set_status(Status(StatusCode.OK))
|
@@ -395,8 +395,8 @@ def async_responses(version, environment, application_name,
|
|
395
395
|
attributes = create_metrics_attributes(
|
396
396
|
service_name=application_name,
|
397
397
|
deployment_environment=environment,
|
398
|
-
operation=
|
399
|
-
system=
|
398
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
399
|
+
system=SemanticConvention.GEN_AI_SYSTEM_OPENAI,
|
400
400
|
request_model=request_model,
|
401
401
|
server_address=server_address,
|
402
402
|
server_port=server_port,
|
@@ -522,7 +522,7 @@ def async_chat_completions(version, environment, application_name,
|
|
522
522
|
self._response_id = chunked.get('id')
|
523
523
|
self._response_model = chunked.get('model')
|
524
524
|
self._finish_reason = chunked.get('choices')[0].get('finish_reason')
|
525
|
-
self._openai_response_service_tier = chunked.get('service_tier')
|
525
|
+
self._openai_response_service_tier = chunked.get('service_tier') or 'auto'
|
526
526
|
self._openai_system_fingerprint = chunked.get('system_fingerprint')
|
527
527
|
return chunk
|
528
528
|
except StopAsyncIteration:
|
@@ -566,51 +566,51 @@ def async_chat_completions(version, environment, application_name,
|
|
566
566
|
|
567
567
|
# Set Span attributes (OTel Semconv)
|
568
568
|
self._span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
569
|
-
self._span.set_attribute(
|
570
|
-
|
571
|
-
self._span.set_attribute(
|
572
|
-
|
573
|
-
self._span.set_attribute(
|
569
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
570
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
571
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
572
|
+
SemanticConvention.GEN_AI_SYSTEM_OPENAI)
|
573
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
574
574
|
request_model)
|
575
|
-
self._span.set_attribute(
|
575
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED,
|
576
576
|
self._kwargs.get("seed", ""))
|
577
|
-
self._span.set_attribute(
|
577
|
+
self._span.set_attribute(SemanticConvention.SERVER_PORT,
|
578
578
|
self._server_port)
|
579
|
-
self._span.set_attribute(
|
579
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
580
580
|
self._kwargs.get("frequency_penalty", 0.0))
|
581
|
-
self._span.set_attribute(
|
581
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
582
582
|
self._kwargs.get("max_tokens", -1))
|
583
|
-
self._span.set_attribute(
|
583
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
584
584
|
self._kwargs.get("presence_penalty", 0.0))
|
585
|
-
self._span.set_attribute(
|
585
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
586
586
|
self._kwargs.get("stop", []))
|
587
|
-
self._span.set_attribute(
|
587
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
588
588
|
self._kwargs.get("temperature", 1.0))
|
589
|
-
self._span.set_attribute(
|
589
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
590
590
|
self._kwargs.get("top_p", 1.0))
|
591
|
-
self._span.set_attribute(
|
591
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON,
|
592
592
|
[self._finish_reason])
|
593
|
-
self._span.set_attribute(
|
593
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
594
594
|
self._response_id)
|
595
|
-
self._span.set_attribute(
|
595
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
596
596
|
self._response_model)
|
597
|
-
self._span.set_attribute(
|
597
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
598
598
|
input_tokens)
|
599
|
-
self._span.set_attribute(
|
599
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
600
600
|
output_tokens)
|
601
|
-
self._span.set_attribute(
|
601
|
+
self._span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
602
602
|
self._server_address)
|
603
|
-
self._span.set_attribute(
|
603
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SERVICE_TIER,
|
604
604
|
self._kwargs.get("service_tier", "auto"))
|
605
|
-
self._span.set_attribute(
|
605
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_SERVICE_TIER,
|
606
606
|
self._openai_response_service_tier)
|
607
|
-
self._span.set_attribute(
|
607
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT,
|
608
608
|
self._openai_system_fingerprint)
|
609
609
|
if isinstance(self._llmresponse, str):
|
610
|
-
self._span.set_attribute(
|
610
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
611
611
|
"text")
|
612
612
|
else:
|
613
|
-
self._span.set_attribute(
|
613
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
614
614
|
"json")
|
615
615
|
|
616
616
|
# Set Span attributes (Extra)
|
@@ -618,31 +618,31 @@ def async_chat_completions(version, environment, application_name,
|
|
618
618
|
environment)
|
619
619
|
self._span.set_attribute(SERVICE_NAME,
|
620
620
|
application_name)
|
621
|
-
self._span.set_attribute(
|
621
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
622
622
|
self._kwargs.get("user", ""))
|
623
|
-
self._span.set_attribute(
|
623
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
624
624
|
True)
|
625
|
-
self._span.set_attribute(
|
625
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
626
626
|
input_tokens + output_tokens)
|
627
|
-
self._span.set_attribute(
|
627
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
628
628
|
cost)
|
629
|
-
self._span.set_attribute(
|
629
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TBT,
|
630
630
|
self._tbt)
|
631
|
-
self._span.set_attribute(
|
631
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
632
632
|
self._ttft)
|
633
|
-
self._span.set_attribute(
|
633
|
+
self._span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
634
634
|
version)
|
635
635
|
if capture_message_content:
|
636
636
|
self._span.add_event(
|
637
|
-
name=
|
637
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
638
638
|
attributes={
|
639
|
-
|
639
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
640
640
|
},
|
641
641
|
)
|
642
642
|
self._span.add_event(
|
643
|
-
name=
|
643
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
644
644
|
attributes={
|
645
|
-
|
645
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: self._llmresponse,
|
646
646
|
},
|
647
647
|
)
|
648
648
|
self._span.set_status(Status(StatusCode.OK))
|
@@ -651,8 +651,8 @@ def async_chat_completions(version, environment, application_name,
|
|
651
651
|
attributes = create_metrics_attributes(
|
652
652
|
service_name=application_name,
|
653
653
|
deployment_environment=environment,
|
654
|
-
operation=
|
655
|
-
system=
|
654
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
655
|
+
system=SemanticConvention.GEN_AI_SYSTEM_OPENAI,
|
656
656
|
request_model=request_model,
|
657
657
|
server_address=self._server_address,
|
658
658
|
server_port=self._server_port,
|
@@ -705,7 +705,7 @@ def async_chat_completions(version, environment, application_name,
|
|
705
705
|
server_address, server_port = set_server_address_and_port(instance, "api.openai.com", 443)
|
706
706
|
request_model = kwargs.get("model", "gpt-4o")
|
707
707
|
|
708
|
-
span_name = f"{
|
708
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT} {request_model}"
|
709
709
|
|
710
710
|
# pylint: disable=no-else-return
|
711
711
|
if streaming:
|
@@ -753,43 +753,43 @@ def async_chat_completions(version, environment, application_name,
|
|
753
753
|
|
754
754
|
# Set base span attribues (OTel Semconv)
|
755
755
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
756
|
-
span.set_attribute(
|
757
|
-
|
758
|
-
span.set_attribute(
|
759
|
-
|
760
|
-
span.set_attribute(
|
756
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
757
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT)
|
758
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
759
|
+
SemanticConvention.GEN_AI_SYSTEM_OPENAI)
|
760
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
761
761
|
request_model)
|
762
|
-
span.set_attribute(
|
762
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SEED,
|
763
763
|
kwargs.get("seed", ""))
|
764
|
-
span.set_attribute(
|
764
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
765
765
|
server_port)
|
766
|
-
span.set_attribute(
|
766
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
767
767
|
kwargs.get("frequency_penalty", 0.0))
|
768
|
-
span.set_attribute(
|
768
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS,
|
769
769
|
kwargs.get("max_tokens", -1))
|
770
|
-
span.set_attribute(
|
770
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
771
771
|
kwargs.get("presence_penalty", 0.0))
|
772
|
-
span.set_attribute(
|
772
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_STOP_SEQUENCES,
|
773
773
|
kwargs.get("stop", []))
|
774
|
-
span.set_attribute(
|
774
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE,
|
775
775
|
kwargs.get("temperature", 1.0))
|
776
|
-
span.set_attribute(
|
776
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_TOP_P,
|
777
777
|
kwargs.get("top_p", 1.0))
|
778
|
-
span.set_attribute(
|
778
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
779
779
|
response_dict.get("id"))
|
780
|
-
span.set_attribute(
|
780
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
781
781
|
response_dict.get('model'))
|
782
|
-
span.set_attribute(
|
782
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
783
783
|
input_tokens)
|
784
|
-
span.set_attribute(
|
784
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_OUTPUT_TOKENS,
|
785
785
|
output_tokens)
|
786
|
-
span.set_attribute(
|
786
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
787
787
|
server_address)
|
788
|
-
span.set_attribute(
|
788
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_SERVICE_TIER,
|
789
789
|
kwargs.get("service_tier", "auto"))
|
790
|
-
span.set_attribute(
|
791
|
-
response_dict.get('service_tier'))
|
792
|
-
span.set_attribute(
|
790
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_SERVICE_TIER,
|
791
|
+
response_dict.get('service_tier', 'auto'))
|
792
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT,
|
793
793
|
response_dict.get('system_fingerprint', ''))
|
794
794
|
|
795
795
|
# Set base span attribues (Extras)
|
@@ -797,46 +797,46 @@ def async_chat_completions(version, environment, application_name,
|
|
797
797
|
environment)
|
798
798
|
span.set_attribute(SERVICE_NAME,
|
799
799
|
application_name)
|
800
|
-
span.set_attribute(
|
800
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
801
801
|
kwargs.get("user", ""))
|
802
|
-
span.set_attribute(
|
802
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM,
|
803
803
|
False)
|
804
|
-
span.set_attribute(
|
804
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
805
805
|
input_tokens + output_tokens)
|
806
|
-
span.set_attribute(
|
806
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
807
807
|
cost)
|
808
|
-
span.set_attribute(
|
808
|
+
span.set_attribute(SemanticConvention.GEN_AI_SERVER_TTFT,
|
809
809
|
end_time - start_time)
|
810
|
-
span.set_attribute(
|
810
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
811
811
|
version)
|
812
812
|
if capture_message_content:
|
813
813
|
span.add_event(
|
814
|
-
name=
|
814
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
815
815
|
attributes={
|
816
|
-
|
816
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: prompt,
|
817
817
|
},
|
818
818
|
)
|
819
819
|
|
820
820
|
for i in range(kwargs.get('n',1)):
|
821
|
-
span.set_attribute(
|
821
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON,
|
822
822
|
[response_dict.get('choices')[i].get('finish_reason')])
|
823
823
|
if capture_message_content:
|
824
824
|
span.add_event(
|
825
|
-
name=
|
825
|
+
name=SemanticConvention.GEN_AI_CONTENT_COMPLETION_EVENT,
|
826
826
|
attributes={
|
827
827
|
# pylint: disable=line-too-long
|
828
|
-
|
828
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: str(response_dict.get('choices')[i].get('message').get('content')),
|
829
829
|
},
|
830
830
|
)
|
831
831
|
if kwargs.get('tools'):
|
832
|
-
span.set_attribute(
|
832
|
+
span.set_attribute(SemanticConvention.GEN_AI_TOOL_CALLS,
|
833
833
|
str(response_dict.get('choices')[i].get('message').get('tool_calls')))
|
834
834
|
|
835
835
|
if isinstance(response_dict.get('choices')[i].get('message').get('content'), str):
|
836
|
-
span.set_attribute(
|
836
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
837
837
|
"text")
|
838
838
|
elif response_dict.get('choices')[i].get('message').get('content') is not None:
|
839
|
-
span.set_attribute(
|
839
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
840
840
|
"json")
|
841
841
|
|
842
842
|
span.set_status(Status(StatusCode.OK))
|
@@ -845,8 +845,8 @@ def async_chat_completions(version, environment, application_name,
|
|
845
845
|
attributes = create_metrics_attributes(
|
846
846
|
service_name=application_name,
|
847
847
|
deployment_environment=environment,
|
848
|
-
operation=
|
849
|
-
system=
|
848
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_CHAT,
|
849
|
+
system=SemanticConvention.GEN_AI_SYSTEM_OPENAI,
|
850
850
|
request_model=request_model,
|
851
851
|
server_address=server_address,
|
852
852
|
server_port=server_port,
|
@@ -916,7 +916,7 @@ def async_embedding(version, environment, application_name,
|
|
916
916
|
server_address, server_port = set_server_address_and_port(instance, "api.openai.com", 443)
|
917
917
|
request_model = kwargs.get("model", "text-embedding-ada-002")
|
918
918
|
|
919
|
-
span_name = f"{
|
919
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_EMBEDDING} {request_model}"
|
920
920
|
|
921
921
|
with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
|
922
922
|
start_time = time.time()
|
@@ -933,21 +933,21 @@ def async_embedding(version, environment, application_name,
|
|
933
933
|
|
934
934
|
# Set Span attributes (OTel Semconv)
|
935
935
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
936
|
-
span.set_attribute(
|
937
|
-
|
938
|
-
span.set_attribute(
|
939
|
-
|
940
|
-
span.set_attribute(
|
936
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
937
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_EMBEDDING)
|
938
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
939
|
+
SemanticConvention.GEN_AI_SYSTEM_OPENAI)
|
940
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
941
941
|
request_model)
|
942
|
-
span.set_attribute(
|
942
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_ENCODING_FORMATS,
|
943
943
|
[kwargs.get('encoding_format', 'float')])
|
944
|
-
span.set_attribute(
|
944
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
945
945
|
request_model)
|
946
|
-
span.set_attribute(
|
946
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
947
947
|
server_address)
|
948
|
-
span.set_attribute(
|
948
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
949
949
|
server_port)
|
950
|
-
span.set_attribute(
|
950
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_INPUT_TOKENS,
|
951
951
|
input_tokens)
|
952
952
|
|
953
953
|
# Set Span attributes (Extras)
|
@@ -955,20 +955,20 @@ def async_embedding(version, environment, application_name,
|
|
955
955
|
environment)
|
956
956
|
span.set_attribute(SERVICE_NAME,
|
957
957
|
application_name)
|
958
|
-
span.set_attribute(
|
958
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
959
959
|
kwargs.get("user", ""))
|
960
|
-
span.set_attribute(
|
960
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS,
|
961
961
|
input_tokens)
|
962
|
-
span.set_attribute(
|
962
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
963
963
|
cost)
|
964
|
-
span.set_attribute(
|
964
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
965
965
|
version)
|
966
966
|
|
967
967
|
if capture_message_content:
|
968
968
|
span.add_event(
|
969
|
-
name=
|
969
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
970
970
|
attributes={
|
971
|
-
|
971
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: str(kwargs.get("input", "")),
|
972
972
|
},
|
973
973
|
)
|
974
974
|
|
@@ -978,8 +978,8 @@ def async_embedding(version, environment, application_name,
|
|
978
978
|
attributes = create_metrics_attributes(
|
979
979
|
service_name=application_name,
|
980
980
|
deployment_environment=environment,
|
981
|
-
operation=
|
982
|
-
system=
|
981
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_EMBEDDING,
|
982
|
+
system=SemanticConvention.GEN_AI_SYSTEM_OPENAI,
|
983
983
|
request_model=request_model,
|
984
984
|
server_address=server_address,
|
985
985
|
server_port=server_port,
|
@@ -1044,7 +1044,7 @@ def async_image_generate(version, environment, application_name,
|
|
1044
1044
|
server_address, server_port = set_server_address_and_port(instance, "api.openai.com", 443)
|
1045
1045
|
request_model = kwargs.get("model", "dall-e-2")
|
1046
1046
|
|
1047
|
-
span_name = f"{
|
1047
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_IMAGE} {request_model}"
|
1048
1048
|
|
1049
1049
|
with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
|
1050
1050
|
start_time = time.time()
|
@@ -1068,21 +1068,21 @@ def async_image_generate(version, environment, application_name,
|
|
1068
1068
|
for items in response.data:
|
1069
1069
|
# Set Span attributes (OTel Semconv)
|
1070
1070
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
1071
|
-
span.set_attribute(
|
1072
|
-
|
1073
|
-
span.set_attribute(
|
1074
|
-
|
1075
|
-
span.set_attribute(
|
1071
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
1072
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_IMAGE)
|
1073
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
1074
|
+
SemanticConvention.GEN_AI_SYSTEM_OPENAI)
|
1075
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
1076
1076
|
request_model)
|
1077
|
-
span.set_attribute(
|
1077
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
1078
1078
|
server_address)
|
1079
|
-
span.set_attribute(
|
1079
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
1080
1080
|
server_port)
|
1081
|
-
span.set_attribute(
|
1081
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
1082
1082
|
response.created)
|
1083
|
-
span.set_attribute(
|
1083
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
1084
1084
|
request_model)
|
1085
|
-
span.set_attribute(
|
1085
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
1086
1086
|
"image")
|
1087
1087
|
|
1088
1088
|
# Set Span attributes (Extras)
|
@@ -1090,37 +1090,37 @@ def async_image_generate(version, environment, application_name,
|
|
1090
1090
|
environment)
|
1091
1091
|
span.set_attribute(SERVICE_NAME,
|
1092
1092
|
application_name)
|
1093
|
-
span.set_attribute(
|
1093
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IMAGE_SIZE,
|
1094
1094
|
kwargs.get("size", "1024x1024"))
|
1095
|
-
span.set_attribute(
|
1095
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IMAGE_QUALITY,
|
1096
1096
|
kwargs.get("quality", "standard"))
|
1097
|
-
span.set_attribute(
|
1097
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IMAGE_STYLE,
|
1098
1098
|
kwargs.get("style", "vivid"))
|
1099
|
-
span.set_attribute(
|
1099
|
+
span.set_attribute(SemanticConvention.GEN_AI_CONTENT_REVISED_PROMPT,
|
1100
1100
|
items.revised_prompt if items.revised_prompt else "")
|
1101
|
-
span.set_attribute(
|
1101
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
1102
1102
|
kwargs.get("user", ""))
|
1103
|
-
span.set_attribute(
|
1103
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
1104
1104
|
version)
|
1105
1105
|
|
1106
1106
|
if capture_message_content:
|
1107
1107
|
span.add_event(
|
1108
|
-
name=
|
1108
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
1109
1109
|
attributes={
|
1110
|
-
|
1110
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
1111
1111
|
},
|
1112
1112
|
)
|
1113
|
-
attribute_name = f"{
|
1113
|
+
attribute_name = f"{SemanticConvention.GEN_AI_RESPONSE_IMAGE}.{images_count}"
|
1114
1114
|
span.add_event(
|
1115
1115
|
name=attribute_name,
|
1116
1116
|
attributes={
|
1117
|
-
|
1117
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: getattr(items, image),
|
1118
1118
|
},
|
1119
1119
|
)
|
1120
1120
|
|
1121
1121
|
images_count+=1
|
1122
1122
|
|
1123
|
-
span.set_attribute(
|
1123
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
1124
1124
|
len(response.data) * cost)
|
1125
1125
|
span.set_status(Status(StatusCode.OK))
|
1126
1126
|
|
@@ -1128,8 +1128,8 @@ def async_image_generate(version, environment, application_name,
|
|
1128
1128
|
attributes = create_metrics_attributes(
|
1129
1129
|
service_name=application_name,
|
1130
1130
|
deployment_environment=environment,
|
1131
|
-
operation=
|
1132
|
-
system=
|
1131
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_IMAGE,
|
1132
|
+
system=SemanticConvention.GEN_AI_SYSTEM_OPENAI,
|
1133
1133
|
request_model=request_model,
|
1134
1134
|
server_address=server_address,
|
1135
1135
|
server_port=server_port,
|
@@ -1191,7 +1191,7 @@ def async_image_variatons(version, environment, application_name,
|
|
1191
1191
|
server_address, server_port = set_server_address_and_port(instance, "api.openai.com", 443)
|
1192
1192
|
request_model = kwargs.get("model", "dall-e-2")
|
1193
1193
|
|
1194
|
-
span_name = f"{
|
1194
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_IMAGE} {request_model}"
|
1195
1195
|
|
1196
1196
|
with tracer.start_as_current_span(span_name, kind= SpanKind.CLIENT) as span:
|
1197
1197
|
start_time = time.time()
|
@@ -1214,21 +1214,21 @@ def async_image_variatons(version, environment, application_name,
|
|
1214
1214
|
for items in response.data:
|
1215
1215
|
# Set Span attributes (OTel Semconv)
|
1216
1216
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
1217
|
-
span.set_attribute(
|
1218
|
-
|
1219
|
-
span.set_attribute(
|
1220
|
-
|
1221
|
-
span.set_attribute(
|
1217
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
1218
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_IMAGE)
|
1219
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
1220
|
+
SemanticConvention.GEN_AI_SYSTEM_OPENAI)
|
1221
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
1222
1222
|
request_model)
|
1223
|
-
span.set_attribute(
|
1223
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
1224
1224
|
server_address)
|
1225
|
-
span.set_attribute(
|
1225
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
1226
1226
|
server_port)
|
1227
|
-
span.set_attribute(
|
1227
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_ID,
|
1228
1228
|
response.created)
|
1229
|
-
span.set_attribute(
|
1229
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
1230
1230
|
request_model)
|
1231
|
-
span.set_attribute(
|
1231
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
1232
1232
|
"image")
|
1233
1233
|
|
1234
1234
|
# Set Span attributes (Extras)
|
@@ -1236,27 +1236,27 @@ def async_image_variatons(version, environment, application_name,
|
|
1236
1236
|
environment)
|
1237
1237
|
span.set_attribute(SERVICE_NAME,
|
1238
1238
|
application_name)
|
1239
|
-
span.set_attribute(
|
1239
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IMAGE_SIZE,
|
1240
1240
|
kwargs.get("size", "1024x1024"))
|
1241
|
-
span.set_attribute(
|
1241
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_IMAGE_QUALITY,
|
1242
1242
|
"standard")
|
1243
|
-
span.set_attribute(
|
1243
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_USER,
|
1244
1244
|
kwargs.get("user", ""))
|
1245
|
-
span.set_attribute(
|
1245
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
1246
1246
|
version)
|
1247
1247
|
|
1248
1248
|
if capture_message_content:
|
1249
|
-
attribute_name = f"{
|
1249
|
+
attribute_name = f"{SemanticConvention.GEN_AI_RESPONSE_IMAGE}.{images_count}"
|
1250
1250
|
span.add_event(
|
1251
1251
|
name=attribute_name,
|
1252
1252
|
attributes={
|
1253
|
-
|
1253
|
+
SemanticConvention.GEN_AI_CONTENT_COMPLETION: getattr(items, image),
|
1254
1254
|
},
|
1255
1255
|
)
|
1256
1256
|
|
1257
1257
|
images_count+=1
|
1258
1258
|
|
1259
|
-
span.set_attribute(
|
1259
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
1260
1260
|
len(response.data) * cost)
|
1261
1261
|
span.set_status(Status(StatusCode.OK))
|
1262
1262
|
|
@@ -1264,8 +1264,8 @@ def async_image_variatons(version, environment, application_name,
|
|
1264
1264
|
attributes = create_metrics_attributes(
|
1265
1265
|
service_name=application_name,
|
1266
1266
|
deployment_environment=environment,
|
1267
|
-
operation=
|
1268
|
-
system=
|
1267
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_IMAGE,
|
1268
|
+
system=SemanticConvention.GEN_AI_SYSTEM_OPENAI,
|
1269
1269
|
request_model=request_model,
|
1270
1270
|
server_address=server_address,
|
1271
1271
|
server_port=server_port,
|
@@ -1327,7 +1327,7 @@ def async_audio_create(version, environment, application_name,
|
|
1327
1327
|
server_address, server_port = set_server_address_and_port(instance, "api.openai.com", 443)
|
1328
1328
|
request_model = kwargs.get("model", "tts-1")
|
1329
1329
|
|
1330
|
-
span_name = f"{
|
1330
|
+
span_name = f"{SemanticConvention.GEN_AI_OPERATION_TYPE_AUDIO} {request_model}"
|
1331
1331
|
|
1332
1332
|
with tracer.start_as_current_span(span_name, kind=SpanKind.CLIENT) as span:
|
1333
1333
|
start_time = time.time()
|
@@ -1341,40 +1341,40 @@ def async_audio_create(version, environment, application_name,
|
|
1341
1341
|
|
1342
1342
|
# Set Span attributes
|
1343
1343
|
span.set_attribute(TELEMETRY_SDK_NAME, "openlit")
|
1344
|
-
span.set_attribute(
|
1345
|
-
|
1346
|
-
span.set_attribute(
|
1347
|
-
|
1348
|
-
span.set_attribute(
|
1344
|
+
span.set_attribute(SemanticConvention.GEN_AI_OPERATION,
|
1345
|
+
SemanticConvention.GEN_AI_OPERATION_TYPE_AUDIO)
|
1346
|
+
span.set_attribute(SemanticConvention.GEN_AI_SYSTEM,
|
1347
|
+
SemanticConvention.GEN_AI_SYSTEM_OPENAI)
|
1348
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_MODEL,
|
1349
1349
|
request_model)
|
1350
|
-
span.set_attribute(
|
1350
|
+
span.set_attribute(SemanticConvention.SERVER_ADDRESS,
|
1351
1351
|
server_address)
|
1352
|
-
span.set_attribute(
|
1352
|
+
span.set_attribute(SemanticConvention.SERVER_PORT,
|
1353
1353
|
server_port)
|
1354
|
-
span.set_attribute(
|
1354
|
+
span.set_attribute(SemanticConvention.GEN_AI_RESPONSE_MODEL,
|
1355
1355
|
request_model)
|
1356
|
-
span.set_attribute(
|
1356
|
+
span.set_attribute(SemanticConvention.GEN_AI_OUTPUT_TYPE,
|
1357
1357
|
"speech")
|
1358
1358
|
|
1359
1359
|
span.set_attribute(DEPLOYMENT_ENVIRONMENT,
|
1360
1360
|
environment)
|
1361
1361
|
span.set_attribute(SERVICE_NAME,
|
1362
1362
|
application_name)
|
1363
|
-
span.set_attribute(
|
1363
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_AUDIO_VOICE,
|
1364
1364
|
kwargs.get("voice", "alloy"))
|
1365
|
-
span.set_attribute(
|
1365
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_AUDIO_RESPONSE_FORMAT,
|
1366
1366
|
kwargs.get("response_format", "mp3"))
|
1367
|
-
span.set_attribute(
|
1367
|
+
span.set_attribute(SemanticConvention.GEN_AI_REQUEST_AUDIO_SPEED,
|
1368
1368
|
kwargs.get("speed", 1))
|
1369
|
-
span.set_attribute(
|
1369
|
+
span.set_attribute(SemanticConvention.GEN_AI_USAGE_COST,
|
1370
1370
|
cost)
|
1371
|
-
span.set_attribute(
|
1371
|
+
span.set_attribute(SemanticConvention.GEN_AI_SDK_VERSION,
|
1372
1372
|
version)
|
1373
1373
|
if capture_message_content:
|
1374
1374
|
span.add_event(
|
1375
|
-
name=
|
1375
|
+
name=SemanticConvention.GEN_AI_CONTENT_PROMPT_EVENT,
|
1376
1376
|
attributes={
|
1377
|
-
|
1377
|
+
SemanticConvention.GEN_AI_CONTENT_PROMPT: kwargs.get("input", ""),
|
1378
1378
|
},
|
1379
1379
|
)
|
1380
1380
|
|
@@ -1384,8 +1384,8 @@ def async_audio_create(version, environment, application_name,
|
|
1384
1384
|
attributes = create_metrics_attributes(
|
1385
1385
|
service_name=application_name,
|
1386
1386
|
deployment_environment=environment,
|
1387
|
-
operation=
|
1388
|
-
system=
|
1387
|
+
operation=SemanticConvention.GEN_AI_OPERATION_TYPE_AUDIO,
|
1388
|
+
system=SemanticConvention.GEN_AI_SYSTEM_OPENAI,
|
1389
1389
|
request_model=request_model,
|
1390
1390
|
server_address=server_address,
|
1391
1391
|
server_port=server_port,
|