-
-
Save siiramone/0d2ed5fe9a78b4f34f70d60d6a9f80b2 to your computer and use it in GitHub Desktop.
Download sentry issues within the specified date range 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: | |
1. create auth token (https://sentry.io/settings/account/api/auth-tokens/). | |
2. make a directory for export if not exists. | |
$ mkdir data | |
3. fix event.timestamp (L27). | |
4. execute | |
$ python download_sentry_data.py <org>/<project> <auth_token> | |
5. a CSV file with a name formatted as "./data/issues_YYYYmmDDHHMMSS.csv" is created. | |
""" | |
import requests | |
import csv | |
import sys | |
import datetime | |
if __name__ == '__main__': | |
dt_now = datetime.datetime.now() | |
now = dt_now.strftime('%Y%m%d%H%M%S') | |
with open('./data/issues_{0}.csv'.format(now), 'w', encoding='utf-8') as csvfile: | |
fieldnames = ['count', 'title', 'status', 'lastSeen', 'firstSeen', 'culprit', 'permalink'] | |
writer = csv.DictWriter(csvfile, fieldnames=fieldnames, extrasaction='ignore') | |
writer.writeheader() | |
url = f'https://app.getsentry.com/api/0/projects/{sys.argv[1]}/issues/' | |
# time-range absolute date | |
params = {'query': 'event.timestamp:>=2020-04-01T00:00:00 event.timestamp:<2020-05-01T00:00:00'} | |
while True: | |
response = requests.get( | |
url, | |
params=params, | |
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(f"Last event date: {data[-1]['lastSeen']}") | |
if link and 'rel="next"; results="true"' 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
Doesn't seem to work anymore