Created
December 11, 2019 04:35
-
-
Save sukechannnn/c33f906441e14baa7f7dc39828d01d07 to your computer and use it in GitHub Desktop.
This script gets sidekiq arguments from an error event of Bugsnag.
This file contains 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
# This script gets sidekiq arguments from an error event of Bugsnag and lists arguments that are unique. | |
# It takes a long time to execute due to the Rate Limit of Bugsnag API. | |
# | |
# USAGE | |
# $ ruby path/to/bugsnag_sidekiq_args.rb #{event_id} | |
# example | |
# $ ruby path/to/bugsnag_sidekiq_args.rb 3efgqevb4dkr9012345n6789 | |
# > {"shop_id"=>"84f82b21-49a0-49cf-b2cf-faf93ca004a0", "_aj_symbol_keys"=>["shop_id"]} | |
# > {"shop_id"=>"2602f165-133a-4e45-84ac-bde7ac058026", "_aj_symbol_keys"=>["shop_id"]} | |
# > {"shop_id"=>"e9b50352-9940-43a6-b81e-5a9c8c24a636", "_aj_symbol_keys"=>["shop_id"]} | |
# > ... | |
# | |
require 'net/http' | |
require 'json' | |
base_url = URI.parse('https://api.bugsnag.com') | |
http = Net::HTTP.new(base_url.host, base_url.port) | |
http.use_ssl = true if base_url.port == 443 | |
auth_token = "token #{ENV['BUGSNAG_PERSONAL_API_TOKEN']}" | |
project_id = ENV['BUGSNAG_PROJECT_ID'] | |
event_id = ARGV.first # assigned like '3efgqevb4dkr9012345n6789' | |
events = http.get( | |
"https://api.bugsnag.com/projects/#{project_id}/errors/#{event_id}/events", | |
'Authorization' => auth_token | |
) | |
sidekiq_args = [] | |
JSON.parse(events.body).each do |body| | |
event = http.get(body['url'], 'Authorization' => auth_token) | |
sidekiq_args << JSON.parse(event.body)&.dig('metaData', 'sidekiq', 'msg', 'args')&.first&.dig('arguments') | |
sleep 10 | |
end | |
puts sidekiq_args.uniq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment