Skip to content

Instantly share code, notes, and snippets.

@anapaulagomes
Created December 30, 2020 13:50
Show Gist options
  • Save anapaulagomes/17d5152573b4e4d5b4c25823b5e65455 to your computer and use it in GitHub Desktop.
Save anapaulagomes/17d5152573b4e4d5b4c25823b5e65455 to your computer and use it in GitHub Desktop.
Retrieve errors from Sentry API
import json
import requests
def retrieve_errors(issue_id):
issue_id = "" # FIXME
endpoint = f"https://sentry.io/api/0/issues/{issue_id}/events/?full=True"
token = "" # FIXME
headers = {"Authorization": f"Bearer {token}"}
return requests.get(endpoint, headers=headers)
events_from_sentry = json.load(open("sentry-errors-1.json"))
errors = {}
all_params = []
for event in events_from_sentry:
task_id = None
from_prod = False
for tag in event["tags"]:
if tag["key"] == "environment" and tag["value"] == "Prod":
from_prod = True
if tag["key"] == "dramatiq_message_id":
task_id = tag["value"]
if task_id and from_prod:
for entry in event["entries"]:
if entry["data"].get("values"):
for value in entry["data"].get("values"):
if value.get("stacktrace") and value["stacktrace"]["frames"]:
for frame in value["stacktrace"]["frames"]:
if frame["vars"].get("params"):
errors[task_id] = frame["vars"].get("params")
if frame["vars"].get("params") not in all_params:
all_params.append(frame["vars"].get("params"))
for task_id, params in errors.items():
print("--------------------------")
print(task_id)
print(params)
print(len(errors), len(all_params))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment