@@ -290,27 +290,39 @@ def _send_logs_from_messages(logger: Logger, messages, attributes: Attributes, c
290290 if message ["role" ] == "system" or message ["role" ] == "developer" :
291291 if message ["role" ] == "developer" :
292292 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+ )
294299 logger .emit (log )
295300 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+ )
297307 logger .emit (log )
298308 elif message ["role" ] == "assistant" :
299309 tool_calls = _serialize_tool_calls_for_log (message .get ("tool_calls" , []))
300310 if tool_calls :
301311 body ["tool_calls" ] = tool_calls
312+ # keep compat on the exported attributes with Event
302313 log = LogRecord (
303314 event_name = EVENT_GEN_AI_ASSISTANT_MESSAGE ,
304315 body = body ,
305- attributes = attributes ,
316+ attributes = { ** attributes , "event.name" : EVENT_GEN_AI_ASSISTANT_MESSAGE } ,
306317 )
307318 logger .emit (log )
308319 elif message ["role" ] == "tool" :
309320 body ["id" ] = message ["tool_call_id" ]
321+ # keep compat on the exported attributes with Event
310322 log = LogRecord (
311323 event_name = EVENT_GEN_AI_TOOL_MESSAGE ,
312324 body = body ,
313- attributes = attributes ,
325+ attributes = { ** attributes , "event.name" : EVENT_GEN_AI_TOOL_MESSAGE } ,
314326 )
315327 logger .emit (log )
316328
@@ -324,7 +336,10 @@ def _send_logs_from_choices(logger: Logger, choices, attributes: Attributes, cap
324336 if capture_message_content and choice .message .content :
325337 body ["message" ]["content" ] = choice .message .content
326338
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+ )
328343 logger .emit (log )
329344
330345
@@ -366,10 +381,11 @@ def _send_logs_from_stream_choices(
366381 }
367382 # StreamWrapper is consumed after start_as_current_span exits, so capture the current span
368383 ctx = span .get_span_context ()
384+ # keep compat on the exported attributes with Event
369385 log = LogRecord (
370386 event_name = EVENT_GEN_AI_CHOICE ,
371387 body = body ,
372- attributes = attributes ,
388+ attributes = { ** attributes , "event.name" : EVENT_GEN_AI_CHOICE } ,
373389 trace_id = ctx .trace_id ,
374390 span_id = ctx .span_id ,
375391 trace_flags = ctx .trace_flags ,
0 commit comments