Created
February 4, 2026 22:35
-
-
Save javierjulio/06853e4a23c658a16ee7532f0a3e8866 to your computer and use it in GitHub Desktop.
Bugsnag Data API Interactive Console
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 | |
| # Include this script with no file extension in your project's `bin` directory. | |
| # Update the script with your organization slug. | |
| ORGANIZATION_SLUG = "" # Your Bugsnag organization slug | |
| require "io/console" # provides `STDIN.noecho` method | |
| begin | |
| require "bugsnag/api" | |
| rescue LoadError | |
| puts "The bugsnag-api gem is not installed." | |
| puts "Run: `gem install bugsnag-api`" | |
| exit 1 | |
| end | |
| module CallWithRetryOnRateLimitExceeded | |
| def call(method, url, data=nil, options=nil) | |
| super | |
| rescue Bugsnag::Api::RateLimitExceeded | |
| puts "RateLimitExceeded: Retrying in 60 seconds" | |
| sleep 60 and retry | |
| end | |
| end | |
| Sawyer::Agent.send(:prepend, CallWithRetryOnRateLimitExceeded) | |
| def token_authenticates?(token) | |
| puts "Testing authentication..." | |
| Bugsnag::Api::Client.new(auth_token: token).organizations | |
| rescue Bugsnag::Api::Error | |
| puts "Failed: Unauthorized" | |
| else | |
| true | |
| end | |
| puts "Please enter your Bugsnag personal access token." | |
| token = "" | |
| loop do | |
| print "Enter token: " | |
| token = STDIN.noecho(&:gets).strip | |
| puts "" | |
| break if token_authenticates?(token) | |
| end | |
| undef :token_authenticates? | |
| @client = Bugsnag::Api::Client.new(auth_token: token) | |
| def client | |
| @client | |
| end | |
| alias :bugsnag :client | |
| alias :bugsnag_api :client | |
| def enable_auto_pagination | |
| client.configuraion.auto_paginate = true | |
| "Enabled auto pagination" | |
| end | |
| def disable_auto_pagination | |
| client.configuraion.auto_paginate = false | |
| "Disabled auto pagination" | |
| end | |
| def organization_id | |
| @organization_id ||= client.organizations.find { |i| i.slug == ORGANIZATION_SLUG }.id | |
| end | |
| def project_ids | |
| @project_ids ||= client.projects(organization_id).sort_by(&:slug).to_h { |i| [i.slug, i.id] } | |
| end | |
| project_ids.each do |slug, id| | |
| name = "#{slug.gsub("-", "_")}_id" | |
| define_method(name) do | |
| return instance_variable_get("@#{name}") if instance_variable_defined?("@#{name}") | |
| instance_variable_set("@#{name}", project_ids[slug]) | |
| end | |
| end | |
| def error_events(project_id, error_id, **options) | |
| client.error_events(project_id, error_id, { full_reports: true }.merge(options)) | |
| end | |
| puts "Bugsnag client ready" | |
| puts enable_auto_pagination | |
| require "irb" | |
| IRB.start(__FILE__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment