dstandish commented on code in PR #69633:
URL: https://github.com/apache/airflow/pull/69633#discussion_r3555282523


##########
shared/observability/tests/observability/test_traces.py:
##########
@@ -250,6 +267,62 @@ def test_force_sampled_preserves_detail_level(self, 
with_sampler):
         assert _carrier_is_sampled(carrier) is True
 
 
+class TestNewDagrunTraceCarrierParentContext:
+    """parent_context embeds the run in an external trace instead of a fresh 
root."""
+
+    @pytest.fixture
+    def with_sampler(self, monkeypatch):
+        def _install(sampler):
+            provider = TracerProvider(sampler=sampler)
+            monkeypatch.setattr(
+                
"airflow_shared.observability.traces.trace.get_tracer_provider",
+                lambda: provider,
+            )
+
+        return _install
+
+    def test_embeds_in_parent_trace_with_own_span(self):
+        parent = _parent_context(trace_id=0xABC123, span_id=0xDEF456)
+        span_ctx = 
_carrier_span_context(new_dagrun_trace_carrier(parent_context=parent))
+        assert span_ctx.trace_id == 0xABC123  # rides the external trace
+        assert span_ctx.span_id != 0xDEF456  # but is its own child span
+
+    def test_without_parent_context_mints_fresh_root(self):
+        parent = _parent_context(trace_id=0xABC123)
+        embedded = 
_carrier_span_context(new_dagrun_trace_carrier(parent_context=parent))
+        root = _carrier_span_context(new_dagrun_trace_carrier())
+        assert root.trace_id != embedded.trace_id
+
+    def test_empty_context_treated_as_no_parent(self):
+        # An empty Context carries an invalid span -> root trace, not an embed.
+        span_ctx = 
_carrier_span_context(new_dagrun_trace_carrier(parent_context=context.Context()))
+        assert span_ctx.is_valid
+
+    def test_parent_based_sampler_inherits_sampled_parent(self, with_sampler):

Review Comment:
   Done — consolidated into a single parametrized 
`test_parent_based_sampler_decision` in 202635526a.



##########
shared/observability/tests/observability/test_traces.py:
##########
@@ -250,6 +267,62 @@ def test_force_sampled_preserves_detail_level(self, 
with_sampler):
         assert _carrier_is_sampled(carrier) is True
 
 
+class TestNewDagrunTraceCarrierParentContext:
+    """parent_context embeds the run in an external trace instead of a fresh 
root."""
+
+    @pytest.fixture
+    def with_sampler(self, monkeypatch):
+        def _install(sampler):
+            provider = TracerProvider(sampler=sampler)
+            monkeypatch.setattr(
+                
"airflow_shared.observability.traces.trace.get_tracer_provider",
+                lambda: provider,
+            )
+
+        return _install
+
+    def test_embeds_in_parent_trace_with_own_span(self):
+        parent = _parent_context(trace_id=0xABC123, span_id=0xDEF456)
+        span_ctx = 
_carrier_span_context(new_dagrun_trace_carrier(parent_context=parent))
+        assert span_ctx.trace_id == 0xABC123  # rides the external trace
+        assert span_ctx.span_id != 0xDEF456  # but is its own child span
+
+    def test_without_parent_context_mints_fresh_root(self):
+        parent = _parent_context(trace_id=0xABC123)
+        embedded = 
_carrier_span_context(new_dagrun_trace_carrier(parent_context=parent))
+        root = _carrier_span_context(new_dagrun_trace_carrier())
+        assert root.trace_id != embedded.trace_id
+
+    def test_empty_context_treated_as_no_parent(self):
+        # An empty Context carries an invalid span -> root trace, not an embed.
+        span_ctx = 
_carrier_span_context(new_dagrun_trace_carrier(parent_context=context.Context()))
+        assert span_ctx.is_valid
+
+    def test_parent_based_sampler_inherits_sampled_parent(self, with_sampler):

Review Comment:
   Done — consolidated into a single parametrized 
`test_parent_based_sampler_decision` in 202635526a.
   
   ---
   Drafted-by: Claude Code (Sonnet 5) (no human review before posting)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to