openlit 1.16.2__py3-none-any.whl → 1.18.0__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/__init__.py +3 -0
- openlit/instrumentation/anthropic/anthropic.py +28 -10
- openlit/instrumentation/anthropic/async_anthropic.py +27 -10
- openlit/instrumentation/bedrock/bedrock.py +13 -5
- openlit/instrumentation/cohere/cohere.py +33 -12
- openlit/instrumentation/elevenlabs/async_elevenlabs.py +6 -2
- openlit/instrumentation/elevenlabs/elevenlabs.py +6 -2
- openlit/instrumentation/gpt4all/gpt4all.py +30 -10
- openlit/instrumentation/groq/async_groq.py +31 -11
- openlit/instrumentation/groq/groq.py +31 -11
- openlit/instrumentation/mistral/async_mistral.py +33 -12
- openlit/instrumentation/mistral/mistral.py +33 -12
- openlit/instrumentation/ollama/async_ollama.py +57 -20
- openlit/instrumentation/ollama/ollama.py +57 -20
- openlit/instrumentation/openai/async_azure_openai.py +94 -35
- openlit/instrumentation/openai/async_openai.py +68 -27
- openlit/instrumentation/openai/azure_openai.py +89 -31
- openlit/instrumentation/openai/openai.py +68 -29
- openlit/instrumentation/transformers/transformers.py +20 -16
- openlit/instrumentation/vertexai/async_vertexai.py +104 -35
- openlit/instrumentation/vertexai/vertexai.py +104 -35
- openlit/instrumentation/vllm/__init__.py +43 -0
- openlit/instrumentation/vllm/vllm.py +143 -0
- openlit/semcov/__init__.py +4 -1
- {openlit-1.16.2.dist-info → openlit-1.18.0.dist-info}/METADATA +3 -1
- {openlit-1.16.2.dist-info → openlit-1.18.0.dist-info}/RECORD +28 -26
- {openlit-1.16.2.dist-info → openlit-1.18.0.dist-info}/LICENSE +0 -0
- {openlit-1.16.2.dist-info → openlit-1.18.0.dist-info}/WHEEL +0 -0
@@ -102,7 +102,7 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
102
102
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
103
103
|
False)
|
104
104
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
105
|
-
response.choices[0].finish_reason)
|
105
|
+
[response.choices[0].finish_reason])
|
106
106
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
107
107
|
response.usage.prompt_tokens)
|
108
108
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
@@ -112,10 +112,19 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
112
112
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
113
113
|
cost)
|
114
114
|
if trace_content:
|
115
|
-
span.
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
span.add_event(
|
116
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
117
|
+
attributes={
|
118
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
119
|
+
},
|
120
|
+
)
|
121
|
+
span.add_event(
|
122
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
123
|
+
# pylint: disable=line-too-long
|
124
|
+
attributes={
|
125
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content if response.choices[0].message.content else "",
|
126
|
+
},
|
127
|
+
)
|
119
128
|
|
120
129
|
span.set_status(Status(StatusCode.OK))
|
121
130
|
|
@@ -259,7 +268,7 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
|
|
259
268
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
260
269
|
True)
|
261
270
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
262
|
-
finish_reason)
|
271
|
+
[finish_reason])
|
263
272
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
264
273
|
prompt_tokens)
|
265
274
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
@@ -269,10 +278,18 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
|
|
269
278
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
270
279
|
cost)
|
271
280
|
if trace_content:
|
272
|
-
span.
|
273
|
-
|
274
|
-
|
275
|
-
|
281
|
+
span.add_event(
|
282
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
283
|
+
attributes={
|
284
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
285
|
+
},
|
286
|
+
)
|
287
|
+
span.add_event(
|
288
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
289
|
+
attributes={
|
290
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
291
|
+
},
|
292
|
+
)
|
276
293
|
|
277
294
|
span.set_status(Status(StatusCode.OK))
|
278
295
|
|
@@ -377,8 +394,12 @@ def embeddings(gen_ai_endpoint, version, environment, application_name,
|
|
377
394
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
378
395
|
cost)
|
379
396
|
if trace_content:
|
380
|
-
span.
|
381
|
-
|
397
|
+
span.add_event(
|
398
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
399
|
+
attributes={
|
400
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
401
|
+
},
|
402
|
+
)
|
382
403
|
|
383
404
|
span.set_status(Status(StatusCode.OK))
|
384
405
|
|
@@ -120,10 +120,18 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
120
120
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
121
121
|
cost)
|
122
122
|
if trace_content:
|
123
|
-
span.
|
124
|
-
|
125
|
-
|
126
|
-
|
123
|
+
span.add_event(
|
124
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
125
|
+
attributes={
|
126
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
127
|
+
},
|
128
|
+
)
|
129
|
+
span.add_event(
|
130
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
131
|
+
attributes={
|
132
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
133
|
+
},
|
134
|
+
)
|
127
135
|
|
128
136
|
span.set_status(Status(StatusCode.OK))
|
129
137
|
|
@@ -198,10 +206,18 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
198
206
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
199
207
|
False)
|
200
208
|
if trace_content:
|
201
|
-
span.
|
202
|
-
|
203
|
-
|
204
|
-
|
209
|
+
span.add_event(
|
210
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
211
|
+
attributes={
|
212
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
213
|
+
},
|
214
|
+
)
|
215
|
+
span.add_event(
|
216
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
217
|
+
attributes={
|
218
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response['message']['content'],
|
219
|
+
},
|
220
|
+
)
|
205
221
|
|
206
222
|
# Calculate cost of the operation
|
207
223
|
cost = 0
|
@@ -216,7 +232,7 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
216
232
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
217
233
|
total_tokens)
|
218
234
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
219
|
-
response["done_reason"])
|
235
|
+
[response["done_reason"]])
|
220
236
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
221
237
|
cost)
|
222
238
|
|
@@ -345,10 +361,19 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
|
|
345
361
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
346
362
|
cost)
|
347
363
|
if trace_content:
|
348
|
-
span.
|
349
|
-
|
350
|
-
|
351
|
-
|
364
|
+
span.add_event(
|
365
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
366
|
+
attributes={
|
367
|
+
# pylint: disable=line-too-long
|
368
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
369
|
+
},
|
370
|
+
)
|
371
|
+
span.add_event(
|
372
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
373
|
+
attributes={
|
374
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
375
|
+
},
|
376
|
+
)
|
352
377
|
|
353
378
|
span.set_status(Status(StatusCode.OK))
|
354
379
|
|
@@ -404,10 +429,18 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
|
|
404
429
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
405
430
|
False)
|
406
431
|
if trace_content:
|
407
|
-
span.
|
408
|
-
|
409
|
-
|
410
|
-
|
432
|
+
span.add_event(
|
433
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
434
|
+
attributes={
|
435
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
436
|
+
},
|
437
|
+
)
|
438
|
+
span.add_event(
|
439
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
440
|
+
attributes={
|
441
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response['response'],
|
442
|
+
},
|
443
|
+
)
|
411
444
|
|
412
445
|
# Calculate cost of the operation
|
413
446
|
cost = 0
|
@@ -422,7 +455,7 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
|
|
422
455
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
423
456
|
total_tokens)
|
424
457
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
425
|
-
response["done_reason"])
|
458
|
+
[response["done_reason"]])
|
426
459
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
427
460
|
cost)
|
428
461
|
|
@@ -525,8 +558,12 @@ def async_embeddings(gen_ai_endpoint, version, environment, application_name,
|
|
525
558
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
526
559
|
cost)
|
527
560
|
if trace_content:
|
528
|
-
span.
|
529
|
-
|
561
|
+
span.add_event(
|
562
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
563
|
+
attributes={
|
564
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
565
|
+
},
|
566
|
+
)
|
530
567
|
|
531
568
|
span.set_status(Status(StatusCode.OK))
|
532
569
|
|
@@ -120,10 +120,18 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
120
120
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
121
121
|
cost)
|
122
122
|
if trace_content:
|
123
|
-
span.
|
124
|
-
|
125
|
-
|
126
|
-
|
123
|
+
span.add_event(
|
124
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
125
|
+
attributes={
|
126
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
127
|
+
},
|
128
|
+
)
|
129
|
+
span.add_event(
|
130
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
131
|
+
attributes={
|
132
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
133
|
+
},
|
134
|
+
)
|
127
135
|
|
128
136
|
span.set_status(Status(StatusCode.OK))
|
129
137
|
|
@@ -198,10 +206,18 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
198
206
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
199
207
|
False)
|
200
208
|
if trace_content:
|
201
|
-
span.
|
202
|
-
|
203
|
-
|
204
|
-
|
209
|
+
span.add_event(
|
210
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
211
|
+
attributes={
|
212
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
213
|
+
},
|
214
|
+
)
|
215
|
+
span.add_event(
|
216
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
217
|
+
attributes={
|
218
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response['message']['content'],
|
219
|
+
},
|
220
|
+
)
|
205
221
|
|
206
222
|
# Calculate cost of the operation
|
207
223
|
cost = 0
|
@@ -216,7 +232,7 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
216
232
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
217
233
|
total_tokens)
|
218
234
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
219
|
-
response["done_reason"])
|
235
|
+
[response["done_reason"]])
|
220
236
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
221
237
|
cost)
|
222
238
|
|
@@ -345,10 +361,19 @@ def generate(gen_ai_endpoint, version, environment, application_name,
|
|
345
361
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
346
362
|
cost)
|
347
363
|
if trace_content:
|
348
|
-
span.
|
349
|
-
|
350
|
-
|
351
|
-
|
364
|
+
span.add_event(
|
365
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
366
|
+
attributes={
|
367
|
+
# pylint: disable=line-too-long
|
368
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
369
|
+
},
|
370
|
+
)
|
371
|
+
span.add_event(
|
372
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
373
|
+
attributes={
|
374
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
375
|
+
},
|
376
|
+
)
|
352
377
|
|
353
378
|
span.set_status(Status(StatusCode.OK))
|
354
379
|
|
@@ -404,10 +429,18 @@ def generate(gen_ai_endpoint, version, environment, application_name,
|
|
404
429
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
405
430
|
False)
|
406
431
|
if trace_content:
|
407
|
-
span.
|
408
|
-
|
409
|
-
|
410
|
-
|
432
|
+
span.add_event(
|
433
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
434
|
+
attributes={
|
435
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
436
|
+
},
|
437
|
+
)
|
438
|
+
span.add_event(
|
439
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
440
|
+
attributes={
|
441
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response['response'],
|
442
|
+
},
|
443
|
+
)
|
411
444
|
|
412
445
|
# Calculate cost of the operation
|
413
446
|
cost = 0
|
@@ -422,7 +455,7 @@ def generate(gen_ai_endpoint, version, environment, application_name,
|
|
422
455
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
423
456
|
total_tokens)
|
424
457
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
425
|
-
response["done_reason"])
|
458
|
+
[response["done_reason"]])
|
426
459
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
427
460
|
cost)
|
428
461
|
|
@@ -525,8 +558,12 @@ def embeddings(gen_ai_endpoint, version, environment, application_name,
|
|
525
558
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
526
559
|
cost)
|
527
560
|
if trace_content:
|
528
|
-
span.
|
529
|
-
|
561
|
+
span.add_event(
|
562
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
563
|
+
attributes={
|
564
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
565
|
+
},
|
566
|
+
)
|
530
567
|
|
531
568
|
span.set_status(Status(StatusCode.OK))
|
532
569
|
|
@@ -143,10 +143,18 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicat
|
|
143
143
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
144
144
|
cost)
|
145
145
|
if trace_content:
|
146
|
-
span.
|
147
|
-
|
148
|
-
|
149
|
-
|
146
|
+
span.add_event(
|
147
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
148
|
+
attributes={
|
149
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
150
|
+
},
|
151
|
+
)
|
152
|
+
span.add_event(
|
153
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
154
|
+
attributes={
|
155
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
156
|
+
},
|
157
|
+
)
|
150
158
|
|
151
159
|
span.set_status(Status(StatusCode.OK))
|
152
160
|
|
@@ -238,8 +246,12 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicat
|
|
238
246
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
239
247
|
False)
|
240
248
|
if trace_content:
|
241
|
-
span.
|
242
|
-
|
249
|
+
span.add_event(
|
250
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
251
|
+
attributes={
|
252
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
253
|
+
},
|
254
|
+
)
|
243
255
|
|
244
256
|
# Set span attributes when tools is not passed to the function call
|
245
257
|
if "tools" not in kwargs:
|
@@ -255,23 +267,31 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicat
|
|
255
267
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
256
268
|
response.usage.total_tokens)
|
257
269
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
258
|
-
response.choices[0].finish_reason)
|
270
|
+
[response.choices[0].finish_reason])
|
259
271
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
260
272
|
cost)
|
261
273
|
|
262
274
|
# Set span attributes for when n = 1 (default)
|
263
275
|
if "n" not in kwargs or kwargs["n"] == 1:
|
264
276
|
if trace_content:
|
265
|
-
span.
|
266
|
-
|
277
|
+
span.add_event(
|
278
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
279
|
+
attributes={
|
280
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content,
|
281
|
+
},
|
282
|
+
)
|
267
283
|
|
268
284
|
# Set span attributes for when n > 0
|
269
285
|
else:
|
270
286
|
i = 0
|
271
287
|
while i < kwargs["n"] and trace_content is True:
|
272
|
-
attribute_name = f"gen_ai.completion.{i}"
|
273
|
-
span.
|
274
|
-
|
288
|
+
attribute_name = f"gen_ai.content.completion.{i}"
|
289
|
+
span.add_event(
|
290
|
+
name=attribute_name,
|
291
|
+
attributes={
|
292
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].message.content,
|
293
|
+
},
|
294
|
+
)
|
275
295
|
i += 1
|
276
296
|
|
277
297
|
# Return original response
|
@@ -284,8 +304,12 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicat
|
|
284
304
|
response.usage.prompt_tokens,
|
285
305
|
response.usage.completion_tokens)
|
286
306
|
|
287
|
-
span.
|
288
|
-
|
307
|
+
span.add_event(
|
308
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
309
|
+
attributes={
|
310
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: "Function called with tools",
|
311
|
+
},
|
312
|
+
)
|
289
313
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
290
314
|
response.usage.prompt_tokens)
|
291
315
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
@@ -443,10 +467,18 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_n
|
|
443
467
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
444
468
|
cost)
|
445
469
|
if trace_content:
|
446
|
-
span.
|
447
|
-
|
448
|
-
|
449
|
-
|
470
|
+
span.add_event(
|
471
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
472
|
+
attributes={
|
473
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
474
|
+
},
|
475
|
+
)
|
476
|
+
span.add_event(
|
477
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
478
|
+
attributes={
|
479
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
480
|
+
},
|
481
|
+
)
|
450
482
|
|
451
483
|
span.set_status(Status(StatusCode.OK))
|
452
484
|
|
@@ -519,8 +551,12 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_n
|
|
519
551
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
520
552
|
False)
|
521
553
|
if trace_content:
|
522
|
-
span.
|
523
|
-
|
554
|
+
span.add_event(
|
555
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
556
|
+
attributes={
|
557
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
558
|
+
},
|
559
|
+
)
|
524
560
|
|
525
561
|
# Set span attributes when tools is not passed to the function call
|
526
562
|
if "tools" not in kwargs:
|
@@ -536,23 +572,31 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_n
|
|
536
572
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
537
573
|
response.usage.total_tokens)
|
538
574
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
539
|
-
response.choices[0].finish_reason)
|
575
|
+
[response.choices[0].finish_reason])
|
540
576
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
541
577
|
cost)
|
542
578
|
|
543
579
|
# Set span attributes for when n = 1 (default)
|
544
580
|
if "n" not in kwargs or kwargs["n"] == 1:
|
545
581
|
if trace_content:
|
546
|
-
span.
|
547
|
-
|
582
|
+
span.add_event(
|
583
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
584
|
+
attributes={
|
585
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].text,
|
586
|
+
},
|
587
|
+
)
|
548
588
|
|
549
589
|
# Set span attributes for when n > 0
|
550
590
|
else:
|
551
591
|
i = 0
|
552
592
|
while i < kwargs["n"] and trace_content is True:
|
553
|
-
attribute_name = f"gen_ai.completion.{i}"
|
554
|
-
span.
|
555
|
-
|
593
|
+
attribute_name = f"gen_ai.content.completion.{i}"
|
594
|
+
span.add_event(
|
595
|
+
name=attribute_name,
|
596
|
+
attributes={
|
597
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].text,
|
598
|
+
},
|
599
|
+
)
|
556
600
|
i += 1
|
557
601
|
return response
|
558
602
|
|
@@ -563,8 +607,12 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_n
|
|
563
607
|
response.usage.prompt_tokens,
|
564
608
|
response.usage.completion_tokens)
|
565
609
|
|
566
|
-
span.
|
567
|
-
|
610
|
+
span.add_event(
|
611
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
612
|
+
attributes={
|
613
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: "Function called with tools",
|
614
|
+
},
|
615
|
+
)
|
568
616
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
569
617
|
response.usage.prompt_tokens)
|
570
618
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
@@ -679,8 +727,12 @@ def azure_async_embedding(gen_ai_endpoint, version, environment, application_nam
|
|
679
727
|
response.usage.total_tokens)
|
680
728
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST, cost)
|
681
729
|
if trace_content:
|
682
|
-
span.
|
683
|
-
|
730
|
+
span.add_event(
|
731
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
732
|
+
attributes={
|
733
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("input", ""),
|
734
|
+
},
|
735
|
+
)
|
684
736
|
|
685
737
|
span.set_status(Status(StatusCode.OK))
|
686
738
|
|
@@ -796,12 +848,19 @@ def azure_async_image_generate(gen_ai_endpoint, version, environment, applicatio
|
|
796
848
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
|
797
849
|
kwargs.get("user", ""))
|
798
850
|
if trace_content:
|
799
|
-
span.
|
800
|
-
|
801
|
-
|
851
|
+
span.add_event(
|
852
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
853
|
+
attributes={
|
854
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
855
|
+
},
|
856
|
+
)
|
802
857
|
attribute_name = f"gen_ai.response.image.{images_count}"
|
803
|
-
span.
|
804
|
-
|
858
|
+
span.add_event(
|
859
|
+
name=attribute_name,
|
860
|
+
attributes={
|
861
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: getattr(items, image),
|
862
|
+
},
|
863
|
+
)
|
805
864
|
|
806
865
|
images_count+=1
|
807
866
|
|