fix: handle missing span description and non-dict MSTeams error JSON#119470
Draft
billyvg wants to merge 2 commits into
Draft
fix: handle missing span description and non-dict MSTeams error JSON#119470billyvg wants to merge 2 commits into
billyvg wants to merge 2 commits into
Conversation
…tector Spans from the process-segments consumer can arrive without a "description" field. The detector was doing a direct dict lookup which raised KeyError and swallowed the detection entirely (caught by the outer try/except that logs "Failed to detect performance problems"). Use .get() with an empty-string default so detection continues even for spans that omit the field. Fixes SENTRY-5QVD Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KTwqnL4x74X2LSUoHg32sd
When MSTeams auth fails (e.g. expired OAuth credentials), the error response body can be a JSON string rather than a dict. Calling .get() on a str raises AttributeError, producing a secondary noisy exception that obscures the real IntegrationError. Use isinstance(error.json, dict) so non-dict payloads fall through to the existing IntegrationError branch cleanly. Fixes SENTRY-5PKQ Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KTwqnL4x74X2LSUoHg32sd
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.
Fixes two bugs surfaced by Sentry alert monitoring.
Fix 1: KeyError 'description' in N+1 DB span detector (SENTRY-5QVD — HIGH actionability)
Issue: SENTRY-5QVD — 291K+ occurrences since 2026-06-25.
Root cause:
mn_plus_one_db_span_detector.py:258did a direct dict lookupdb_span["description"]. Spans arriving from theprocess-segmentsconsumer can omit the"description"field, causing aKeyError. This exception is caught by the outertry/exceptindetect_performance_problems()which logs"Failed to detect performance problems"and suppresses detection entirely for affected spans.Evidence from event stacktrace:
Local variable
common_parent_spanshowed"downsampled_retention_days":"30"and no"description"key.Fix: Use
db_span.get("description", "")— matches the pattern used inevidence_datathroughout the same function.Fix 2: AttributeError on non-dict MSTeams error JSON (SENTRY-5PKQ — MEDIUM)
Issue: SENTRY-5PKQ — 2573 occurrences, 240 users affected since 2026-05-11.
Root cause:
msteams/metrics.py:34callederror.json.get(...)without verifyingerror.jsonis a dict. When Microsoft's OAuth endpoint returns a 401 with certain error payloads (e.g.AADSTS7000222— expired client secret),error.jsonis a string, not a dict..get()on a string raisesAttributeError, which bubbles up as a noisy secondary exception obscuring the realApiUnauthorizederror.Evidence from event stacktrace:
The underlying cause was an expired Azure app client secret (the primary operator issue), but the secondary
AttributeErrorwas generating an additional 2500+ Sentry events.Fix: Use
isinstance(error.json, dict)instead of a truthiness check, so non-dict payloads fall through to the existingIntegrationErrorbranch cleanly.Session
Generated by Claude Code: https://claude.ai/code/session_01KTwqnL4x74X2LSUoHg32sd
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