|
26 | 26 | from google.adk.models.llm_response import LlmResponse |
27 | 27 | from google.adk.sessions.in_memory_session_service import InMemorySessionService |
28 | 28 | from google.adk.telemetry.tracing import ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS |
| 29 | +from google.adk.telemetry.tracing import GEN_AI_AGENT_VERSION |
29 | 30 | from google.adk.telemetry.tracing import trace_agent_invocation |
30 | 31 | from google.adk.telemetry.tracing import trace_call_llm |
31 | 32 | from google.adk.telemetry.tracing import trace_inference_result |
@@ -121,6 +122,33 @@ async def test_trace_agent_invocation(mock_span_fixture): |
121 | 122 | mock.call('gen_ai.operation.name', 'invoke_agent'), |
122 | 123 | mock.call('gen_ai.agent.description', agent.description), |
123 | 124 | mock.call('gen_ai.agent.name', agent.name), |
| 125 | + mock.call(GEN_AI_AGENT_VERSION, ''), |
| 126 | + mock.call( |
| 127 | + 'gen_ai.conversation.id', |
| 128 | + invocation_context.session.id, |
| 129 | + ), |
| 130 | + ] |
| 131 | + mock_span_fixture.set_attribute.assert_has_calls( |
| 132 | + expected_calls, any_order=True |
| 133 | + ) |
| 134 | + assert mock_span_fixture.set_attribute.call_count == len(expected_calls) |
| 135 | + |
| 136 | + |
| 137 | +@pytest.mark.asyncio |
| 138 | +async def test_trace_agent_invocation_with_version(mock_span_fixture): |
| 139 | + """Test trace_agent_invocation sets span attributes correctly when version is provided.""" |
| 140 | + agent = LlmAgent(name='test_llm_agent', model='gemini-pro') |
| 141 | + agent.description = 'Test agent description' |
| 142 | + agent.version = '1.0.0' |
| 143 | + invocation_context = await _create_invocation_context(agent) |
| 144 | + |
| 145 | + trace_agent_invocation(mock_span_fixture, agent, invocation_context) |
| 146 | + |
| 147 | + expected_calls = [ |
| 148 | + mock.call('gen_ai.operation.name', 'invoke_agent'), |
| 149 | + mock.call('gen_ai.agent.description', agent.description), |
| 150 | + mock.call('gen_ai.agent.name', agent.name), |
| 151 | + mock.call(GEN_AI_AGENT_VERSION, agent.version), |
124 | 152 | mock.call( |
125 | 153 | 'gen_ai.conversation.id', |
126 | 154 | invocation_context.session.id, |
@@ -769,6 +797,7 @@ async def test_generate_content_span( |
769 | 797 |
|
770 | 798 | mock_span.set_attributes.assert_called_once_with({ |
771 | 799 | GEN_AI_AGENT_NAME: invocation_context.agent.name, |
| 800 | + GEN_AI_AGENT_VERSION: '', |
772 | 801 | GEN_AI_CONVERSATION_ID: invocation_context.session.id, |
773 | 802 | USER_ID: invocation_context.session.user_id, |
774 | 803 | 'gcp.vertex.agent.event_id': 'event-123', |
@@ -1089,6 +1118,7 @@ async def test_generate_content_span_with_experimental_semconv( |
1089 | 1118 |
|
1090 | 1119 | mock_span.set_attributes.assert_called_once_with({ |
1091 | 1120 | GEN_AI_AGENT_NAME: invocation_context.agent.name, |
| 1121 | + GEN_AI_AGENT_VERSION: '', |
1092 | 1122 | GEN_AI_CONVERSATION_ID: invocation_context.session.id, |
1093 | 1123 | USER_ID: invocation_context.session.user_id, |
1094 | 1124 | 'gcp.vertex.agent.event_id': 'event-123', |
|
0 commit comments