-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(errors): Store error metadata for sorting
- Loading branch information
1 parent
34a4f6b
commit 8c18e2e
Showing
11 changed files
with
151 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from sentry_sdk import capture_exception | ||
from posthog.models.error_tracking.error_tracking import ErrorTrackingIssue | ||
from posthog.redis import get_client | ||
from django.db.models import F | ||
|
||
|
||
def populate_error_tracking_issue_metrics(): | ||
Check failure on line 7 in posthog/tasks/error_tracking.py GitHub Actions / Python code quality checks
|
||
client = get_client() | ||
keys = client.scan_iter(match="issue_metadata:*", count=20) | ||
for key in keys: | ||
# check key is valid | ||
parts = key.split(":") | ||
if len(parts) != 3: | ||
continue | ||
|
||
team_id = parts[1] | ||
issue_id = parts[2] | ||
|
||
# Fetch data associated with the key | ||
data = client.hgetall(key) | ||
last_seen = data.get(b"last_seen") | ||
occurrences = data.get(b"occurrences") | ||
|
||
try: | ||
# update the issue and reset redis key | ||
ErrorTrackingIssue.objects.filter(team=team_id, id=issue_id).update( | ||
last_seen=last_seen, occurrences=F("occurrences") + occurrences | ||
) | ||
# :TRICKY: Resetting the redis key here is prone to race conditions, | ||
# but given we sync later and the data here is not critical, just an estimate for sorting, | ||
# I'm skipping locking and letting this be. | ||
client.delete(key) | ||
except Exception as error: | ||
capture_exception(error) | ||
continue |
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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