Skip to content

Commit edc808f

Browse files
update tests
1 parent 14dcdd2 commit edc808f

14 files changed

Lines changed: 143 additions & 182 deletions

tests/observability/core/test_baggage_builder.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ def test_all_baggage_keys(self):
8383
BaggageBuilder()
8484
.tenant_id("tenant-1")
8585
.agent_id("agent-1")
86-
.agent_auid("auid-1")
87-
.agent_upn("upn-1")
86+
.agentic_user_id("auid-1")
87+
.agentic_user_email("upn-1")
8888
.agent_blueprint_id("blueprint-1")
89-
.caller_id("caller-1")
90-
.caller_client_ip("192.168.1.100")
89+
.user_id("caller-1")
90+
.user_client_ip("192.168.1.100")
9191
.build()
9292
):
9393
current_baggage = baggage.get_all()
@@ -153,10 +153,10 @@ def test_baggage_reset_after_scope_exit(self):
153153
BaggageBuilder()
154154
.tenant_id("test-tenant")
155155
.agent_id("test-agent")
156-
.agent_auid("test-auid")
157-
.agent_upn("test-upn")
156+
.agentic_user_id("test-auid")
157+
.agentic_user_email("test-upn")
158158
.agent_blueprint_id("test-blueprint")
159-
.caller_id("test-caller")
159+
.user_id("test-caller")
160160
.build()
161161
):
162162
# Inside scope - verify all baggage values are set
@@ -271,29 +271,29 @@ def test_channel_links_method(self):
271271
"https://teams.microsoft.com/channel/123",
272272
)
273273

274-
def test_caller_client_ip_method(self):
275-
"""Test caller_client_ip method sets client IP baggage with validation."""
274+
def test_user_client_ip_method(self):
275+
"""Test user_client_ip method sets client IP baggage with validation."""
276276
# Should exist and be callable
277-
self.assertTrue(hasattr(self.builder, "caller_client_ip"))
278-
self.assertTrue(callable(self.builder.caller_client_ip))
277+
self.assertTrue(hasattr(self.builder, "user_client_ip"))
278+
self.assertTrue(callable(self.builder.user_client_ip))
279279

280280
# Test valid IPv4 address
281-
with BaggageBuilder().caller_client_ip("192.168.1.100").build():
281+
with BaggageBuilder().user_client_ip("192.168.1.100").build():
282282
current_baggage = baggage.get_all()
283283
self.assertEqual(current_baggage.get(GEN_AI_CALLER_CLIENT_IP_KEY), "192.168.1.100")
284284

285285
# Test valid IPv6 address
286-
with BaggageBuilder().caller_client_ip("2001:db8::1").build():
286+
with BaggageBuilder().user_client_ip("2001:db8::1").build():
287287
current_baggage = baggage.get_all()
288288
self.assertEqual(current_baggage.get(GEN_AI_CALLER_CLIENT_IP_KEY), "2001:db8::1")
289289

290290
# Test None value (should not set baggage)
291-
with BaggageBuilder().caller_client_ip(None).build():
291+
with BaggageBuilder().user_client_ip(None).build():
292292
current_baggage = baggage.get_all()
293293
self.assertIsNone(current_baggage.get(GEN_AI_CALLER_CLIENT_IP_KEY))
294294

295295
# Test invalid IP address (should be handled gracefully now)
296-
with BaggageBuilder().caller_client_ip("not.an.ip.address").build():
296+
with BaggageBuilder().user_client_ip("not.an.ip.address").build():
297297
current_baggage = baggage.get_all()
298298
# Should be None due to proper exception handling
299299
self.assertIsNone(current_baggage.get(GEN_AI_CALLER_CLIENT_IP_KEY))

