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

Exceptions from ActiveJob with Resque backend are not captured on Sentry #1559

Closed
tsrivishnu opened this issue Sep 2, 2021 · 5 comments · Fixed by #1565
Closed

Exceptions from ActiveJob with Resque backend are not captured on Sentry #1559

tsrivishnu opened this issue Sep 2, 2021 · 5 comments · Fixed by #1565
Assignees
Projects
Milestone

Comments

@tsrivishnu
Copy link

tsrivishnu commented Sep 2, 2021

Describe the bug

Exceptions from ActiveJob jobs are not sent to Sentry. The jobs simply fail and no errors are sent to Sentry.

image

I'm not sure if I'm missing any configuration options for this to work correctly.

To Reproduce

Rails.application.config.active_job.queue_adapter = :resque

class ApplicationJob < ActiveJob::Base
end

class MyJob < ApplicationJob
  def perform
    raise "foo"
  end
end

MyJob.perform_later
$ bundle exec rake environment resque:work QUEUE=*

Expected behavior

foo RuntimeError is captured and sent to Sentry

Actual behavior

foo RuntimeError is not captured and not sent to Sentry

Environment

  • Ruby Version: 2.7.1
  • SDK Version: 4.7.1
  • Integration Versions (if any):
    • Rails 6.1.3.2,
    • Resque 2.0.0,
    • sentry-rails 4.7.1

Sentry Config

Sentry.init do |config|
  config.dsn = "..."
  config.breadcrumbs_logger = [:active_support_logger, :http_logger]

  # Sent events only for the below environments
  config.enabled_environments = %w[ development staging production ]

  config.background_worker_threads = 0

  filter = ActiveSupport::ParameterFilter.new(Rails.application.config.filter_parameters)
  config.before_send = lambda do |event, _hint|
    filter.filter(event.to_hash)
  end
end
@st0012
Copy link
Collaborator

st0012 commented Sep 2, 2021

I'm not able to reproduce this issue with the example app under sentry-rails/examples/rails-6.0. here's a screenshot of the events I received:

With sentry-resque + sentry-rails

截圖 2021-09-02 下午9 25 00

With only sentry-rails

截圖 2021-09-02 下午9 30 20

can you check if the SDK is initialized and enabled in your environment? you can check it by manually sending a message from rails console:

Sentry.capture_message("test message")

if you confirm that SDK works properly for the rest of your application, can you make a reproduction app to help me debug the issue?

@tsrivishnu
Copy link
Author

Explicitly sending a message works both from rails console or from with the job's perform method.

I will try to reproduce in a sample app and push that.

@tsrivishnu
Copy link
Author

Here is the test app: https://github.com/tsrivishnu/rails-sentry-resque-active-job-test. I included instructions to run it in docker with docker-compose.

Let me know if you face any issues.

Correction to my previous comment.
Manually sending message with Sentry.capture_message works from console but not from the job's perform method.

@st0012
Copy link
Collaborator

st0012 commented Sep 2, 2021

@tsrivishnu ok it's because resque worker doesn't contain either RAILS_ENV or RACK_ENV, so the SDK uses a default "default" environment (inherited from the old SDK). and because it's not in your enabled_environments, event capturing is disabled.

I think you can make it work by adding default to the list.

I'll make a PR to change the default environment to 'development'.

@tsrivishnu
Copy link
Author

@st0012 Thank you. I confirm that it works after adding default to the enabled_environments list or passing RAILS_ENV=development to the Resque worker. 👍🏽

Feel free to close this issue or keep it open for you to track the PR to change the default environment to 'development'.

@st0012 st0012 added this to To do in 4.x via automation Sep 3, 2021
@st0012 st0012 added this to the 4.8.0 milestone Sep 3, 2021
4.x automation moved this from To do to Done Sep 3, 2021
@st0012 st0012 modified the milestones: 4.8.0, 4.7.2 Sep 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4.x
  
Done
Development

Successfully merging a pull request may close this issue.

2 participants