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

Background worker doesn't work for classic Sinatra apps #1778

Closed
st0012 opened this issue Mar 31, 2022 · 7 comments
Closed

Background worker doesn't work for classic Sinatra apps #1778

st0012 opened this issue Mar 31, 2022 · 7 comments
Assignees
Projects
Milestone

Comments

@st0012
Copy link
Collaborator

st0012 commented Mar 31, 2022

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:

at_exit do
@session_flusher&.kill
@background_worker.shutdown
end

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

@st0012 st0012 added this to the 5.3.0 milestone Mar 31, 2022
@st0012 st0012 added this to To do in 5.x via automation Mar 31, 2022
@st0012 st0012 self-assigned this Mar 31, 2022
@st0012
Copy link
Collaborator Author

st0012 commented Mar 31, 2022

@sl0thentr0py This is a funny behavior that really puzzled me for a while 😂

@sl0thentr0py
Copy link
Member

sl0thentr0py commented Mar 31, 2022

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.

@st0012
Copy link
Collaborator Author

st0012 commented Mar 31, 2022

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.

@sl0thentr0py
Copy link
Member

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. :)

@st0012
Copy link
Collaborator Author

st0012 commented Mar 31, 2022

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.

@github-actions
Copy link

github-actions bot commented May 1, 2022

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 🥀

@sl0thentr0py
Copy link
Member

this is now documented https://docs.sentry.io/platforms/ruby/guides/rack/#without-rackup
so I'm closing this

5.x automation moved this from To do to Done Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
5.x
Done
Development

No branches or pull requests

3 participants