Skip to content

feat(events): Add a log for query errors#116696

Merged
wmak merged 3 commits into
masterfrom
wmak/feat/add-log-for-query-errors
Jun 2, 2026
Merged

feat(events): Add a log for query errors#116696
wmak merged 3 commits into
masterfrom
wmak/feat/add-log-for-query-errors

Conversation

@wmak

@wmak wmak commented Jun 2, 2026

Copy link
Copy Markdown
Member
  • As ai usage increases we're getting more query errors, log these so we can get a better idea of what kind of query errors are happening

- As ai usage increases we're getting more query errors, log these so we
  can get a better idea of what kind of query errors are happening
@wmak wmak requested a review from a team as a code owner June 2, 2026 16:23
@wmak wmak enabled auto-merge (squash) June 2, 2026 16:24
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 2, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 800521c. Configure here.

Comment thread src/sentry/api/utils.py
Comment thread src/sentry/api/utils.py
Comment thread src/sentry/api/utils.py Outdated
sentry_sdk.set_tag("query.error_reason", message)
message = "Project in query does not exist or not selected"
sentry_sdk.set_tag("query.error_reason", message)
logger.info(message)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User-supplied search query values logged via logger.info

The InvalidSearchQuery error message—built from str(error)—frequently embeds the raw user-typed query value (e.g. user.email:alice@corp.com"user.email: Invalid date: alice@corp.com. ..."). Logging this with logger.info(message) sends that value to a durable application-log sink. Replace with a fixed categorical string or log only type(error).__name__ and omit the user-supplied value.

Evidence
  • message = str(error) (line 371) captures the full InvalidSearchQuery string verbatim.
  • In event_search.py (_handle_basic_filter), errors are raised as f"{search_key.name}: Invalid date: {search_value.raw_value}. ..."raw_value is the literal text from the user's search bar.
  • A user searching user.email:victim@company.com with an invalid format would produce an error whose string contains the email address.
  • sentry_sdk.set_tag("query.error_reason", message) already existed before this PR; logger.info(message) on line 377 is the only new durable sink introduced by this diff.
  • Application logs are typically retained and may be forwarded to third-party log aggregators, making this a broader exposure than the existing Sentry tag.

Identified by Warden wrdn-pii · Z5F-6NG

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix attempt detected (commit 5d74bfd)

The logger.info call was modified to use a static message with the user-derived value moved to extra, but extra={'query.error_reason': message} still embeds the raw user-supplied query string into the durable log record, so the PII exposure persists.

The original issue appears unresolved. Please review and try again.

Evaluated by Warden

Comment thread src/sentry/api/utils.py
message = "Project in query does not exist or not selected"
sentry_sdk.set_tag("query.error_reason", message)
logger.info("A query error was handled", extra={"query.error_reason": message})
raise ParseError(detail=original_error)
@wmak wmak merged commit 1e76b08 into master Jun 2, 2026
84 checks passed
@wmak wmak deleted the wmak/feat/add-log-for-query-errors branch June 2, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants