@@ -91,6 +91,9 @@ def _set_agent_input_attribute(
9191
9292 user_content = invocation_context .user_content
9393 if user_content and user_content .parts :
94+ # set gen_ai.input attribute required by APMPlus
95+ span .set_attribute ("gen_ai.input" , user_content .model_dump (exclude_none = True ))
96+
9497 span .add_event (
9598 "gen_ai.user.message" ,
9699 {
@@ -128,6 +131,9 @@ def _set_agent_input_attribute(
128131def _set_agent_output_attribute (span : Span , llm_response : LlmResponse ) -> None :
129132 content = llm_response .content
130133 if content and content .parts :
134+ # set gen_ai.output attribute required by APMPlus
135+ span .set_attribute ("gen_ai.output" , content .model_dump (exclude_none = True ))
136+
131137 for idx , part in enumerate (content .parts ):
132138 if part .text :
133139 span .add_event (
@@ -173,10 +179,15 @@ def set_common_attributes_on_model_span(
173179 current_step_token_usage + int (prev_total_token_usage ) # type: ignore
174180 ) # we can ignore this warning, cause we manually set the attribute to int before
175181 invocation_span .set_attribute (
176- "gen_ai.usage.total_tokens" , accumulated_total_token_usage
182+ # record input/output token usage?
183+ "gen_ai.usage.total_tokens" ,
184+ accumulated_total_token_usage ,
177185 )
178186
179- if agent_run_span and agent_run_span .name .startswith ("agent_run" ):
187+ if agent_run_span and (
188+ agent_run_span .name .startswith ("agent_run" )
189+ or agent_run_span .name .startswith ("invoke_agent" )
190+ ):
180191 _set_agent_input_attribute (agent_run_span , invocation_context )
181192 _set_agent_output_attribute (agent_run_span , llm_response )
182193 for attr_name , attr_extractor in common_attributes .items ():
0 commit comments