sentry-ruby icon indicating copy to clipboard operation
sentry-ruby copied to clipboard

Sentry Cron MonitorCheckIns ability to skip and resume checkin process

Open amkisko opened this issue 4 months ago • 9 comments

Problem Statement

Hey!

This is very specific problem related to very frequent or jobs which split progress within runs e.g. pagination, cursor-based parameters for the same job.

Due to large volume Sentry starts rate-limiting and also since progress determined by job parameters it should not be so that check-in happens on each and every run.

References:

  • https://github.com/getsentry/sentry-ruby/blob/master/sentry-ruby/lib/sentry/cron/monitor_check_ins.rb

Solution Brainstorm

  • Add skip_sentry_check_in! method to job class instance, without additional arguments
  • Add send_sentry_check_in! method to job class instance, default to :ok checkin type (error should be attached to actual error? in_progress does not make sense to send in this case?)

amkisko avatar Oct 17 '25 09:10 amkisko

RUBY-106

linear[bot] avatar Oct 17 '25 09:10 linear[bot]

hey @amkisko, this is a custom use case, I would advice you to a build a helper for those specific jobs that calls Sentry.capture_check_in before the job starts and after the job completes as per your parameters.

You can take inspiration from our patch for job classes here. https://github.com/getsentry/sentry-ruby/blob/c6d98f1acc072dafd2d1d11c641d4fb1225ce9b9/sentry-ruby/lib/sentry/cron/monitor_check_ins.rb#L9-L28

I will close this as not planned because this use case isn't general enough but if you want help with your solution, feel free to continue the discussion and I will help you!

sl0thentr0py avatar Oct 20 '25 10:10 sl0thentr0py

@sl0thentr0py Hey!

this is a custom use case

I don't agree with this as check-ins happen automatically when integration turned on. Also I would want automation to be in place, but for only some exact jobs to have full control within the code.

At least skip_sentry_check_ins! method on the job level definition could be already a solution and then doing custom thing as you mentioned, which for sure I already considered, but there is no way to disable automation per job.

amkisko avatar Oct 20 '25 15:10 amkisko

Do you want to add skip_sentry_check_ins! on the job class or on a single job instance?

sl0thentr0py avatar Oct 20 '25 16:10 sl0thentr0py

@sl0thentr0py according to initially described problem having at least job class method already covers the needs, basically ordering Sentry SDK to not do any check-in actions related to this job, so it all will be handled (or not) manually.

amkisko avatar Oct 21 '25 05:10 amkisko

ok makes sense, I'll try to add it soon! a bit swamped right now

sl0thentr0py avatar Oct 21 '25 10:10 sl0thentr0py

@sl0thentr0py I had quick look at this, but it was not fully clear at which point we should put a block if ordered to skip, as there are multiple places, and also not sure what is the best way to store such setting. That's why I left issue without pull request, expecting to have a discussion here first. :)

amkisko avatar Oct 21 '25 10:10 amkisko

There's actually a hacky way to achieve what you want without any changes.

I assume you are using either sidekiq_cron or sidekiq_scheduler. Those patches skip the prepend if the ancestor already exists. https://github.com/getsentry/sentry-ruby/blob/c6d98f1acc072dafd2d1d11c641d4fb1225ce9b9/sentry-sidekiq/lib/sentry/sidekiq/cron/job.rb#L60

So in the job you want to skip, if you just include the module WITHOUT calling sentry_monitor_check_ins, those jobs will not be tracked.

class ExampleJob < ApplicationJob
  include Sentry::Cron::MonitorCheckIns

  ## DON'T ADD THIS LINE - sentry_monitor_check_ins

  def perform(*args)
    # do stuff
  end
end

Of course this is very hacky and confusing, so I'd make this more explicit by adding a boolean parameter disabled here https://github.com/getsentry/sentry-ruby/blob/c6d98f1acc072dafd2d1d11c641d4fb1225ce9b9/sentry-ruby/lib/sentry/cron/monitor_check_ins.rb#L46

that doesn't patch the job if disabled. Then, you can do the following to be a bit more consistent.

```ruby
class ExampleJob < ApplicationJob
  include Sentry::Cron::MonitorCheckIns

  sentry_monitor_check_ins disabled: true

  def perform(*args)
    # do stuff
  end
end

sl0thentr0py avatar Oct 21 '25 10:10 sl0thentr0py

@sl0thentr0py I am using brand new GoodJob extension which is under Pull Request here and it should work the way you described.

amkisko avatar Oct 21 '25 15:10 amkisko