Skip to content

Instantly share code, notes, and snippets.

@vladox
Forked from bubenkoff/download_sentry_data.py
Last active April 13, 2024 01:00
Show Gist options
  • Save vladox/f401db999c5efdf2f25d38683fde2813 to your computer and use it in GitHub Desktop.
Save vladox/f401db999c5efdf2f25d38683fde2813 to your computer and use it in GitHub Desktop.
Download all sentry events for a project. Useful for data processing
"""Download sentry data.
usage:
python download_sentry_data.py <org>/<project> <api_key>
"""
import requests
import csv
import sys
if __name__ == '__main__':
with open('data.csv', 'w', encoding='utf-8') as csvfile:
fieldnames = ['culprit', 'count', 'lastSeen', 'logger']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames, extrasaction='ignore')
writer.writeheader()
url = 'https://app.getsentry.com/api/0/projects/{0}/issues/'.format(sys.argv[1])
while True:
response = requests.get(
url,
headers={'Authorization': 'Bearer {TOKEN}'.format(TOKEN=sys.argv[2])}
)
data = response.json()
for event in data:
# tags = {item['key']: item['value'] for item in event['tags']}
writer.writerow(dict(event))
link = response.headers.get('Link')
print("Last event date: {0}".format(data[-1]['lastSeen']))
if link and '"next"' in link:
print("Getting next page...")
url = link.split()[4][1:-2]
else:
break
@mezotv
Copy link

mezotv commented Nov 16, 2023

Does not work anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment