Background worker doesn't work for classic Sinatra apps
Issue Description
When being ran in classic mode and without config.ru (e.g. bundle exec ruby app.rb), Sinatra apps will be initialized at the end of the Ruby script by a at_exit callback. And that means that the SDK's at_exit callback will also be called:
https://github.com/getsentry/sentry-ruby/blob/0f66522fec93bd03d5f3a3c9e9c0a1d759013b64/sentry-ruby/lib/sentry-ruby.rb#L216-L219
So when app.rb is loaded, the SDK's background worker is also disabled 🙈 Therefore, no event will be sent by the SDK.
Reproduction Steps
Script
# app.rb
require 'sinatra'
require 'sentry-ruby'
Sentry.init do |config|
config.dsn = 'DSN'
end
use Sentry::Rack::CaptureExceptions
get "/" do
raise "foo"
end
Command
$ bundle exec ruby app.rb
Expected Behavior
Errors will be reported.
Actual Behavior
Errors are not reported because the background worker is shut down unexpectedly.
Ruby Version
3.1.0
SDK Version
5.2.1 & master
Integration and Its Version
No response
Sentry Config
No response
@sl0thentr0py This is a funny behavior that really puzzled me for a while 😂
We already had a support ticket for this, the following workaround works
# app.rb
require 'sentry-ruby'
Sentry.init do |config|
config.dsn = 'DSN'
end
require 'sinatra'
use Sentry::Rack::CaptureExceptions
get "/" do
raise "foo"
end
Not ideal but it's just because of this funny business that sinatra does with at_exit.
Oh damn. How many support tickets do we have that could've been turned into issues 😂 I don't know how to fix this either. But I'm going to add logging (debug) when the background worker is shutdown. That'll make similar issues easier to investigate.
How many support tickets do we have that could've been turned into issues
Oh not too many so far, but yeah that's a good point that I could definitely document some of those in the open on github. Just need to be less lazy. Will keep in mind. :)
Haha, I'm not blaming you! It's a fun issue to debug and a good way to learn Sinatra anyway. I just didn't expect that you are already aware of it.
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
this is now documented https://docs.sentry.io/platforms/ruby/guides/rack/#without-rackup so I'm closing this