tests/observability/core/test_custom_start_end_time.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
from microsoft_agents_a365.observability.core import (
1515
AgentDetails,
1616
ExecuteToolScope,
17-
TenantDetails,
17+
Request,
18+
SpanDetails,
1819
ToolCallDetails,
1920
configure,
2021
get_tracer_provider,
@@ -38,7 +39,6 @@ def setUpClass(cls):
3839
service_namespace="test-namespace",
3940
)
4041
# Create test data
41-
cls.tenant_details = TenantDetails(tenant_id="12345678-1234-5678-1234-567812345678")
4242
cls.agent_details = AgentDetails(
4343
agent_id="test-agent-123",
4444
agent_name="Test Agent",
@@ -85,11 +85,10 @@ def test_custom_start_and_end_time_with_datetime(self):
8585
custom_end = datetime(2023, 11, 14, 22, 13, 25, tzinfo=UTC) # 5 seconds later
8686

8787
scope = ExecuteToolScope.start(
88+
Request(),
8889
self.tool_details,
8990
self.agent_details,
90-
self.tenant_details,
91-
start_time=custom_start,
92-
end_time=custom_end,
91+
span_details=SpanDetails(start_time=custom_start, end_time=custom_end),
9392
)
9493
scope.dispose()
9594

@@ -111,11 +110,10 @@ def test_set_end_time_overrides_end_time(self):
111110
later_end = datetime(2023, 11, 14, 22, 13, 48, tzinfo=UTC) # 8 seconds after start
112111

113112
scope = ExecuteToolScope.start(
113+
Request(),
114114
self.tool_details,
115115
self.agent_details,
116-
self.tenant_details,
117-
start_time=custom_start,
118-
end_time=initial_end,
116+
span_details=SpanDetails(start_time=custom_start, end_time=initial_end),
119117
)
120118
# Override the end time
121119
scope.set_end_time(later_end)
@@ -131,9 +129,9 @@ def test_wall_clock_time_used_when_no_custom_times(self):
131129
"""Test that wall-clock time is used when no custom times are provided."""
132130
before = time.time_ns()
133131
scope = ExecuteToolScope.start(
132+
Request(),
134133
self.tool_details,
135134
self.agent_details,
136-
self.tenant_details,
137135
)
138136
scope.dispose()
139137
after = time.time_ns()
@@ -153,10 +151,10 @@ def test_only_start_time_provided(self):
153151
custom_start = datetime(2023, 11, 14, 22, 13, 20, tzinfo=UTC)
154152

155153
scope = ExecuteToolScope.start(
154+
Request(),
156155
self.tool_details,
157156
self.agent_details,
158-
self.tenant_details,
159-
start_time=custom_start,
157+
span_details=SpanDetails(start_time=custom_start),
160158
)
161159
scope.dispose()
162160

tests/observability/core/test_execute_tool_scope.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
AgentDetails,
1212
Channel,
1313
ExecuteToolScope,
14-
ExecutionType,
1514
Request,
16-
TenantDetails,
15+
SpanDetails,
1716
ToolCallDetails,
1817
configure,
1918
extract_context_from_headers,
@@ -44,7 +43,6 @@ def setUpClass(cls):
4443
service_namespace="test-namespace",
4544
)
4645
# Create test data
47-
cls.tenant_details = TenantDetails(tenant_id="12345678-1234-5678-1234-567812345678")
4846
cls.agent_details = AgentDetails(
4947
agent_id="test-agent-123",
5048
agent_name="Test Agent",
@@ -83,7 +81,7 @@ def tearDown(self):
8381

8482
def test_record_response_method_exists(self):
8583
"""Test that record_response method exists on ExecuteToolScope."""
86-
scope = ExecuteToolScope.start(self.tool_details, self.agent_details, self.tenant_details)
84+
scope = ExecuteToolScope.start(Request(), self.tool_details, self.agent_details)
8785

8886
if scope is not None:
8987
# Test that the method exists
@@ -95,14 +93,11 @@ def test_request_metadata_set_on_span(self):
9593
"""Test that request source metadata is set on span attributes."""
9694
request = Request(
9795
content="Execute tool with request metadata",
98-
execution_type=ExecutionType.AGENT_TO_AGENT,
9996
session_id="session-xyz",
10097
channel=Channel(name="Channel 1", link="Link to channel"),
10198
)
10299

103-
scope = ExecuteToolScope.start(
104-
self.tool_details, self.agent_details, self.tenant_details, request
105-
)
100+
scope = ExecuteToolScope.start(request, self.tool_details, self.agent_details)
106101

107102
if scope is not None:
108103
scope.dispose()
@@ -143,10 +138,10 @@ def test_execute_tool_scope_with_parent_context(self):
143138
parent_context = extract_context_from_headers({"traceparent": traceparent})
144139

145140
with ExecuteToolScope.start(
141+
Request(),
146142
self.tool_details,
147143
self.agent_details,
148-
self.tenant_details,
149-
parent_context=parent_context,
144+
span_details=SpanDetails(parent_context=parent_context),
150145
):
151146
pass
152147

@@ -167,7 +162,7 @@ def test_execute_tool_scope_with_parent_context(self):
167162

168163
def test_span_kind_defaults_to_internal(self):
169164
"""Test that ExecuteToolScope defaults to SpanKind.INTERNAL."""
170-
scope = ExecuteToolScope.start(self.tool_details, self.agent_details, self.tenant_details)
165+
scope = ExecuteToolScope.start(Request(), self.tool_details, self.agent_details)
171166
scope.dispose()
172167

173168
finished_spans = self.span_exporter.get_finished_spans()
@@ -177,7 +172,10 @@ def test_span_kind_defaults_to_internal(self):
177172
def test_span_kind_override_to_client(self):
178173
"""Test that ExecuteToolScope accepts SpanKind.CLIENT override."""
179174
scope = ExecuteToolScope.start(
180-
self.tool_details, self.agent_details, self.tenant_details, span_kind=SpanKind.CLIENT
175+
Request(),
176+
self.tool_details,
177+
self.agent_details,
178+
span_details=SpanDetails(span_kind=SpanKind.CLIENT),
181179
)
182180
scope.dispose()
183181

tests/observability/core/test_inference_scope.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99
import pytest
1010
from microsoft_agents_a365.observability.core import (
1111
Channel,
12-
ExecutionType,
1312
InferenceCallDetails,
1413
InferenceOperationType,
1514
InferenceScope,
1615
Request,
17-
TenantDetails,
16+
SpanDetails,
1817
configure,
1918
extract_context_from_headers,
2019
get_tracer_provider,
@@ -43,9 +42,8 @@ def setUpClass(cls):
4342
service_name="test-inference-service",
4443
service_namespace="test-namespace",
4544
)
46-
# Create test agent and tenant details
45+
# Create test agent details
4746
cls.agent_details = AgentDetails(agent_id="test-inference-agent")
48-
cls.tenant_details = TenantDetails(tenant_id="12345678-1234-5678-1234-567812345678")
4947

5048
def setUp(self):
5149
super().setUp()
@@ -119,7 +117,7 @@ def test_inference_scope_start_method(self):
119117
providerName="openai",
120118
)
121119

