Skip to content

Instantly share code, notes, and snippets.

@arthurchui
Last active January 29, 2020 00:44
Show Gist options
  • Save arthurchui/39444505076835eed48ef9950e5b4d4a to your computer and use it in GitHub Desktop.
Save arthurchui/39444505076835eed48ef9950e5b4d4a to your computer and use it in GitHub Desktop.
Export Bugsnag's errors to
#!/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