Skip to content

Commit 919df7f

Browse files
CopilotnikhilNava
andcommitted
Update tests to reflect telemetry schema changes
Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
1 parent c8ac107 commit 919df7f

9 files changed

Lines changed: 55 additions & 162 deletions

File tree

tests/observability/core/test_baggage_builder.py

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,19 @@
55
import unittest
66

77
from microsoft_agents_a365.observability.core.constants import (
8-
CORRELATION_ID_KEY,
8+
CHANNEL_LINK_KEY,
9+
CHANNEL_NAME_KEY,
910
GEN_AI_AGENT_AUID_KEY,
1011
GEN_AI_AGENT_BLUEPRINT_ID_KEY,
1112
GEN_AI_AGENT_ID_KEY,
1213
GEN_AI_AGENT_UPN_KEY,
1314
GEN_AI_CALLER_CLIENT_IP_KEY,
1415
GEN_AI_CALLER_ID_KEY,
15-
GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY,
16-
GEN_AI_EXECUTION_SOURCE_NAME_KEY,
17-
HIRING_MANAGER_ID_KEY,
18-
OPERATION_SOURCE_KEY,
1916
SESSION_DESCRIPTION_KEY,
2017
SESSION_ID_KEY,
2118
TENANT_ID_KEY,
2219
)
2320
from microsoft_agents_a365.observability.core.middleware.baggage_builder import BaggageBuilder
24-
from microsoft_agents_a365.observability.core.models.operation_source import OperationSource
2521
from opentelemetry import baggage, context, trace
2622
from opentelemetry.sdk.trace import TracerProvider
2723
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
@@ -66,50 +62,41 @@ def test_baggage_builder_sets_values(self):
6662
"""Test that BaggageBuilder sets baggage values correctly."""
6763
tenant = "tenant-1"
6864
agent = "agent-1"
69-
corr = "corr-1"
7065

7166
# Use the baggage builder within a context
72-
with BaggageBuilder().tenant_id(tenant).agent_id(agent).correlation_id(corr).build():
67+
with BaggageBuilder().tenant_id(tenant).agent_id(agent).build():
7368
# Assert inside scope - baggage should be set
7469
current_baggage = baggage.get_all()
7570
self.assertEqual(current_baggage.get(TENANT_ID_KEY), tenant)
7671
self.assertEqual(current_baggage.get(GEN_AI_AGENT_ID_KEY), agent)
77-
self.assertEqual(current_baggage.get(CORRELATION_ID_KEY), corr)
7872

7973
# Assert after exiting scope - baggage should be restored/cleared
8074
current_baggage = baggage.get_all()
8175
self.assertIsNone(current_baggage.get(TENANT_ID_KEY))
8276
self.assertIsNone(current_baggage.get(GEN_AI_AGENT_ID_KEY))
83-
self.assertIsNone(current_baggage.get(CORRELATION_ID_KEY))
8477
print("✅ BaggageBuilder sets and restores values correctly!")
8578

8679
def test_all_baggage_keys(self):
8780
"""Test all baggage key setter methods."""
8881
with (
8982
BaggageBuilder()
90-
.operation_source(OperationSource.SDK)
9183
.tenant_id("tenant-1")
9284
.agent_id("agent-1")
9385
.agent_auid("auid-1")
9486
.agent_upn("upn-1")
9587
.agent_blueprint_id("blueprint-1")
96-
.correlation_id("corr-1")
9788
.caller_id("caller-1")
9889
.caller_client_ip("192.168.1.100")
99-
.hiring_manager_id("manager-1")
10090
.build()
10191
):
10292
current_baggage = baggage.get_all()
103-
self.assertEqual(current_baggage.get(OPERATION_SOURCE_KEY), OperationSource.SDK.value)
10493
self.assertEqual(current_baggage.get(TENANT_ID_KEY), "tenant-1")
10594
self.assertEqual(current_baggage.get(GEN_AI_AGENT_ID_KEY), "agent-1")
10695
self.assertEqual(current_baggage.get(GEN_AI_AGENT_AUID_KEY), "auid-1")
10796
self.assertEqual(current_baggage.get(GEN_AI_AGENT_UPN_KEY), "upn-1")
10897
self.assertEqual(current_baggage.get(GEN_AI_AGENT_BLUEPRINT_ID_KEY), "blueprint-1")
109-
self.assertEqual(current_baggage.get(CORRELATION_ID_KEY), "corr-1")
11098
self.assertEqual(current_baggage.get(GEN_AI_CALLER_ID_KEY), "caller-1")
11199
self.assertEqual(current_baggage.get(GEN_AI_CALLER_CLIENT_IP_KEY), "192.168.1.100")
112-
self.assertEqual(current_baggage.get(HIRING_MANAGER_ID_KEY), "manager-1")
113100
print("✅ All baggage keys work correctly!")
114101

