Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sentry::Cron::MonitorCheckIns module for automatic monitoring of jobs #2130

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

sl0thentr0py
Copy link
Member

@sl0thentr0py sl0thentr0py commented Oct 5, 2023

Standard job frameworks such as ActiveJob and Sidekiq can now use this module to automatically capture check ins.

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

  sentry_monitor_check_ins

  def perform(*args)
    # do stuff
  end
end
class SidekiqJob
  include Sidekiq::Job
  include Sentry::Cron::MonitorCheckIns

  sentry_monitor_check_ins

  def perform(*args)
    # do stuff
  end
end

You can pass in optional attributes to sentry_monitor_check_ins as follows.

# slug defaults to the job class name
sentry_monitor_check_ins slug: 'custom_slug'

# define the monitor config with an interval
sentry_monitor_check_ins monitor_config: Sentry::Cron::MonitorConfig.from_interval(1, :minute)

# define the monitor config with a crontab
sentry_monitor_check_ins monitor_config: Sentry::Cron::MonitorConfig.from_crontab('5 * * * *')

part of #2090

@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

Merging #2130 (571e522) into master (3d0ed07) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2130      +/-   ##
==========================================
- Coverage   97.30%   97.27%   -0.03%     
==========================================
  Files          96       89       -7     
  Lines        3596     3342     -254     
==========================================
- Hits         3499     3251     -248     
+ Misses         97       91       -6     
Components Coverage Δ
sentry-ruby 97.94% <100.00%> (-0.06%) ⬇️
sentry-rails 94.96% <ø> (ø)
sentry-sidekiq ∅ <ø> (∅)
sentry-resque 91.80% <ø> (-1.64%) ⬇️
sentry-delayed_job 94.36% <ø> (ø)
sentry-opentelemetry ∅ <ø> (∅)
Files Coverage Δ
sentry-ruby/lib/sentry-ruby.rb 95.33% <100.00%> (-0.50%) ⬇️
sentry-ruby/lib/sentry/cron/monitor_check_ins.rb 100.00% <100.00%> (ø)

... and 10 files with indirect coverage changes

…f jobs

Standard job frameworks such as `ActiveJob` and `Sidekiq` can now use this module to automatically capture check ins.

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

  sentry_monitor_check_ins

  def perform(*args)
    # do stuff
  end
end
```

```rb
class SidekiqJob
  include Sidekiq::Job
  include Sentry::Cron::MonitorCheckIns

  sentry_monitor_check_ins

  def perform(*args)
    # do stuff
  end
end
```

You can pass in optional attributes to `sentry_monitor_check_ins` as follows.
```rb
sentry_monitor_check_ins slug: 'custom_slug'

sentry_monitor_check_ins monitor_config: Sentry::Cron::MonitorConfig.from_interval(1, :minute)

sentry_monitor_check_ins monitor_config: Sentry::Cron::MonitorConfig.from_crontab('5 * * * *')
```
@sl0thentr0py sl0thentr0py marked this pull request as ready for review October 9, 2023 14:16
@cleptric cleptric self-requested a review October 9, 2023 14:19
@sl0thentr0py sl0thentr0py merged commit 65ef04c into master Oct 9, 2023
98 of 99 checks passed
@sl0thentr0py sl0thentr0py deleted the neel/crons/aj-sidekiq-module branch October 9, 2023 18:12
@trevorturk
Copy link

👋 Hello and apologies if this is the wrong place to ask, but I upgraded my gems today and was excited to see this new feature. However, after deploying and having some Sidekiq jobs running, I'm not seeing anything in the Sentry web interface. In reading the docs, I'm unclear if I need to do additional work (perhaps visiting /crons and then clicking "Add Monitor") or should I see the cron monitors appear automatically if I've done the include Sentry::Cron::MonitorCheckIns and sentry_monitor_check_ins dance?

@sl0thentr0py
Copy link
Member Author

you need to either Add Monitor in the UI or add a monitor_config to the helper in your job. We'll try to make this DX/docs better.

@trevorturk
Copy link

Thank you for the info! Just to follow up a bit, I do have the following:

class Api::ExampleJob
  include Sidekiq::Job
  include Sentry::Cron::MonitorCheckIns
  sentry_monitor_check_ins monitor_config: Sentry::Cron::MonitorConfig.from_crontab("0 * * * * *")

...but I'm gathering from other GH chatter that perhaps I need to include a slug param in the monitor_config bit, perhaps like so?

monitor_config = Sentry::Cron::MonitorConfig.from_crontab(
  "0 * * * * *",
  slug: "example_job"
)

I'd prefer to try to auto-configure these, so I don't have to use the web interface for other monitors, so I'm curious what else would be required.

I believe the relevant docs I think could use additional detail would be here: https://docs.sentry.io/platforms/ruby/crons/#job-monitoring

I appreciate the help, thank you!

@sl0thentr0py
Copy link
Member Author

Yeah this should be made clear in the docs, sorry about that.

  sentry_monitor_check_ins monitor_config: Sentry::Cron::MonitorConfig.from_crontab("0 * * * * *")

this will work, it'll set the slug to the job class name.

Or you can do the following for a custom slug

 sentry_monitor_check_ins slug: "example_job", monitor_config: Sentry::Cron::MonitorConfig.from_crontab("0 * * * * *")

@trevorturk
Copy link

Gotcha, so I think I'm all set? Perhaps my confusion is just that I expected to see something on sentry.io/crons telling me that my cron monitor was set up and is working. Might be worth considering for the product roadmap, if possible. Now I think I'd just expect to see something on sentry.io/issues if/when something goes wrong, but it'd be nice to see something in the web interface that confirmed the cron is being monitored. Now that I think of it, I'm not sure what would happen if I intentionally removed this job that's being monitored -- perhaps I'd see one error and then no more?

(Apologies for the chatter here, just trying to help with the beta feedback!)

@sl0thentr0py
Copy link
Member Author

np! always happy to hear feedback and this is quite new so we're still iterating.

but it'd be nice to see something in the web interface that confirmed the cron is being monitored.

if you've pushed this out, you should see check-ins start appearing in the Crons section in the product. And error statuses will get logged into Issues as well.

@trevorturk
Copy link

trevorturk commented Nov 7, 2023

Hmm, perhaps a bug, or I didn't configure things correctly. Let me know if I should contact support or via email, but the relevant project ID is 294023, I'm using sentry-rails (5.12.0) and the relevant code change is:

class Api::RedisHitCounterDbSyncJob
  include Sentry::Cron::MonitorCheckIns
  sentry_monitor_check_ins monitor_config: Sentry::Cron::MonitorConfig.from_crontab("0 * * * * *")

...and I think I'm seeing the blank slate view on the sentry.io/crons page.

@sl0thentr0py
Copy link
Member Author

that should work, can you make another issue with some details if possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants