Skip to content

Commit 342140e

Browse files
NiteshDhanpalclaude
andcommitted
fix(tracing): align _correlate_business to opt-out semantics (default on)
Match sgp_obs env_off: disable ONLY on an explicit {0,false,no,off}; unset, empty, or an unrecognized value stays ON. Adds "off" to the token set and stops treating an unrecognized value as True-by-coincidence — now it's True by rule (opt-out), so a typo can't silently drop correlation. Test covers off-tokens + empty/typo staying on. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 57c90d7 commit 342140e

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/agentex/lib/core/tracing/trace.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,14 @@ def _obs_mode() -> ObsMode:
5050

5151

5252
def _correlate_business() -> bool:
53-
"""``SGP_OBS_CORRELATE_BUSINESS`` — default True. Read from the env directly
53+
"""``SGP_OBS_CORRELATE_BUSINESS`` — OPT-OUT: defaults True, disables ONLY on an
54+
explicit {0, false, no, off}. Unset, empty, or an unrecognized value (a typo)
55+
stays ON, so correlation is never silently dropped. Read from the env directly
5456
(mirroring ``_obs_mode``) rather than sgp_obs.TracingConfig, so we don't depend
55-
on a specific config-field surface. When false, the Correlator opens the obs
56-
span but writes NO business<->obs correlation in either direction."""
57-
return (os.getenv("SGP_OBS_CORRELATE_BUSINESS") or "true").strip().lower() not in ("false", "0", "no")
57+
on a specific config-field surface; the off-token set matches sgp_obs ``env_off``.
58+
When false, the Correlator opens the obs span but writes NO business<->obs
59+
correlation in either direction."""
60+
return (os.getenv("SGP_OBS_CORRELATE_BUSINESS") or "").strip().lower() not in ("0", "false", "no", "off")
5861

5962

6063
def _build_correlator() -> Correlator:

tests/test_correlate_business_passthrough.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313

1414
def test_correlate_business_env_parsing(monkeypatch):
1515
monkeypatch.delenv("SGP_OBS_CORRELATE_BUSINESS", raising=False)
16-
assert _correlate_business() is True # default on
17-
for falsey in ("false", "0", "no", "FALSE", " no "):
16+
assert _correlate_business() is True # unset -> on
17+
# explicit recognized off-tokens -> off (matches sgp_obs env_off)
18+
for falsey in ("false", "0", "no", "off", "FALSE", "Off", " no "):
1819
monkeypatch.setenv("SGP_OBS_CORRELATE_BUSINESS", falsey)
19-
assert _correlate_business() is False
20-
for truthy in ("true", "1", "yes", "", "anything"):
20+
assert _correlate_business() is False, falsey
21+
# on-tokens AND empty / unrecognized (a typo) -> stays ON, never silently off
22+
for truthy in ("true", "1", "yes", "on", "", " ", "ture", "garbage"):
2123
monkeypatch.setenv("SGP_OBS_CORRELATE_BUSINESS", truthy)
22-
assert _correlate_business() is True
24+
assert _correlate_business() is True, repr(truthy)
2325

2426

2527
def test_build_correlator_never_crashes():

0 commit comments

Comments
 (0)