openlit 1.16.2__py3-none-any.whl → 1.17.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.
@@ -130,7 +130,7 @@ def messages(gen_ai_endpoint, version, environment, application_name, tracer,
130
130
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
131
131
  kwargs.get("top_k", ""))
132
132
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
133
- finish_reason)
133
+ [finish_reason])
134
134
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
135
135
  prompt_tokens)
136
136
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
@@ -140,10 +140,18 @@ def messages(gen_ai_endpoint, version, environment, application_name, tracer,
140
140
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
141
141
  cost)
142
142
  if trace_content:
143
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
144
- prompt)
145
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
146
- llmresponse)
143
+ span.add_event(
144
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
145
+ attributes={
146
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
147
+ },
148
+ )
149
+ span.add_event(
150
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
151
+ attributes={
152
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
153
+ },
154
+ )
147
155
 
148
156
  span.set_status(Status(StatusCode.OK))
149
157
 
@@ -234,7 +242,7 @@ def messages(gen_ai_endpoint, version, environment, application_name, tracer,
234
242
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
235
243
  kwargs.get("top_k", ""))
236
244
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
237
- response.stop_reason)
245
+ [response.stop_reason])
238
246
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
239
247
  response.usage.input_tokens)
240
248
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
@@ -244,11 +252,21 @@ def messages(gen_ai_endpoint, version, environment, application_name, tracer,
244
252
  response.usage.output_tokens)
245
253
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
246
254
  cost)
255
+
247
256
  if trace_content:
248
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
249
- prompt)
250
- # pylint: disable=line-too-long
251
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION, response.content[0].text if response.content else "")
257
+ span.add_event(
258
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
259
+ attributes={
260
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
261
+ },
262
+ )
263
+ span.add_event(
264
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
265
+ attributes={
266
+ # pylint: disable=line-too-long
267
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.content[0].text if response.content else "",
268
+ },
269
+ )
252
270
 
253
271
  span.set_status(Status(StatusCode.OK))
254
272
 
@@ -130,7 +130,7 @@ def async_messages(gen_ai_endpoint, version, environment, application_name,
130
130
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
131
131
  kwargs.get("top_k", ""))
132
132
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
133
- finish_reason)
133
+ [finish_reason])
134
134
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
135
135
  prompt_tokens)
136
136
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
@@ -140,10 +140,18 @@ def async_messages(gen_ai_endpoint, version, environment, application_name,
140
140
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
141
141
  cost)
142
142
  if trace_content:
143
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
144
- prompt)
145
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
146
- llmresponse)
143
+ span.add_event(
144
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
145
+ attributes={
146
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
147
+ },
148
+ )
149
+ span.add_event(
150
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
151
+ attributes={
152
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
153
+ },
154
+ )
147
155
 
148
156
  span.set_status(Status(StatusCode.OK))
149
157
 
@@ -234,7 +242,7 @@ def async_messages(gen_ai_endpoint, version, environment, application_name,
234
242
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_K,
235
243
  kwargs.get("top_k", ""))
236
244
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
237
- response.stop_reason)
245
+ [response.stop_reason])
238
246
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
239
247
  response.usage.input_tokens)
240
248
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
@@ -245,10 +253,19 @@ def async_messages(gen_ai_endpoint, version, environment, application_name,
245
253
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
246
254
  cost)
247
255
  if trace_content:
248
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
249
- prompt)
250
- # pylint: disable=line-too-long
251
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION, response.content[0].text if response.content else "")
256
+ span.add_event(
257
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
258
+ attributes={
259
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
260
+ },
261
+ )
262
+ span.add_event(
263
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
264
+ attributes={
265
+ # pylint: disable=line-too-long
266
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.content[0].text if response.content else "",
267
+ },
268
+ )
252
269
 
253
270
  span.set_status(Status(StatusCode.OK))
254
271
 
@@ -96,7 +96,6 @@ def converse(gen_ai_endpoint, version, environment, application_name, tracer,
96
96
 
97
97
  try:
98
98
  message_prompt = method_kwargs.get("messages", "")
99
- print(message_prompt)
100
99
  formatted_messages = []
101
100
  for message in message_prompt:
102
101
  role = message["role"]
@@ -144,10 +143,19 @@ def converse(gen_ai_endpoint, version, environment, application_name, tracer,
144
143
  cost)
145
144
 
146
145
  if trace_content:
147
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
148
- prompt)
149
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
150
- response["output"]["message"]["content"][0]["text"])
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
+ # pylint: disable=line-too-long
156
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response["output"]["message"]["content"][0]["text"],
157
+ },
158
+ )
151
159
 
152
160
  span.set_status(Status(StatusCode.OK))
153
161
 
@@ -89,8 +89,12 @@ def embed(gen_ai_endpoint, version, environment, application_name, tracer,
89
89
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
90
90
  cost)
91
91
  if trace_content:
92
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
93
- prompt)
92
+ span.add_event(
93
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
94
+ attributes={
95
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
96
+ },
97
+ )
94
98
 
95
99
  span.set_status(Status(StatusCode.OK))
96
100
 
@@ -205,7 +209,7 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
205
209
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
206
210
  response.generation_id)
207
211
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
208
- response.finish_reason)
212
+ [response.finish_reason])
209
213
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
210
214
  response.meta.billed_units.input_tokens)
211
215
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
@@ -215,11 +219,20 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
215
219
  response.meta.billed_units.output_tokens)
216
220
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
217
221
  cost)
222
+
218
223
  if trace_content:
219
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
220
- kwargs.get("message", ""))
221
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
222
- response.text)
224
+ span.add_event(
225
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
226
+ attributes={
227
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("message", ""),
228
+ },
229
+ )
230
+ span.add_event(
231
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
232
+ attributes={
233
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.text,
234
+ },
235
+ )
223
236
 
224
237
  span.set_status(Status(StatusCode.OK))
225
238
 
@@ -348,7 +361,7 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
348
361
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
349
362
  response_id)
350
363
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
351
- finish_reason)
364
+ [finish_reason])
352
365
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
353
366
  prompt_tokens)
354
367
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
@@ -358,10 +371,18 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
358
371
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
359
372
  cost)
360
373
  if trace_content:
361
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
362
- kwargs.get("message", ""))
363
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
364
- llmresponse)
374
+ span.add_event(
375
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
376
+ attributes={
377
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("message", ""),
378
+ },
379
+ )
380
+ span.add_event(
381
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
382
+ attributes={
383
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
384
+ },
385
+ )
365
386
 
366
387
  span.set_status(Status(StatusCode.OK))
367
388
 
@@ -80,8 +80,12 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
80
80
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
81
81
  cost)
82
82
  if trace_content:
83
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
84
- str(kwargs.get("text", "")))
83
+ span.add_event(
84
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
85
+ attributes={
86
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: str(kwargs.get("text", "")),
87
+ },
88
+ )
85
89
 
86
90
  span.set_status(Status(StatusCode.OK))
87
91
 
@@ -86,8 +86,12 @@ def generate(gen_ai_endpoint, version, environment, application_name,
86
86
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
87
87
  cost)
88
88
  if trace_content:
89
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
90
- str(kwargs.get("text", "")))
89
+ span.add_event(
90
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
91
+ attributes={
92
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: str(kwargs.get("text", "")),
93
+ },
94
+ )
91
95
 
92
96
  span.set_status(Status(StatusCode.OK))
93
97
 
@@ -107,10 +107,18 @@ def generate(gen_ai_endpoint, version, environment, application_name,
107
107
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
108
108
  True)
109
109
  if trace_content:
110
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
111
- prompt)
112
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
113
- llmresponse)
110
+ span.add_event(
111
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
112
+ attributes={
113
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
114
+ },
115
+ )
116
+ span.add_event(
117
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
118
+ attributes={
119
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
120
+ },
121
+ )
114
122
 
115
123
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
116
124
  prompt_tokens)
@@ -195,10 +203,18 @@ def generate(gen_ai_endpoint, version, environment, application_name,
195
203
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
196
204
  False)
197
205
  if trace_content:
198
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
199
- prompt)
200
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
201
- response)
206
+ span.add_event(
207
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
208
+ attributes={
209
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
210
+ },
211
+ )
212
+ span.add_event(
213
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
214
+ attributes={
215
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response,
216
+ },
217
+ )
202
218
 
203
219
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
204
220
  prompt_tokens)
@@ -313,8 +329,12 @@ def embed(gen_ai_endpoint, version, environment, application_name,
313
329
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
314
330
  cost)
315
331
  if trace_content:
316
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
317
- prompt)
332
+ span.add_event(
333
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
334
+ attributes={
335
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
336
+ },
337
+ )
318
338
 
319
339
  span.set_status(Status(StatusCode.OK))
320
340
 
@@ -141,10 +141,18 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
141
141
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
142
142
  cost)
143
143
  if trace_content:
144
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
145
- prompt)
146
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
147
- llmresponse)
144
+ span.add_event(
145
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
146
+ attributes={
147
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
148
+ },
149
+ )
150
+ span.add_event(
151
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
152
+ attributes={
153
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
154
+ },
155
+ )
148
156
 
149
157
  span.set_status(Status(StatusCode.OK))
150
158
 
@@ -237,8 +245,12 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
237
245
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
238
246
  False)
239
247
  if trace_content:
240
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
241
- prompt)
248
+ span.add_event(
249
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
250
+ attributes={
251
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
252
+ },
253
+ )
242
254
 
243
255
  # Set span attributes when tools is not passed to the function call
244
256
  if "tools" not in kwargs:
@@ -254,23 +266,31 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
254
266
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
255
267
  response.usage.total_tokens)
256
268
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
257
- response.choices[0].finish_reason)
269
+ [response.choices[0].finish_reason])
258
270
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
259
271
  cost)
260
272
 
261
273
  # Set span attributes for when n = 1 (default)
262
274
  if "n" not in kwargs or kwargs["n"] == 1:
263
275
  if trace_content:
264
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
265
- response.choices[0].message.content)
276
+ span.add_event(
277
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
278
+ attributes={
279
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content,
280
+ },
281
+ )
266
282
 
267
283
  # Set span attributes for when n > 0
268
284
  else:
269
285
  i = 0
270
286
  while i < kwargs["n"] and trace_content is True:
271
287
  attribute_name = f"gen_ai.completion.{i}"
272
- span.set_attribute(attribute_name,
273
- response.choices[i].message.content)
288
+ span.add_event(
289
+ name=attribute_name,
290
+ attributes={
291
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].message.content,
292
+ },
293
+ )
274
294
  i += 1
275
295
 
276
296
  # Return original response
@@ -141,10 +141,18 @@ def chat(gen_ai_endpoint, version, environment, application_name,
141
141
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
142
142
  cost)
143
143
  if trace_content:
144
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
145
- prompt)
146
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
147
- llmresponse)
144
+ span.add_event(
145
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
146
+ attributes={
147
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
148
+ },
149
+ )
150
+ span.add_event(
151
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
152
+ attributes={
153
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
154
+ },
155
+ )
148
156
 
149
157
  span.set_status(Status(StatusCode.OK))
150
158
 
@@ -237,8 +245,12 @@ def chat(gen_ai_endpoint, version, environment, application_name,
237
245
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
238
246
  False)
239
247
  if trace_content:
240
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
241
- prompt)
248
+ span.add_event(
249
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
250
+ attributes={
251
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
252
+ },
253
+ )
242
254
 
243
255
  # Set span attributes when tools is not passed to the function call
244
256
  if "tools" not in kwargs:
@@ -254,23 +266,31 @@ def chat(gen_ai_endpoint, version, environment, application_name,
254
266
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
255
267
  response.usage.total_tokens)
256
268
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
257
- response.choices[0].finish_reason)
269
+ [response.choices[0].finish_reason])
258
270
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
259
271
  cost)
260
272
 
261
273
  # Set span attributes for when n = 1 (default)
262
274
  if "n" not in kwargs or kwargs["n"] == 1:
263
275
  if trace_content:
264
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
265
- response.choices[0].message.content)
276
+ span.add_event(
277
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
278
+ attributes={
279
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content,
280
+ },
281
+ )
266
282
 
267
283
  # Set span attributes for when n > 0
268
284
  else:
269
285
  i = 0
270
286
  while i < kwargs["n"] and trace_content is True:
271
287
  attribute_name = f"gen_ai.completion.{i}"
272
- span.set_attribute(attribute_name,
273
- response.choices[i].message.content)
288
+ span.add_event(
289
+ name=attribute_name,
290
+ attributes={
291
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].message.content,
292
+ },
293
+ )
274
294
  i += 1
275
295
 
276
296
  # Return original response
@@ -103,7 +103,7 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
103
103
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
104
104
  False)
105
105
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
106
- response.choices[0].finish_reason)
106
+ [response.choices[0].finish_reason])
107
107
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
108
108
  response.usage.prompt_tokens)
109
109
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
@@ -113,10 +113,19 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
113
113
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
114
114
  cost)
115
115
  if trace_content:
116
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
117
- prompt)
118
- # pylint: disable=line-too-long
119
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION, response.choices[0].message.content if response.choices[0].message.content else "")
116
+ span.add_event(
117
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
118
+ attributes={
119
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
120
+ },
121
+ )
122
+ span.add_event(
123
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
124
+ attributes={
125
+ # pylint: disable=line-too-long
126
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content if response.choices[0].message.content else "",
127
+ },
128
+ )
120
129
 
121
130
  span.set_status(Status(StatusCode.OK))
122
131
 
@@ -260,7 +269,7 @@ def async_chat_stream(gen_ai_endpoint, version, environment, application_name,
260
269
  span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
261
270
  True)
262
271
  span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
263
- finish_reason)
272
+ [finish_reason])
264
273
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
265
274
  prompt_tokens)
266
275
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
@@ -270,10 +279,18 @@ def async_chat_stream(gen_ai_endpoint, version, environment, application_name,
270
279
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
271
280
  cost)
272
281
  if trace_content:
273
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
274
- prompt)
275
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_COMPLETION,
276
- llmresponse)
282
+ span.add_event(
283
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
284
+ attributes={
285
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
286
+ },
287
+ )
288
+ span.add_event(
289
+ name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
290
+ attributes={
291
+ SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
292
+ },
293
+ )
277
294
 
278
295
  span.set_status(Status(StatusCode.OK))
279
296
 
@@ -378,8 +395,12 @@ def async_embeddings(gen_ai_endpoint, version, environment, application_name,
378
395
  span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
379
396
  cost)
380
397
  if trace_content:
381
- span.set_attribute(SemanticConvetion.GEN_AI_CONTENT_PROMPT,
382
- prompt)
398
+ span.add_event(
399
+ name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
400
+ attributes={
401
+ SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
402
+ },
403
+ )
383
404
 
384
405
  span.set_status(Status(StatusCode.OK))
385
406