Skip to content

fix(perf-detection): handle missing description in MN+1 DB detector; downgrade noisy DetectorGroup log#119449

Draft
billyvg wants to merge 1 commit into
masterfrom
claude/serene-cannon-kg1ry3
Draft

fix(perf-detection): handle missing description in MN+1 DB detector; downgrade noisy DetectorGroup log#119449
billyvg wants to merge 1 commit into
masterfrom
claude/serene-cannon-kg1ry3

Conversation

@billyvg

@billyvg billyvg commented Jul 11, 2026

Copy link
Copy Markdown
Member

Fixes two Sentry-reported production errors found during automated alert triage.


Fix 1 — KeyError: 'description' in MN+1 DB span detector (SENTRY-5QVD, high severity)

Issue: SENTRY-5QVD — 210K+ events, ongoing since 2026-06-25.

Root cause: ContinuingMNPlusOne._maybe_performance_problem accessed db_span["description"] directly in two places. The segment consumer (spans.consumers.process_segments) processes spans from the process-segments Kafka consumer, and some spans in this path do not include a description key (e.g. downsampled spans, spans with stripped fields). This caused KeyError: 'description', which was caught by the outer detect_performance_problems handler and logged as "Failed to detect performance problems" — silently dropping all N+1 detection for affected segments.

Fix: Use db_span.get("description", "") in both callsites (desc= argument and get_notification_attachment_body call) in mn_plus_one_db_span_detector.py:258,283.


Fix 2 — DetectorGroup.DoesNotExist logged as exception (SENTRY-5R4N, medium severity)

Issue: SENTRY-5R4N — 24K+ events, 4K+ users impacted, ongoing since 2026-07-01.

Root cause: _get_detector_for_group in workflow_engine/processors/detector.py used logger.exception(...) inside the except DetectorGroup.DoesNotExist handler. logger.exception logs at ERROR level and includes the full traceback. The Seer root cause analysis confirms this is an expected condition for legacy groups that predate DetectorGroup associations — the code already handles the missing record gracefully by falling through to look up a detector by (project, type) or the issue stream detector.

Fix: Change logger.exceptionlogger.warning so the expected fallback path doesn't generate noisy ERROR-level events with full tracebacks.


Evidence

  • SENTRY-5QVD: 210,514 events, Seer actionability: high, Seer recommendation: "Use .get('description', '') to safely access the db span description."
  • SENTRY-5R4N: 24,547 events / 4,362 users affected, Seer root cause: "Legacy groups without DetectorGroup associations trigger a logged exception when resolved."

Session

https://claude.ai/code/session_01AY6kMQotceHm8vtMtSkdBc

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.


Generated by Claude Code

… detector

Spans processed by the segment consumer may not always include a
`description` key. Accessing `db_span["description"]` raised KeyError
causing the entire performance problem detection to fail (SENTRY-5QVD,
210K+ events). Changed both callsites to use `.get("description", "")`.

Also downgrade `logger.exception` to `logger.warning` for
`DetectorGroup.DoesNotExist` in `_get_detector_for_group` — this is an
expected condition for legacy groups that predate DetectorGroup
associations, and the code already handles it gracefully by falling
through to alternative detector lookups (SENTRY-5R4N, 24K events, 4K
users). Using `logger.exception` was generating noisy error-level
log events with full tracebacks for a known benign case.

Fixes SENTRY-5QVD
Ref SENTRY-5R4N
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 11, 2026
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.

2 participants