122-
scope = InferenceScope.start(details, self.agent_details, self.tenant_details)
120+
scope = InferenceScope.start(Request(), details, self.agent_details)
123121

124122
# Scope might be None if telemetry is disabled
125123
if scope is not None:
@@ -139,11 +137,10 @@ def test_inference_scope_with_request(self):
139137

140138
request = Request(
141139
content="What is the weather like?",
142-
execution_type=ExecutionType.EVENT_TO_AGENT,
143140
session_id="test-session-123",
144141
)
145142

146-
scope = InferenceScope.start(details, self.agent_details, self.tenant_details, request)
143+
scope = InferenceScope.start(request, details, self.agent_details)
147144

148145
# Test that scope can be created with request
149146
if scope is not None:
@@ -159,12 +156,11 @@ def test_request_metadata_set_on_span(self):
159156

160157
request = Request(
161158
content="Inference request with source metadata",
162-
execution_type=ExecutionType.AGENT_TO_AGENT,
163159
session_id="session-meta",
164160
channel=Channel(name="Channel 1", link="Link to channel"),
165161
)
166162

167-
scope = InferenceScope.start(details, self.agent_details, self.tenant_details, request)
163+
scope = InferenceScope.start(request, details, self.agent_details)
168164

169165
if scope is not None:
170166
scope.dispose()
@@ -205,7 +201,7 @@ def test_inference_scope_context_manager(self):
205201
outputTokens=50,
206202
)
207203

