|
24 | 24 | from google.adk.models.llm_response import LlmResponse |
25 | 25 | from google.adk.sessions.in_memory_session_service import InMemorySessionService |
26 | 26 | from google.adk.telemetry.tracing import ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS |
| 27 | +from google.adk.telemetry.tracing import GEN_AI_AGENT_VERSION |
27 | 28 | from google.adk.telemetry.tracing import trace_agent_invocation |
28 | 29 | from google.adk.telemetry.tracing import trace_call_llm |
29 | 30 | from google.adk.telemetry.tracing import trace_inference_result |
@@ -119,6 +120,34 @@ async def test_trace_agent_invocation(mock_span_fixture): |
119 | 120 | mock.call('gen_ai.operation.name', 'invoke_agent'), |
120 | 121 | mock.call('gen_ai.agent.description', agent.description), |
121 | 122 | mock.call('gen_ai.agent.name', agent.name), |
| 123 | + mock.call(GEN_AI_AGENT_VERSION, ''), |
| 124 | + mock.call( |
| 125 | + 'gen_ai.conversation.id', |
| 126 | + invocation_context.session.id, |
| 127 | + ), |
| 128 | + mock.call(USER_ID, invocation_context.session.user_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 | +@pytest.mark.asyncio |
| 137 | +async def test_trace_agent_invocation_with_version(mock_span_fixture): |
| 138 | + """Test trace_agent_invocation sets span attributes correctly when version is provided.""" |
| 139 | + agent = LlmAgent(name='test_llm_agent', model='gemini-pro') |
| 140 | + agent.description = 'Test agent description' |
| 141 | + agent.version = '1.0.0' |
| 142 | + invocation_context = await _create_invocation_context(agent) |
| 143 | + |
| 144 | + trace_agent_invocation(mock_span_fixture, agent, invocation_context) |
| 145 | + |
| 146 | + expected_calls = [ |
| 147 | + mock.call('gen_ai.operation.name', 'invoke_agent'), |
| 148 | + mock.call('gen_ai.agent.description', agent.description), |
| 149 | + mock.call('gen_ai.agent.name', agent.name), |
| 150 | + mock.call(GEN_AI_AGENT_VERSION, agent.version), |
122 | 151 | mock.call( |
123 | 152 | 'gen_ai.conversation.id', |
124 | 153 | invocation_context.session.id, |
@@ -767,6 +796,7 @@ async def test_generate_content_span( |
767 | 796 |
|
768 | 797 | mock_span.set_attributes.assert_called_once_with({ |
769 | 798 | GEN_AI_AGENT_NAME: invocation_context.agent.name, |
| 799 | + GEN_AI_AGENT_VERSION: '', |
770 | 800 | GEN_AI_CONVERSATION_ID: invocation_context.session.id, |
771 | 801 | USER_ID: invocation_context.session.user_id, |
772 | 802 | 'gcp.vertex.agent.event_id': 'event-123', |
|
0 commit comments