fix(query): stop capturing expected user query errors into error tracking#67275
Draft
posthog[bot] wants to merge 1 commit into
Draft
fix(query): stop capturing expected user query errors into error tracking#67275posthog[bot] wants to merge 1 commit into
posthog[bot] wants to merge 1 commit into
Conversation
…king The query runner's `posthoganalytics.new_context()` boundary auto-captured every exception raised during a query, including ones the runner already classifies as SLO-success (user errors, cancellations, rate limits). A direct Postgres / data-warehouse query exceeding statement_timeout surfaces as an ExposedHogQLError, so it was creating error-tracking issues even though the user gets a clean error message and we treat it as expected input. Disable auto-capture on the context and capture manually only for genuine platform failures (SLO-failure outcomes), preserving the same context tags. Extends the existing SLO-boundary test to assert capture_exception is invoked for failures and suppressed for expected user-input errors. Generated-By: PostHog Code Task-Id: f56d2296-ef23-4f54-935f-794a6bce8138
Contributor
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, please remove the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Query error tracking was getting polluted by expected user-input errors. When a HogQL query runs against a direct Postgres / data-warehouse source and exceeds the Postgres
statement_timeout, Postgres raisesQueryCanceled; the adapter re-raises it as anExposedHogQLError, which bubbles up throughQueryRunner.run. That method wraps execution in aposthoganalytics.new_context()block, which auto-captures any exception raised inside it into error tracking.The catch: the runner already classifies
ExposedHogQLErroras aUSER_ERRORand counts it as an SLO success. So we were capturing something we've explicitly decided is normal user input, not a platform failure. The person running the slow query gets a clean error message back, but we still opened an error-tracking issue for it. Low volume today, but it fires every time a warehouse query is too slow, so it's ongoing triage noise and a source of false alarms.Changes
Disable auto-capture on the
new_context()boundary inQueryRunner.runand capture manually instead, gated on the SLO outcome the runner already computes:cache_key,query_type,insight_id, etc.) are still attached as before.This is the general form of the fix the report suggested: the runner already knows which errors are expected, so suppress those at the capture boundary while letting genuine platform errors surface unchanged.
How did you test this code?
I could not run the suite in this sandbox (test dependencies aren't installed here), so I did not execute the tests. I verified both changed files byte-compile and traced the control flow to confirm the outer boundary is the only exception-capture point on this path (
_execute_and_cache_blocking's innerexceptonly increments metrics and re-raises).I extended the existing parameterized test
test_run_classifies_slo_error_at_except_boundaryrather than adding a new one — it already exercises exactly the SUCCESS/FAILURE outcomes I care about. The new assertion catches the regression that expected user-input errors would again be captured into error tracking if auto-capture were re-enabled or the manual guard removed:capture_exceptionmust not be called for SLO-success outcomes and must be called once for failures.Automatic notifications
Docs update
No docs changes needed.
🤖 Agent context
Autonomy: Fully autonomous
Authored by Claude (via PostHog Code) from an inbox report about a new error-tracking issue that turned out to be an expected direct-Postgres warehouse query timeout. Invoked the
/writing-testsskill before touching tests, which steered me to extend the existing SLO-boundary parameterized test rather than write a redundant new one.Considered two options from the report: narrowly special-casing the wrapped
QueryCanceledstatement-timeout inpostgres_adapter.py, versus suppressing at thenew_contextcapture boundary. Chose the boundary fix because the runner already classifies these as SLO-success, so keying capture off that existing classification is more principled and also covers other expected user-input errors (cancellations, rate limits) that were being captured for the same reason.posthoganalytics.new_contexthas no per-exception filter, so the mechanism is: disable its auto-capture and callposthoganalytics.capture_exceptionmanually for failures only.Created with PostHog Code from an inbox report.