Skip to content

Commit 081737a

Browse files
CopilotnikhilNava
andcommitted
Add operation_source method to BaggageBuilder using SERVICE_NAME_KEY
Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
1 parent 826e2ae commit 081737a

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/constants.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@
9494
CHANNEL_NAME_KEY = "microsoft.channel.name"
9595
CHANNEL_LINK_KEY = "microsoft.channel.link"
9696

97+
# Deprecated channel dimension keys - use CHANNEL_NAME_KEY and CHANNEL_LINK_KEY instead
98+
GEN_AI_EXECUTION_SOURCE_NAME_KEY = "microsoft.channel.name"
99+
GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY = "microsoft.channel.link"
100+
101+
# Event content key
102+
GEN_AI_EVENT_CONTENT = "gen_ai.event.content"
103+
97104
# Custom parent id and parent name key
98105
CUSTOM_PARENT_SPAN_ID_KEY = "custom.parent.span.id"
99106
CUSTOM_SPAN_NAME_KEY = "custom.span.name"

libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/middleware/baggage_builder.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
GEN_AI_CALLER_UPN_KEY,
2424
GEN_AI_CONVERSATION_ID_KEY,
2525
GEN_AI_CONVERSATION_ITEM_LINK_KEY,
26+
SERVICE_NAME_KEY,
2627
SESSION_DESCRIPTION_KEY,
2728
SESSION_ID_KEY,
2829
TENANT_ID_KEY,
@@ -55,6 +56,20 @@ def __init__(self):
5556
"""Initialize the baggage builder."""
5657
self._pairs: dict[str, str] = {}
5758

59+
def operation_source(self, value: str | None) -> "BaggageBuilder":
60+
"""Set the operation source baggage value.
61+
62+
This captures the name of the service using the SDK.
63+
64+
Args:
65+
value: The service name (e.g., "my-agent-service", "weather-bot")
66+
67+
Returns:
68+
Self for method chaining
69+
"""
70+
self._set(SERVICE_NAME_KEY, value)
71+
return self
72+
5873
def tenant_id(self, value: str | None) -> "BaggageBuilder":
5974
"""Set the tenant ID baggage value.
6075

tests/observability/core/test_baggage_builder.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
GEN_AI_AGENT_UPN_KEY,
1414
GEN_AI_CALLER_CLIENT_IP_KEY,
1515
GEN_AI_CALLER_ID_KEY,
16+
SERVICE_NAME_KEY,
1617
SESSION_DESCRIPTION_KEY,
1718
SESSION_ID_KEY,
1819
TENANT_ID_KEY,
@@ -319,6 +320,37 @@ def test_caller_client_ip_method(self):
319320
# Should be None due to proper exception handling
320321
self.assertIsNone(current_baggage.get(GEN_AI_CALLER_CLIENT_IP_KEY))
321322

323+
def test_operation_source_method(self):
324+
"""Test operation_source method sets service name baggage using string values."""
325+
# Should exist and be callable
326+
self.assertTrue(hasattr(self.builder, "operation_source"))
327+
self.assertTrue(callable(self.builder.operation_source))
328+
329+
# Test with custom service name
330+
with BaggageBuilder().operation_source("my-agent-service").build():
331+
current_baggage = baggage.get_all()
332+
self.assertEqual(current_baggage.get(SERVICE_NAME_KEY), "my-agent-service")
333+
334+
# Test with another service name
335+
with BaggageBuilder().operation_source("weather-bot").build():
336+
current_baggage = baggage.get_all()
337+
self.assertEqual(current_baggage.get(SERVICE_NAME_KEY), "weather-bot")
338+
339+
# Test with SDK as string
340+
with BaggageBuilder().operation_source("SDK").build():
341+
current_baggage = baggage.get_all()
342+
self.assertEqual(current_baggage.get(SERVICE_NAME_KEY), "SDK")
343+
344+
# Test with None value (should not set baggage)
345+
with BaggageBuilder().operation_source(None).build():
346+
current_baggage = baggage.get_all()
347+
self.assertIsNone(current_baggage.get(SERVICE_NAME_KEY))
348+
349+
# Test with whitespace-only value (should not set baggage)
350+
with BaggageBuilder().operation_source(" ").build():
351+
current_baggage = baggage.get_all()
352+
self.assertIsNone(current_baggage.get(SERVICE_NAME_KEY))
353+
322354

323355
if __name__ == "__main__":
324356
unittest.main()

0 commit comments

Comments
 (0)