4040 LLMInvocation ,
4141 MessagePart ,
4242 OutputMessage ,
43- _BaseAgent ,
4443)
4544from opentelemetry .util .genai .utils import (
4645 ContentCapturingMode ,
@@ -390,51 +389,35 @@ def _get_embedding_response_attributes(
390389 return {key : value for key , value in optional_attrs if value is not None }
391390
392391
393- def _get_base_agent_common_attributes (
394- agent : _BaseAgent ,
395- ) -> dict [str , Any ]:
396- """Get common attributes shared by all agent operations (invoke_agent, create_agent)."""
397- optional_attrs = (
398- (GenAI .GEN_AI_REQUEST_MODEL , agent .request_model ),
399- (GenAI .GEN_AI_PROVIDER_NAME , agent .provider ),
400- (GenAI .GEN_AI_AGENT_NAME , agent .agent_name ),
401- (GenAI .GEN_AI_AGENT_ID , agent .agent_id ),
402- (GenAI .GEN_AI_AGENT_DESCRIPTION , agent .agent_description ),
403- (GenAI .GEN_AI_AGENT_VERSION , agent .agent_version ),
404- (server_attributes .SERVER_ADDRESS , agent .server_address ),
405- (server_attributes .SERVER_PORT , agent .server_port ),
406- )
407-
408- return {
409- GenAI .GEN_AI_OPERATION_NAME : agent .operation_name ,
410- ** {key : value for key , value in optional_attrs if value is not None },
411- }
412-
413-
414- def _get_base_agent_span_name (agent : _BaseAgent ) -> str :
415- """Get the span name for any agent operation."""
416- if agent .agent_name :
417- return f"{ agent .operation_name } { agent .agent_name } "
418- return agent .operation_name
392+ def _get_agent_span_name (invocation : AgentInvocation ) -> str :
393+ """Get the span name for an agent invocation."""
394+ if invocation .agent_name :
395+ return f"{ invocation .operation_name } { invocation .agent_name } "
396+ return invocation .operation_name
419397
420398
421399def _get_agent_common_attributes (
422400 invocation : AgentInvocation ,
423401) -> dict [str , Any ]:
424402 """Get common agent invocation attributes shared by finish() and error() paths."""
425- attrs = _get_base_agent_common_attributes (invocation )
426-
427- # Invoke-specific conditionally required attributes
428- invoke_attrs = (
403+ optional_attrs = (
404+ (GenAI .GEN_AI_REQUEST_MODEL , invocation .request_model ),
405+ (GenAI .GEN_AI_AGENT_NAME , invocation .agent_name ),
406+ (GenAI .GEN_AI_AGENT_ID , invocation .agent_id ),
407+ (GenAI .GEN_AI_AGENT_DESCRIPTION , invocation .agent_description ),
408+ ("gen_ai.agent.version" , invocation .agent_version ),
429409 (GenAI .GEN_AI_CONVERSATION_ID , invocation .conversation_id ),
430410 (GenAI .GEN_AI_DATA_SOURCE_ID , invocation .data_source_id ),
431411 (GenAI .GEN_AI_OUTPUT_TYPE , invocation .output_type ),
432- )
433- attrs .update (
434- {key : value for key , value in invoke_attrs if value is not None }
412+ (server_attributes .SERVER_ADDRESS , invocation .server_address ),
413+ (server_attributes .SERVER_PORT , invocation .server_port ),
435414 )
436415
437- return attrs
416+ return {
417+ GenAI .GEN_AI_OPERATION_NAME : invocation .operation_name ,
418+ GenAI .GEN_AI_PROVIDER_NAME : invocation .provider ,
419+ ** {key : value for key , value in optional_attrs if value is not None },
420+ }
438421
439422
440423def _get_agent_request_attributes (
@@ -485,11 +468,11 @@ def _get_agent_response_attributes(
485468 (GenAI .GEN_AI_USAGE_INPUT_TOKENS , invocation .input_tokens ),
486469 (GenAI .GEN_AI_USAGE_OUTPUT_TOKENS , invocation .output_tokens ),
487470 (
488- GenAI . GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS ,
471+ "gen_ai.usage.cache_creation_input_tokens" ,
489472 invocation .cache_creation_input_tokens ,
490473 ),
491474 (
492- GenAI . GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS ,
475+ "gen_ai.usage.cache_read_input_tokens" ,
493476 invocation .cache_read_input_tokens ,
494477 ),
495478 )
@@ -501,7 +484,7 @@ def _apply_agent_finish_attributes(
501484 span : Span , invocation : AgentInvocation
502485) -> None :
503486 """Apply attributes/messages common to agent finish() paths."""
504- span .update_name (_get_base_agent_span_name (invocation ))
487+ span .update_name (_get_agent_span_name (invocation ))
505488
506489 attributes : dict [str , Any ] = {}
507490 attributes .update (_get_agent_common_attributes (invocation ))
@@ -534,8 +517,7 @@ def _apply_agent_finish_attributes(
534517 "_get_embedding_request_attributes" ,
535518 "_get_embedding_response_attributes" ,
536519 "_get_embedding_span_name" ,
537- "_get_base_agent_common_attributes" ,
538- "_get_base_agent_span_name" ,
520+ "_get_agent_span_name" ,
539521 "_apply_agent_finish_attributes" ,
540522 "_get_system_instructions_for_span" ,
541523 "_get_agent_common_attributes" ,
0 commit comments