115102
def test_baggage_propagates_to_child_spans(self):
@@ -163,44 +150,35 @@ def test_baggage_reset_after_scope_exit(self):
163150
# Use BaggageBuilder to set all possible values
164151
with (
165152
BaggageBuilder()
166-
.operation_source(OperationSource.SDK)
167153
.tenant_id("test-tenant")
168154
.agent_id("test-agent")
169155
.agent_auid("test-auid")
170156
.agent_upn("test-upn")
171157
.agent_blueprint_id("test-blueprint")
172-
.correlation_id("test-correlation")
173158
.caller_id("test-caller")
174-
.hiring_manager_id("test-manager")
175159
.build()
176160
):
177161
# Inside scope - verify all baggage values are set
178162
scoped_baggage = baggage.get_all()
179-
self.assertEqual(scoped_baggage.get(OPERATION_SOURCE_KEY), OperationSource.SDK.value)
180163
self.assertEqual(scoped_baggage.get(TENANT_ID_KEY), "test-tenant")
181164
self.assertEqual(scoped_baggage.get(GEN_AI_AGENT_ID_KEY), "test-agent")
182165
self.assertEqual(scoped_baggage.get(GEN_AI_AGENT_AUID_KEY), "test-auid")
183166
self.assertEqual(scoped_baggage.get(GEN_AI_AGENT_UPN_KEY), "test-upn")
184167
self.assertEqual(scoped_baggage.get(GEN_AI_AGENT_BLUEPRINT_ID_KEY), "test-blueprint")
185-
self.assertEqual(scoped_baggage.get(CORRELATION_ID_KEY), "test-correlation")
186168
self.assertEqual(scoped_baggage.get(GEN_AI_CALLER_ID_KEY), "test-caller")
187-
self.assertEqual(scoped_baggage.get(HIRING_MANAGER_ID_KEY), "test-manager")
188169
# Original baggage should still exist
189170
self.assertEqual(scoped_baggage.get("existing_key"), "existing_value")
190171

191172
# After exiting scope - verify ALL BaggageBuilder values are cleared
192173
final_baggage = baggage.get_all()
193174

194175
# All BaggageBuilder keys should be None/cleared
195-
self.assertIsNone(final_baggage.get(OPERATION_SOURCE_KEY))
196176
self.assertIsNone(final_baggage.get(TENANT_ID_KEY))
197177
self.assertIsNone(final_baggage.get(GEN_AI_AGENT_ID_KEY))
198178
self.assertIsNone(final_baggage.get(GEN_AI_AGENT_AUID_KEY))
199179
self.assertIsNone(final_baggage.get(GEN_AI_AGENT_UPN_KEY))
200180
self.assertIsNone(final_baggage.get(GEN_AI_AGENT_BLUEPRINT_ID_KEY))
201-
self.assertIsNone(final_baggage.get(CORRELATION_ID_KEY))
202181
self.assertIsNone(final_baggage.get(GEN_AI_CALLER_ID_KEY))
203-
self.assertIsNone(final_baggage.get(HIRING_MANAGER_ID_KEY))
204182

