-
-
Save gurukulkarni/3c1d32d7aec05a864829f50953642cc4 to your computer and use it in GitHub Desktop.
Download all sentry events for a project. Useful for data processing
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
"""Download sentry data. | |
usage: | |
python download_sentry_data.py <org>/<project> <api_key> | |
""" | |
import requests | |
import csv | |
if __name__ == '__main__': | |
with open('data.csv', 'w', encoding='utf-8') as csvfile: | |
fieldnames = ['dateCreated', 'device', 'environment', 'os', 'url', 'message'] | |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames, extrasaction='ignore') | |
writer.writeheader() | |
url = 'https://app.getsentry.com/api/0/projects/{0}/events/'.format(sys.argv[1]) | |
while True: | |
response = requests.get( | |
url, | |
auth=(sys.argv[2], '')) | |
data = response.json() | |
for event in data: | |
tags = {item['key']: item['value'] for item in event['tags']} | |
writer.writerow(dict(event, **tags)) | |
link = response.headers.get('Link') | |
print("Last event date: {0}".format(data[-1]['dateCreated'])) | |
if link and '"next"' in link: | |
print("Getting next page...") | |
url = link.split()[4][1:-2] | |
else: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment