fix: loosen StatsigEventSerializer validation and downgrade DetectorGroup.DoesNotExist noise#119482
Closed
billyvg wants to merge 1 commit into
Closed
fix: loosen StatsigEventSerializer validation and downgrade DetectorGroup.DoesNotExist noise#119482billyvg wants to merge 1 commit into
billyvg wants to merge 1 commit into
Conversation
…roup.DoesNotExist log level Two Sentry alert fixes: 1. SENTRY-5J6Z: StatsigEventSerializer rejects Statsig server-SDK payloads where user.customIDs, user.custom, and user.statsigEnvironment are nested objects rather than flat strings. Remove child=CharField() constraint on the user DictField and allow blank values on value/timeUUID fields that are not used by the handler logic anyway. 2. SENTRY-5R4N: _get_detector_for_group uses logger.exception() for a DetectorGroup.DoesNotExist that is an expected condition for legacy groups that predate the workflow engine. This generates ~27k noisy Sentry events affecting ~4800 users. Downgrade to logger.warning() since the fallback lookup path already handles this case correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0152iRwgLj2pwmC8VKUsxoKL
Contributor
|
🚨 Warning: This pull request contains Frontend and Backend changes! It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently. Have questions? Please ask in the |
41502ce to
2a16f59
Compare
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.
Summary
Fixes two production Sentry alerts surfaced by automated monitoring.
Fix 1 — SENTRY-5J6Z: Statsig webhook
DeserializationError(medium severity, ~17k events/day, 4826 users impacted)Root cause:
StatsigEventSerializer.userwas declared asDictField(child=CharField()), which requires every value in the dict to be a plain string. Statsig server-SDK payloads (e.g.statsig-server-core-node) send nested objects foruser.customIDs,user.custom, anduser.statsigEnvironment. This caused every such webhook to fail with aDeserializationErrorbefore flag audit logs could be written.Two additional fields also caused spurious failures:
value— Statsig sends an empty string for exposure events;CharFieldwithoutallow_blank=Truerejects it.timeUUID— Sent in formats that don't satisfy DRF'sUUIDField; changed toCharFieldsince this field is unused by the handler.Fix: Remove the
child=CharField()constraint fromuser, addallow_blank=Truetovalue, and relaxtimeUUIDtoCharField. None of these fields are used downstream in the audit-log construction path.Files changed:
src/sentry/flags/providers.py— relaxStatsigEventSerializerfield constraintstests/sentry/flags/providers/test_statsig.py— add regression test with nested user fieldsFix 2 — SENTRY-5R4N:
DetectorGroup.DoesNotExistlogged as exception (medium severity, ~27k events, 4800 users triggering noisy errors)Root cause:
_get_detector_for_groupinsentry/workflow_engine/processors/detector.pyusedlogger.exception()inside theDetectorGroup.DoesNotExisthandler.logger.exception()attaches the exception traceback and triggers a Sentry capture, but thisDoesNotExistis an expected condition for legacy groups that were created before the workflow engine'sDetectorGrouptable existed. The function already falls through correctly to two further lookup strategies; the exception capture was pure instrumentation noise.Fix: Downgrade
logger.exception()→logger.warning()so the condition is noted in logs without generating a Sentry event.Files changed:
src/sentry/workflow_engine/processors/detector.py— downgrade log levelEvidence / Reasoning
user.customIDs: {"organizationId": "org_..."}(a dict) being rejected bychild=CharField().logger.exceptiondirectly after catchingDetectorGroup.DoesNotExist; the surrounding code falls back to other lookups successfully.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