Skip to content

Commit b190a8e

Browse files
LEANDERANTONYclaude
andcommitted
fix(observability): pytest guard on _init_posthog
The jobagent _init_posthog was missing the pytest no-op guard that HelpmateAI's _init_posthog has. Result: every test exercising an instrumented route (test_feedback in particular) shipped events into the production PostHog project with distinct_id="user-test" - visible on the assistant_turn dashboard as ~50% thumbs-down (paired up/down events ~80 ms apart, clearly fixtures and not real users). Fix: mirror the HelpmateAI guard verbatim. Zero production behavior change - only affects what happens when PYTEST_CURRENT_TEST is set or pytest is in sys.modules. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8dce13e commit b190a8e

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

backend/observability.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,18 @@ def _init_posthog(settings: BackendSettings) -> None:
219219
logger.debug("POSTHOG_API_KEY not configured; skipping PostHog init.")
220220
_posthog_client = None
221221
return
222+
if _running_under_pytest():
223+
# The local .env carries a real POSTHOG_API_KEY for dev work;
224+
# without this guard every test that exercises an instrumented
225+
# route (feedback, workspace, resume-builder, a quota reject)
226+
# ships events into the production analytics project. Discovered
227+
# when the assistant_turn dashboard showed ~50% thumbs-down
228+
# purely from test_feedback's user-test fixture firing paired
229+
# up/down events ~80 ms apart. Mirrors the _init_sentry pytest
230+
# guard above + HelpmateAI's _init_posthog guard.
231+
logger.debug("Pytest detected; skipping PostHog init.")
232+
_posthog_client = None
233+
return
222234
try:
223235
from posthog import Posthog
224236
except Exception as exc: # pragma: no cover — defensive

0 commit comments

Comments
 (0)