208-
scope = InferenceScope.start(details, self.agent_details, self.tenant_details)
204+
scope = InferenceScope.start(Request(), details, self.agent_details)
209205

210206
if scope is not None:
211207
# Test context manager usage
@@ -230,7 +226,7 @@ def test_inference_scope_dispose(self):
230226
providerName="openai",
231227
)
232228

233-
scope = InferenceScope.start(details, self.agent_details, self.tenant_details)
229+
scope = InferenceScope.start(Request(), details, self.agent_details)
234230

235231
if scope is not None:
236232
# Test manual dispose
@@ -246,7 +242,7 @@ def test_record_input_messages(self):
246242
providerName="openai",
247243
)
248244

249-
scope = InferenceScope.start(details, self.agent_details, self.tenant_details)
245+
scope = InferenceScope.start(Request(), details, self.agent_details)
250246

251247
if scope is not None:
252248
# Test recording input messages
@@ -263,7 +259,7 @@ def test_record_output_messages(self):
263259
providerName="openai",
264260
)
265261

266-
scope = InferenceScope.start(details, self.agent_details, self.tenant_details)
262+
scope = InferenceScope.start(Request(), details, self.agent_details)
267263

268264
if scope is not None:
269265
# Test recording output messages
@@ -280,7 +276,7 @@ def test_record_input_tokens(self):
280276
providerName="openai",
281277
)
282278

283-
scope = InferenceScope.start(details, self.agent_details, self.tenant_details)
279+
scope = InferenceScope.start(Request(), details, self.agent_details)
284280

285281
if scope is not None:
286282
# Test recording input tokens
@@ -296,7 +292,7 @@ def test_record_output_tokens(self):
296292
providerName="openai",
297293
)
298294

299-
scope = InferenceScope.start(details, self.agent_details, self.tenant_details)
295+
scope = InferenceScope.start(Request(), details, self.agent_details)
300296

301297
if scope is not None:
302298
# Test recording output tokens
@@ -312,7 +308,7 @@ def test_record_finish_reasons(self):
312308
providerName="openai",
313309
)
314310

315-
scope = InferenceScope.start(details, self.agent_details, self.tenant_details)
311+
scope = InferenceScope.start(Request(), details, self.agent_details)
316312

317313
if scope is not None:
318314
# Test recording finish reasons
@@ -329,7 +325,7 @@ def test_record_thought_process(self):
329325
providerName="openai",
330326
)
331327

332-
scope = InferenceScope.start(details, self.agent_details, self.tenant_details)
328+
scope = InferenceScope.start(Request(), details, self.agent_details)
333329

334330
if scope is not None:
335331
# Test recording thought process
@@ -354,7 +350,10 @@ def test_inference_scope_with_parent_context(self):
354350
parent_context = extract_context_from_headers({"traceparent": traceparent})
355351

356352
with InferenceScope.start(
357-
details, self.agent_details, self.tenant_details, parent_context=parent_context
353+
Request(),
354+
details,
355+
self.agent_details,
356+
span_details=SpanDetails(parent_context=parent_context),
358357
):
359358
pass
360359

0 commit comments

Comments
 (0)