Skip to content

Instantly share code, notes, and snippets.

@bubenkoff
Created April 22, 2016 19:51
Show Gist options
  • Save bubenkoff/60a33b8de7e9af16ec064802101829ce to your computer and use it in GitHub Desktop.
Save bubenkoff/60a33b8de7e9af16ec064802101829ce 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
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
@vladox
Copy link

vladox commented Jul 4, 2019

For a more current version check my fork: https://gist.github.com/vladox/f401db999c5efdf2f25d38683fde2813

@Arafat-alim
Copy link

@vladox could you please make a video or refer to any documentation for beginners, or explain more briefly?

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