@@ -290,27 +290,39 @@ def _send_logs_from_messages(logger: Logger, messages, attributes: Attributes, c
290
290
if message ["role" ] == "system" or message ["role" ] == "developer" :
291
291
if message ["role" ] == "developer" :
292
292
body ["role" ] = message ["role" ]
293
- log = LogRecord (event_name = EVENT_GEN_AI_SYSTEM_MESSAGE , body = body , attributes = attributes )
293
+ # keep compat on the exported attributes with Event
294
+ log = LogRecord (
295
+ event_name = EVENT_GEN_AI_SYSTEM_MESSAGE ,
296
+ body = body ,
297
+ attributes = {** attributes , "event.name" : EVENT_GEN_AI_SYSTEM_MESSAGE },
298
+ )
294
299
logger .emit (log )
295
300
elif message ["role" ] == "user" :
296
- log = LogRecord (event_name = EVENT_GEN_AI_USER_MESSAGE , body = body , attributes = attributes )
301
+ # keep compat on the exported attributes with Event
302
+ log = LogRecord (
303
+ event_name = EVENT_GEN_AI_USER_MESSAGE ,
304
+ body = body ,
305
+ attributes = {** attributes , "event.name" : EVENT_GEN_AI_USER_MESSAGE },
306
+ )
297
307
logger .emit (log )
298
308
elif message ["role" ] == "assistant" :
299
309
tool_calls = _serialize_tool_calls_for_log (message .get ("tool_calls" , []))
300
310
if tool_calls :
301
311
body ["tool_calls" ] = tool_calls
312
+ # keep compat on the exported attributes with Event
302
313
log = LogRecord (
303
314
event_name = EVENT_GEN_AI_ASSISTANT_MESSAGE ,
304
315
body = body ,
305
- attributes = attributes ,
316
+ attributes = { ** attributes , "event.name" : EVENT_GEN_AI_ASSISTANT_MESSAGE } ,
306
317
)
307
318
logger .emit (log )
308
319
elif message ["role" ] == "tool" :
309
320
body ["id" ] = message ["tool_call_id" ]
321
+ # keep compat on the exported attributes with Event
310
322
log = LogRecord (
311
323
event_name = EVENT_GEN_AI_TOOL_MESSAGE ,
312
324
body = body ,
313
- attributes = attributes ,
325
+ attributes = { ** attributes , "event.name" : EVENT_GEN_AI_TOOL_MESSAGE } ,
314
326
)
315
327
logger .emit (log )
316
328
@@ -324,7 +336,10 @@ def _send_logs_from_choices(logger: Logger, choices, attributes: Attributes, cap
324
336
if capture_message_content and choice .message .content :
325
337
body ["message" ]["content" ] = choice .message .content
326
338
327
- log = LogRecord (event_name = EVENT_GEN_AI_CHOICE , body = body , attributes = attributes )
339
+ # keep compat on the exported attributes with Event
340
+ log = LogRecord (
341
+ event_name = EVENT_GEN_AI_CHOICE , body = body , attributes = {** attributes , "event.name" : EVENT_GEN_AI_CHOICE }
342
+ )
328
343
logger .emit (log )
329
344
330
345
@@ -366,10 +381,11 @@ def _send_logs_from_stream_choices(
366
381
}
367
382
# StreamWrapper is consumed after start_as_current_span exits, so capture the current span
368
383
ctx = span .get_span_context ()
384
+ # keep compat on the exported attributes with Event
369
385
log = LogRecord (
370
386
event_name = EVENT_GEN_AI_CHOICE ,
371
387
body = body ,
372
- attributes = attributes ,
388
+ attributes = { ** attributes , "event.name" : EVENT_GEN_AI_CHOICE } ,
373
389
trace_id = ctx .trace_id ,
374
390
span_id = ctx .span_id ,
375
391
trace_flags = ctx .trace_flags ,
0 commit comments