getsentry / getsentry/sentry-ruby
Profiling Rake Tasks launched with Cron
- Dominant language
- Ruby
- Stars
- 987
- Forks
- 541
- Avg merge
- 17h 40m
- Merged PRs (30d)
- 19
Description
### Environment
SaaS (https://sentry.io/)
### What are you trying to accomplish?
I am trying to profile Ruby/Rails rake tasks that run with Cron so that I can have insight into their performance (slow queries, n+1 issues, etc) like I do with normal rails transactions. I use a cron file run rake tasks. Ex:
```
0 0,2,4,6,8,10,12,14,16,18,20,22 * * * /bin/bash -l -c 'cd /home/deploy/projectName/releases/20240... && RAILS_ENV=production RAILS_ENV=production bundle exec rake environment myraketasks:hello_workd --silent >> log/cron.log 2>> log/cron-error.log'
```
It seems that even if I put profile sampling to 100%, these rake tasks are never picked up and I have no visibility into how they're performing.
I've also tried manually starting a transaction within the rake task. This seems like it would be the right thing to do however database queries and profiling data is still not logged.
```
desc 'This is a sample rake task'
task :hello_world, [:force_staging, :mode] => :environment do |t, args|
transaction = Sentry.start_transaction(op: "hello_world")
...
do_work()
...
transaction.finish
end
```
### How are you getting stuck?
I'm not sure how to enable profiling for these rake tasks so that I can monitor their performance.
### Where in the product are you?
Performance
### Link
_No response_
### DSN
_No response_
### Version
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.