Skip to content

Collecting Sentry event data using the API

Mike Lissner edited this page Feb 8, 2024 · 2 revisions

For some debugging tasks where we should test our solutions against all offending documents, it is convenient to download the Sentry events data to access the documents programatically.

To use the Sentry API, we create a bearer token here.

After that, we can download all event data changing the issue_id numeric value, and, if needed, the project_slug

Depending on the logging.info and the exception traceback, the event data fields will be different. You will need to write access scripts in an issue-to-issue basis.

import requests

SENTRY_BEARER_TOKEN = "..."
headers = {'Authorization': f'Bearer {SENTRY_BEARER_TOKEN}'}

organization_slug = "freelawproject"
issue_id = '4615345348'

url = f"https://sentry.io/api/0/organizations/{organization_slug}/issues/{issue_id}/events/"
issue_response = requests.get(url, headers=headers).json()

# Returns a JSON List of summary information of events
# dict_keys(['id', 'event.type', 'groupID', 'eventID', 'projectID', 'message', 'title', 'location', 'culprit', 'user', 'tags', 'platform', 'dateCreated', 'crashFile'])


project_slug = 'courtlistener'
events = []
for event in issue_response:
    event_id = event['eventID']
    url = f"https://sentry.io/api/0/projects/{organization_slug}/{project_slug}/events/{event_id}/"
    events.append( requests.get(url, headers=headers).json())

# dict_keys(['id', 'groupID', 'eventID', 'projectID', 'size', 'entries', 'dist', 'message', 'title', 'location', 'user', 
# 'contexts', 'sdk', 'context', 'packages', 'type', 'metadata', 'tags', 'platform', 'dateReceived', 'errors', 'occurrence', '_meta', 'crashFile', 'culprit',
# 'dateCreated', 'fingerprints', 'groupingConfig', 'release', 'userReport', 'sdkUpdates', 'resolvedWith', 'nextEventID', 'previousEventID'])