|
21 | 21 | ) |
22 | 22 | from microsoft_agents_a365.observability.core.config import _telemetry_manager |
23 | 23 | from microsoft_agents_a365.observability.core.constants import ( |
| 24 | + GEN_AI_CALLER_AGENT_TYPE_KEY, |
24 | 25 | GEN_AI_CALLER_AGENT_USER_CLIENT_IP, |
25 | 26 | GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY, |
26 | 27 | GEN_AI_EXECUTION_SOURCE_NAME_KEY, |
27 | 28 | GEN_AI_EXECUTION_TYPE_KEY, |
28 | 29 | GEN_AI_INPUT_MESSAGES_KEY, |
29 | 30 | ) |
| 31 | +from microsoft_agents_a365.observability.core.models.agent_type import AgentType |
30 | 32 | from microsoft_agents_a365.observability.core.models.caller_details import CallerDetails |
31 | 33 | from microsoft_agents_a365.observability.core.opentelemetry_scope import OpenTelemetryScope |
32 | 34 | from opentelemetry.sdk.trace.export import SimpleSpanProcessor |
@@ -94,6 +96,7 @@ def setUpClass(cls): |
94 | 96 | agent_upn="agent@contoso.com", |
95 | 97 | tenant_id="tenant-789", |
96 | 98 | agent_client_ip="192.168.1.100", |
| 99 | + agent_type=AgentType.DECLARATIVE_AGENT, |
97 | 100 | ) |
98 | 101 |
|
99 | 102 | def setUp(self): |
@@ -232,6 +235,39 @@ def test_caller_agent_client_ip_in_scope(self): |
232 | 235 | span_attributes[GEN_AI_CALLER_AGENT_USER_CLIENT_IP], "192.168.1.100" |
233 | 236 | ) |
234 | 237 |
|
| 238 | + def test_caller_agent_type_in_scope(self): |
| 239 | + """Test that caller agent type is properly set when creating InvokeAgentScope.""" |
| 240 | + # Set up tracer to capture spans |
| 241 | + span_exporter = InMemorySpanExporter() |
| 242 | + tracer_provider = get_tracer_provider() |
| 243 | + tracer_provider.add_span_processor(SimpleSpanProcessor(span_exporter)) |
| 244 | + |
| 245 | + # Create scope with caller agent details that include agent_type |
| 246 | + scope = InvokeAgentScope.start( |
| 247 | + invoke_agent_details=self.invoke_details, |
| 248 | + tenant_details=self.tenant_details, |
| 249 | + caller_agent_details=self.caller_agent_details, |
| 250 | + ) |
| 251 | + |
| 252 | + # Verify scope was created and caller agent details contain the expected type |
| 253 | + self.assertIsNotNone(scope) |
| 254 | + self.assertEqual(self.caller_agent_details.agent_type, AgentType.DECLARATIVE_AGENT) |
| 255 | + scope.dispose() |
| 256 | + |
| 257 | + # Verify the agent type is set as a span attribute |
| 258 | + finished_spans = span_exporter.get_finished_spans() |
| 259 | + self.assertTrue(len(finished_spans) > 0, "Expected at least one span to be created") |
| 260 | + |
| 261 | + span = finished_spans[-1] |
| 262 | + span_attributes = getattr(span, "attributes", {}) or {} |
| 263 | + |
| 264 | + # Verify the caller agent type is set as a span attribute |
| 265 | + self.assertIn(GEN_AI_CALLER_AGENT_TYPE_KEY, span_attributes) |
| 266 | + self.assertEqual( |
| 267 | + span_attributes[GEN_AI_CALLER_AGENT_TYPE_KEY], |
| 268 | + AgentType.DECLARATIVE_AGENT.value, |
| 269 | + ) |
| 270 | + |
235 | 271 |
|
236 | 272 | if __name__ == "__main__": |
237 | 273 | # Run pytest only on the current file |
|
0 commit comments