205183
# Original baggage should be restored
206184
self.assertEqual(final_baggage.get("existing_key"), "existing_value")
@@ -212,7 +190,6 @@ def test_set_pairs_accepts_dict_and_iterable(self):
212190
dict_pairs = {
213191
TENANT_ID_KEY: "tenant-x",
214192
GEN_AI_AGENT_ID_KEY: "agent-x",
215-
CORRELATION_ID_KEY: "corr-x",
216193
}
217194
iter_pairs = [
218195
(GEN_AI_AGENT_AUID_KEY, "auid-x"),
@@ -221,11 +198,10 @@ def test_set_pairs_accepts_dict_and_iterable(self):
221198

222199
# Also verify that None / whitespace values are ignored
223200
dict_pairs_with_ignored = {
224-
OPERATION_SOURCE_KEY: OperationSource.SDK.value,
225201
GEN_AI_CALLER_ID_KEY: None, # ignored
226202
}
227203
iter_pairs_with_ignored = [
228-
(HIRING_MANAGER_ID_KEY, " "), # ignored (whitespace)
204+
(SESSION_ID_KEY, " "), # ignored (whitespace)
229205
]
230206

231207
with (
@@ -239,13 +215,11 @@ def test_set_pairs_accepts_dict_and_iterable(self):
239215
baggage_contents = baggage.get_all()
240216
self.assertEqual(baggage_contents.get(TENANT_ID_KEY), "tenant-x")
241217
self.assertEqual(baggage_contents.get(GEN_AI_AGENT_ID_KEY), "agent-x")
242-
self.assertEqual(baggage_contents.get(CORRELATION_ID_KEY), "corr-x")
243218
self.assertEqual(baggage_contents.get(GEN_AI_AGENT_AUID_KEY), "auid-x")
244219
self.assertEqual(baggage_contents.get(GEN_AI_AGENT_UPN_KEY), "upn-x")
245-
self.assertEqual(baggage_contents.get(OPERATION_SOURCE_KEY), OperationSource.SDK.value)
246220
# Ignored values should not be present
247221
self.assertIsNone(baggage_contents.get(GEN_AI_CALLER_ID_KEY))
248-
self.assertIsNone(baggage_contents.get(HIRING_MANAGER_ID_KEY))
222+
self.assertIsNone(baggage_contents.get(SESSION_ID_KEY))
249223

250224
def test_source_metadata_name_method(self):
251225
"""Test deprecated source_metadata_name method - should delegate to channel_name."""
@@ -256,7 +230,7 @@ def test_source_metadata_name_method(self):
256230
# Should set channel name baggage through delegation
257231
with self.builder.source_metadata_name("test-channel").build():
258232
current_baggage = baggage.get_all()
259-
self.assertEqual(current_baggage.get(GEN_AI_EXECUTION_SOURCE_NAME_KEY), "test-channel")
233+
self.assertEqual(current_baggage.get(CHANNEL_NAME_KEY), "test-channel")
260234

261235
def test_source_metadata_description_method(self):
262236
"""Test deprecated source_metadata_description method - should delegate to channel_links."""
@@ -268,7 +242,7 @@ def test_source_metadata_description_method(self):
268242
with self.builder.source_metadata_description("test-description").build():
269243
current_baggage = baggage.get_all()
270244
self.assertEqual(
271-
current_baggage.get(GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY), "test-description"
245+
current_baggage.get(CHANNEL_LINK_KEY), "test-description"
272246
)
273247

274248
def test_session_id_method(self):
@@ -304,7 +278,7 @@ def test_channel_name_method(self):
304278
# Should set channel name baggage
305279
with self.builder.channel_name("Teams Channel").build():
306280
current_baggage = baggage.get_all()
307-
self.assertEqual(current_baggage.get(GEN_AI_EXECUTION_SOURCE_NAME_KEY), "Teams Channel")
281+
self.assertEqual(current_baggage.get(CHANNEL_NAME_KEY), "Teams Channel")
308282

309283
def test_channel_links_method(self):
310284
"""Test channel_links method sets channel description baggage."""
@@ -316,7 +290,7 @@ def test_channel_links_method(self):
316290
with self.builder.channel_links("https://teams.microsoft.com/channel/123").build():
317291
current_baggage = baggage.get_all()
318292
self.assertEqual(
319-
current_baggage.get(GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY),
293+
current_baggage.get(CHANNEL_LINK_KEY),
320294
"https://teams.microsoft.com/channel/123",
321295
)
322296

tests/observability/core/test_execute_tool_scope.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
)
2121
from microsoft_agents_a365.observability.core.config import _telemetry_manager
2222
from microsoft_agents_a365.observability.core.constants import (
23-
GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY,
24-
GEN_AI_EXECUTION_SOURCE_NAME_KEY,
23+
CHANNEL_LINK_KEY,
24+
CHANNEL_NAME_KEY,
2525
)
2626
from microsoft_agents_a365.observability.core.opentelemetry_scope import OpenTelemetryScope
2727
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
@@ -112,22 +112,22 @@ def test_request_metadata_set_on_span(self):
112112
span_attributes = getattr(span, "attributes", {}) or {}
113113

114114
self.assertIn(
115-
GEN_AI_EXECUTION_SOURCE_NAME_KEY,
115+
CHANNEL_NAME_KEY,
116116
span_attributes,
117117
"Expected source name to be set on span",
118118
)
119119
self.assertEqual(
120-
span_attributes[GEN_AI_EXECUTION_SOURCE_NAME_KEY],
120+
span_attributes[CHANNEL_NAME_KEY],
121121
request.source_metadata.name,
122122
)
123123

124124
self.assertIn(
125-
GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY,
125+
CHANNEL_LINK_KEY,
126126
span_attributes,
127127
"Expected source description to be set on span",
128128
)
129129
self.assertEqual(
130-
span_attributes[GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY],
130+
span_attributes[CHANNEL_LINK_KEY],
131131
request.source_metadata.description,
132132
)
133133

tests/observability/core/test_inference_scope.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
from microsoft_agents_a365.observability.core.agent_details import AgentDetails
2222
from microsoft_agents_a365.observability.core.config import _telemetry_manager
2323
from microsoft_agents_a365.observability.core.constants import (
24-
GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY,
25-
GEN_AI_EXECUTION_SOURCE_NAME_KEY,
24+
CHANNEL_LINK_KEY,
25+
CHANNEL_NAME_KEY,
2626
)
2727
from microsoft_agents_a365.observability.core.opentelemetry_scope import OpenTelemetryScope
2828
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
@@ -178,22 +178,22 @@ def test_request_metadata_set_on_span(self):
178178
span_attributes = getattr(span, "attributes", {}) or {}
179179

180180
self.assertIn(
181-
GEN_AI_EXECUTION_SOURCE_NAME_KEY,
181+
CHANNEL_NAME_KEY,
182182
span_attributes,
183183
"Expected source name to be set on span",
184184
)
185185
self.assertEqual(
186-
span_attributes[GEN_AI_EXECUTION_SOURCE_NAME_KEY],
186+
span_attributes[CHANNEL_NAME_KEY],
187187
request.source_metadata.name,
188188
)
189189

190190
self.assertIn(
191-
GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY,
191+
CHANNEL_LINK_KEY,
192192
span_attributes,
193193
"Expected source description to be set on span",
194194
)
195195
self.assertEqual(
196-
span_attributes[GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY],
196+
span_attributes[CHANNEL_LINK_KEY],
197197
request.source_metadata.description,
198198
)
199199

tests/observability/core/test_invoke_agent_scope.py

Lines changed: 8 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@
2121
)
2222
from microsoft_agents_a365.observability.core.config import _telemetry_manager
2323
from microsoft_agents_a365.observability.core.constants import (
24-
GEN_AI_CALLER_AGENT_TYPE_KEY,
25-
GEN_AI_CALLER_AGENT_USER_CLIENT_IP,
26-
GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY,
27-
GEN_AI_EXECUTION_SOURCE_NAME_KEY,
24+
CHANNEL_LINK_KEY,
25+
CHANNEL_NAME_KEY,
2826
GEN_AI_EXECUTION_TYPE_KEY,
2927
GEN_AI_INPUT_MESSAGES_KEY,
3028
)
31-
from microsoft_agents_a365.observability.core.models.agent_type import AgentType
3229
from microsoft_agents_a365.observability.core.models.caller_details import CallerDetails
3330
from microsoft_agents_a365.observability.core.opentelemetry_scope import OpenTelemetryScope
3431
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
@@ -82,8 +79,7 @@ def setUpClass(cls):
8279
caller_id="user-123",
8380
caller_upn="user@contoso.com",
8481
caller_name="John Doe",
85-
caller_user_id="user-id-456",
86-
tenant_id="tenant-789",
82+
caller_client_ip="192.168.1.100",
8783
)
8884

8985
# Create caller agent details (agentic caller)
@@ -95,8 +91,7 @@ def setUpClass(cls):
9591
agent_auid="auid-123",
9692
agent_upn="agent@contoso.com",
9793
tenant_id="tenant-789",
98-
agent_client_ip="192.168.1.100",
99-
agent_type=AgentType.DECLARATIVE_AGENT,
94+
agent_platform_id="platform-123",
10095
)
10196

10297
def setUp(self):
@@ -176,16 +171,16 @@ def test_request_attributes_set_on_span(self):
176171

177172
# Verify mock data request parameters are in span attributes
178173
# Check source channel name from mock data
179-
if GEN_AI_EXECUTION_SOURCE_NAME_KEY in span_attributes:
174+
if CHANNEL_NAME_KEY in span_attributes:
180175
self.assertEqual(
181-
span_attributes[GEN_AI_EXECUTION_SOURCE_NAME_KEY],
176+
span_attributes[CHANNEL_NAME_KEY],
182177
self.source_metadata.name, # From cls.source_metadata.name
183178
)
184179

185180
# Check source channel description from mock data
186-
if GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY in span_attributes:
181+
if CHANNEL_LINK_KEY in span_attributes:
187182
self.assertEqual(
188-
span_attributes[GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY],
183+
span_attributes[CHANNEL_LINK_KEY],
189184
self.source_metadata.description, # From cls.source_metadata.description
190185
)
191186

@@ -204,70 +199,6 @@ def test_request_attributes_set_on_span(self):
204199
input_messages,
205200
)
206201

207-
def test_caller_agent_client_ip_in_scope(self):
208-
"""Test that caller agent client IP is properly handled when creating InvokeAgentScope."""
209-
# Set up tracer to capture spans
210-
span_exporter = InMemorySpanExporter()
211-
tracer_provider = get_tracer_provider()
212-
tracer_provider.add_span_processor(SimpleSpanProcessor(span_exporter))
213-
214-
# Create scope with caller agent details that include client IP
215-
scope = InvokeAgentScope.start(
216-
invoke_agent_details=self.invoke_details,
217-
tenant_details=self.tenant_details,
218-
caller_agent_details=self.caller_agent_details, # Contains agent_client_ip="192.168.1.100"
219-
)
220-
221-
if scope is not None:
222-
# Verify the caller agent details contain the expected IP
223-
self.assertEqual(self.caller_agent_details.agent_client_ip, "192.168.1.100")
224-
scope.dispose()
225-
226-
# Verify the IP is set as a span attribute
227-
finished_spans = span_exporter.get_finished_spans()
228-
if finished_spans:
229-
span = finished_spans[-1]
230-
span_attributes = getattr(span, "attributes", {}) or {}
231-
232-
# Verify the caller agent client IP is set as a span attribute
233-
if GEN_AI_CALLER_AGENT_USER_CLIENT_IP in span_attributes:
234-
self.assertEqual(
235-
span_attributes[GEN_AI_CALLER_AGENT_USER_CLIENT_IP], "192.168.1.100"
236-
)
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-
271202

272203
if __name__ == "__main__":
273204
# Run pytest only on the current file

0 commit comments

Comments
 (0)