Last active
January 29, 2020 00:44
-
-
Save arthurchui/39444505076835eed48ef9950e5b4d4a to your computer and use it in GitHub Desktop.
Export Bugsnag's errors to
This file contains hidden or 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
#!/usr/bin/env ruby | |
require "csv" | |
require "bugsnag/api" | |
token = ENV["TOKEN"] | |
Bugsnag::Api.configure do |config| | |
config.auth_token = token | |
end | |
def organization | |
@organization ||= Bugsnag::Api::organizations[0] | |
end | |
def projects | |
Bugsnag::Api.projects(organization.id, per_page: 100) | |
end | |
def export_for_project(project, csv) | |
csv << ["Project", "Last Seen", "Context", "ErrorClass", "Message", "URL"] | |
get_errors(project.id).each do |error| | |
csv << [ | |
project.slug, | |
error.last_seen, | |
error.context, | |
error.error_class, | |
error.message, | |
"https://app.bugsnag.com/#{organization.slug}/#{project.slug}/errors/#{error.id}" | |
] | |
end | |
end | |
def get_errors(project_id) | |
errors = Bugsnag::Api.errors(project_id, per_page: 100) | |
last_response = Bugsnag::Api.last_response | |
until last_response.rels[:next].nil? | |
last_response = last_response.rels[:next].get | |
sleep(3) # avoid rate limit | |
errors.concat last_response.data | |
end | |
errors | |
end | |
CSV.open("bugsnag.csv", "w") do |csv| | |
projects.each do |project| | |
export_for_project(project, csv) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment