bugsnag / bugsnag-api-ruby

BugSnag API toolkit for Ruby
Other
21 stars 15 forks source link

Bugsnag::Api::BadRequest when paginating errors for event #21

Closed ckhall closed 5 years ago

ckhall commented 6 years ago

per pagination documentation, I'm attempting to pull down all the events associated with a given error. As it loops through, the 4th time through, it errors with a 400 bad request error and outputs a very large URI with several offset event_ids parameters.

error: (project, error, and event ids redacted)

Bugsnag::Api::BadRequest: GET https://api.bugsnag.com/projects/project_id/errors/error_id/events?base=2018-09-06T00%3A57%3A53Z&offset%5Bcount%5D=400&offset%5Bevent_ids%5D%5B%5D=event_id1&offset%5Bevent_ids%5D%5B%5D=event_id2&offset%5Bevent_ids%5D%5B%5D=event_id3&offset%5Bevent_ids%5D%5B%5D=event_id4&offset%5Bevent_ids%5D%5B%5D=event_id5&offset%5Bevent_ids%5D%5B%5D=event_id6&offset%5Bevent_ids%5D%5B%5D=event_id7&offset%5Bevent_ids%5D%5B%5D=event_id8&offset%5Bevent_ids%5D%5B%5D=event_id9&offset%5Bevent_ids%5D%5B%5D=event_id10&offset%5Bevent_ids%5D%5B%5D=event_id11&offset%5Bevent_ids%5D%5B%5D=event_id12&offset%5Bevent_ids%5D%5B%5D=event_id13&offset%5Bevent_ids%5D%5B%5D=event_id14&offset%5Bevent_ids%5D%5B%5D=event_id15&offset%5Bevent_ids%5D%5B%5D=event_id16&offset%5Bevent_ids%5D%5B%5D=event_id17&offset%5Bevent_ids%5D%5B%5D=event_id18&offset%5Bevent_ids%5D%5B%5D=event_id19&offset%5Bevent_ids%5D%5B%5D=event_id20&offset%5Bevent_ids%5D%5B%5D=event_id21&offset%5Bevent_ids%5D%5B%5D=event_id21&offset%5Bevent_ids%5D%5B%5D=event_id22&offset%5Bevent_ids%5D%5B%5D=event_id23&offset%5Bevent_ids%5D%5B%5D=event_id24&offset%5Bevent_ids%5D%5B%5D=event_id25&offset%5Bevent_ids%5D%5B%5D=event_id26&offset%5Bevent_ids%5D%5B%5D=event_id27&offset%5Bevent_ids%5D%5B%5D=event_id28&offset%5Bevent_ids%5D%5B%5D=event_id29&offset%5Bevent_ids%5D%5B%5D=event_id30&offset%5Bevent_ids%5D%5B%5D=event_id31&offset%5Bevent_ids%5D%5B%5D=event_id32&offset%5Bevent_ids%5D%5B%5D=event_id33&offset%5Btimestamp%5D=2018-09-05T21%3A53%3A26.000Z&offset%5Btotal_count%5D=11447&per_page=100: 400
-
from /Projects/my_app/vendor/bundle/ruby/2.3.0/gems/bugsnag-api-2.0.2/lib/bugsnag/api/response/raise_error.rb:16:in `on_complete'

code to reproduce:

client = Bugsnag::Api::Client.new(auth_token: "my-token")
project_id ="abc123"
filters = { "event.since"       => [{ type: "eq", value: "2018-09-05T12:00:00.000Z" }],
            "event.before"      => [{ type: "eq", value: "2018-09-05T23:00:00.000Z" }],
            "app.release_stage" => [{ type: "eq", value: "production" }],
            "event.severity"    => [{ type: "eq", value: "error" }, { type: "eq", value: "warning" }],
            "error.status"      => [{ type: "eq", value: "open" }],
            "event.class"       => [{ type: "eq", value: "ActiveRecord::StatementInvalid" }]
}

errors = client.errors(project_id, nil, { filters: filters })
events = client.error_events(project_id, errors[0][:id], { per_page: 100 })

last_response = client.last_response
puts Addressable::URI.unescape(last_response.rels[:next].href_template.pattern)

until last_response.rels[:next].nil?
  last_response = last_response.rels[:next].get
  puts Addressable::URI.unescape(last_response.rels[:next].href_template.pattern)
end

`

if i change per_page option to 50, it errors on the 8th time through the loop, so it seems like it gets to the same spot and blows up once it gets through 400 events. I've tried it on a few other errors, another one with a large amount of events, and a couple smaller ones and those get past the 400 mark and I eventually get a 429 RateLimit error, which is expected.

Any help would be appreciated. Thanks.

ckhall commented 6 years ago

additional backtrace:

/Projectsmyapp/vendor/bundle/ruby/2.3.0/gems/bugsnag-api-2.0.2/lib/bugsnag/api/response/raise_error.rb:16:in `on_complete'
/Projectsmyapp/vendor/bundle/ruby/2.3.0/gems/faraday-0.9.2/lib/faraday/response.rb:9:in `block in call'
/Projectsmyapp/vendor/bundle/ruby/2.3.0/gems/faraday-0.9.2/lib/faraday/response.rb:57:in `on_complete'
/Projectsmyapp/vendor/bundle/ruby/2.3.0/gems/faraday-0.9.2/lib/faraday/response.rb:8:in `call'
/Projectsmyapp/vendor/bundle/ruby/2.3.0/gems/faraday-0.9.2/lib/faraday/rack_builder.rb:139:in `build_response'
/Projectsmyapp/vendor/bundle/ruby/2.3.0/gems/faraday-0.9.2/lib/faraday/connection.rb:377:in `run_request'
/Projectsmyapp/vendor/bundle/ruby/2.3.0/gems/faraday-0.9.2/lib/faraday/connection.rb:140:in `get'
/Projectsmyapp/vendor/bundle/ruby/2.3.0/gems/sawyer-0.8.1/lib/sawyer/agent.rb:94:in `call'
/Projectsmyapp/vendor/bundle/ruby/2.3.0/gems/sawyer-0.8.1/lib/sawyer/relation.rb:264:in `call'
/Projectsmyapp/vendor/bundle/ruby/2.3.0/gems/sawyer-0.8.1/lib/sawyer/relation.rb:163:in `get'
snmaynard commented 6 years ago

You need to set the sort parameter to unsorted when using filters and paginating for a few pages. Looks like our docs here need improvement - and I don't know if this library supports/validates the sort param. If it allows it, that should unblock you and we should look at improving the docs here!

Cawllec commented 5 years ago

Hi @ckhall, has the above comment solved your issue? Any feedback you have regarding the API or the docs is really valuable, so we'd love to know.

ckhall commented 5 years ago

It worked fine. Thanks for the information.

On Mon, Sep 17, 2018 at 11:55 AM Alex Moinet notifications@github.com wrote:

Hi @ckhall https://github.com/ckhall, has the above comment solved your issue? Any feedback you have regarding the API or the docs is really valuable, so we'd love to know.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/bugsnag/bugsnag-api-ruby/issues/21#issuecomment-422070220, or mute the thread https://github.com/notifications/unsubscribe-auth/AAArPFJoJj3kfiQieXcA0SAcfQhE-Ro9ks5ub8YGgaJpZM4Wb_J- .