|
4 | 4 | import os |
5 | 5 | import unittest |
6 | 6 |
|
7 | | -from microsoft_agents_a365.observability.core import config as telemetry_config |
8 | 7 | from microsoft_agents_a365.observability.core.constants import ( |
9 | 8 | CORRELATION_ID_KEY, |
10 | 9 | GEN_AI_AGENT_AUID_KEY, |
@@ -104,52 +103,30 @@ def test_all_baggage_keys(self): |
104 | 103 |
|
105 | 104 | def test_baggage_propagates_to_child_spans(self): |
106 | 105 | """Test that baggage values are copied as attributes onto parent and child spans via SpanProcessor.""" |
107 | | - # Configure global telemetry; this will add the SpanProcessor automatically. |
108 | | - # Use a temporary tracer provider with our in-memory exporter for assertion. |
109 | 106 | exporter = InMemorySpanExporter() |
110 | 107 | provider = TracerProvider() |
111 | | - provider.add_span_processor(SimpleSpanProcessor(exporter)) |
112 | | - trace.set_tracer_provider(provider) |
113 | | - # Invoke SDK configure to attach Agent365 span processor (agent processor) |
114 | | - telemetry_config.configure( |
115 | | - service_name="baggage-test-service", |
116 | | - service_namespace="baggage.test", |
117 | | - logger_name="Agent365-test", |
| 108 | + processor = SimpleSpanProcessor(exporter) |
| 109 | + provider.add_span_processor(processor) |
| 110 | + |
| 111 | + # Also add the Agent365 span processor directly |
| 112 | + from microsoft_agents_a365.observability.core.trace_processor.span_processor import ( |
| 113 | + SpanProcessor as Agent365SpanProcessor, |
118 | 114 | ) |
119 | | - tracer = telemetry_config.get_tracer(__name__) |
| 115 | + |
| 116 | + agent365_processor = Agent365SpanProcessor() |
| 117 | + provider.add_span_processor(agent365_processor) |
| 118 | + |
| 119 | + tracer = provider.get_tracer(__name__) |
120 | 120 |
|
121 | 121 | tenant = "tenant-propagation-test" |
122 | 122 | agent = "agent-propagation-test" |
123 | 123 |
|
124 | 124 | # Create baggage before starting spans so processor can copy it |
125 | 125 | with BaggageBuilder().tenant_id(tenant).agent_id(agent).build(): |
126 | | - with tracer.start_as_current_span("parent_span") as parent_span: |
127 | | - # Attributes should now include baggage-derived keys |
128 | | - parent_attrs = getattr(parent_span, "attributes", {}) |
129 | | - self.assertEqual( |
130 | | - parent_attrs.get(TENANT_ID_KEY), |
131 | | - tenant, |
132 | | - "Parent span missing tenant attribute from baggage", |
133 | | - ) |
134 | | - self.assertEqual( |
135 | | - parent_attrs.get(GEN_AI_AGENT_ID_KEY), |
136 | | - agent, |
137 | | - "Parent span missing agent attribute from baggage", |
138 | | - ) |
139 | | - |
| 126 | + with tracer.start_as_current_span("parent_span"): |
140 | 127 | # Nested child span should also receive baggage-derived attributes at start |
141 | | - with tracer.start_as_current_span("child_span") as child_span: |
142 | | - child_attrs = getattr(child_span, "attributes", {}) |
143 | | - self.assertEqual( |
144 | | - child_attrs.get(TENANT_ID_KEY), |
145 | | - tenant, |
146 | | - "Child span missing tenant attribute from baggage", |
147 | | - ) |
148 | | - self.assertEqual( |
149 | | - child_attrs.get(GEN_AI_AGENT_ID_KEY), |
150 | | - agent, |
151 | | - "Child span missing agent attribute from baggage", |
152 | | - ) |
| 128 | + with tracer.start_as_current_span("child_span"): |
| 129 | + pass # Just create the spans, attributes are set by the processor |
153 | 130 |
|
154 | 131 | # Ensure spans exported contain these attributes (export happens on end) |
155 | 132 | finished_spans = exporter.get_finished_spans() |
|
0 commit comments