Skip to content

Commit 2a9576b

Browse files
NiteshDhanpalclaude
andcommitted
test(tracing): update obs_span invalid-context test to the None-fallback contract
The comment-#2 fix changed open_obs_span so an invalid wrapper context returns None (caller falls back to ambient obs_correlation()) instead of a handle with empty correlation. The pre-existing tests/lib/core/tracing/test_obs_span.py still asserted the old contract and failed CI. Update it to assert None + that the attached context is detached and the no-op span ended (no leak). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 9018a61 commit 2a9576b

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

tests/lib/core/tracing/test_obs_span.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,29 @@ def test_lgtm_opens_named_span_and_reads_its_ids(self, monkeypatch):
150150
"agentex.business_trace_id": "btrace-1",
151151
}
152152

153-
def test_invalid_span_context_yields_empty_correlation(self, monkeypatch):
153+
def test_invalid_span_context_returns_none_for_fallback(self, monkeypatch):
154+
"""Invalid wrapper context (proxy NonRecordingSpan / no TracerProvider):
155+
open_obs_span returns None so the caller falls back to the ambient
156+
obs_correlation() instead of taking an empty-correlation handle (which
157+
would suppress the fallback and strip obs_* ids). It also detaches the
158+
context it attached and ends the no-op span, so nothing leaks."""
154159
monkeypatch.setenv("SGP_OBS_MODE", "lgtm")
155-
_install_fake_otel(monkeypatch)
160+
record = _install_fake_otel(monkeypatch)
161+
162+
made: dict = {}
156163

157164
def start_span(name):
158165
span = _FakeOtelSpan(name, 0, 0)
159166
span._ctx = _FakeSpanContext(0, 0, is_valid=False)
167+
made["span"] = span
160168
return span
161169

162170
sys.modules["opentelemetry"].trace.get_tracer = lambda _n: types.SimpleNamespace(start_span=start_span)
163171
handle = obs_span.open_obs_span("step")
164-
assert handle is not None
165-
assert handle.correlation == {}
172+
assert handle is None
173+
# cleaned up: the attached context was detached and the no-op span ended
174+
assert len(record["detached"]) == 1
175+
assert made["span"].ended is True
166176

167177
def test_close_detaches_and_ends(self, monkeypatch):
168178
monkeypatch.setenv("SGP_OBS_MODE", "lgtm")

0 commit comments

Comments
 (0)