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

Use ActiveSupport Lazy Load Hook to Apply ActiveJob Extension #1494

Merged
merged 1 commit into from
Jul 8, 2021

Conversation

jdelStrother
Copy link
Contributor

@jdelStrother jdelStrother commented Jul 2, 2021

Since the 4.5.1 release, setting Rails.application.config.active_job.foo = bar in an initializers file (eg config/initializers/foo.rb) would be ignored.

As soon as ActiveJob::Base is referenced, it applies Rails.application.config.active_job, and any further changes to that config are ignored. By loading ActiveJob::Base before eager_load, it prevents ActiveJob being configured in, eg, config/initializers/new_framework_defaults.rb

How about using ActiveSupport.on_load(:active_job) instead?

This tweaks the behaviour in #1464 which was introduced to fix #1249, would be good to confirm that the original issue poster isn't affected by this new fix.

I tried to add a test but found it kind of tricky. ActiveJob::Base is already loaded by the time we call make_basic_app in specs, so it seems impossible to hook in early enough to test the failure case.

cc @CroneKorkN, @st0012

@codecov-commenter
Copy link

codecov-commenter commented Jul 2, 2021

Codecov Report

Merging #1494 (537ff27) into master (7b9f8fc) will increase coverage by 0.56%.
The diff coverage is 100.00%.

❗ Current head 537ff27 differs from pull request most recent head c0d4dd9. Consider uploading reports for the commit c0d4dd9 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1494      +/-   ##
==========================================
+ Coverage   98.21%   98.77%   +0.56%     
==========================================
  Files         218      123      -95     
  Lines       10553     6715    -3838     
==========================================
- Hits        10365     6633    -3732     
+ Misses        188       82     -106     
Impacted Files Coverage Δ
sentry-rails/lib/sentry/rails/railtie.rb 100.00% <100.00%> (ø)
sentry-raven/spec/raven/instance_spec.rb
sentry-raven/lib/raven/transports/stdout.rb
sentry-raven/spec/raven/integration_spec.rb
sentry-raven/spec/raven/cli_spec.rb
sentry-raven/lib/raven/interfaces/stack_trace.rb
sentry-raven/spec/raven/breadcrumbs_spec.rb
sentry-raven/lib/raven/breadcrumbs.rb
sentry-raven/spec/raven/json_spec.rb
sentry-raven/lib/raven/transports/dummy.rb
... and 86 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b9f8fc...c0d4dd9. Read the comment docs.

@st0012
Copy link
Collaborator

st0012 commented Jul 2, 2021

@jdelStrother thanks for spotting the issue and opening this PR. I can confirm that it fixes the original issue by manually testing it 👍
but given that there are 2 scenarios to cover, I want to come up with a test setup for testing patches in isolation. give me a few days and I'll come back to this.

@st0012 st0012 added this to In progress in 4.x via automation Jul 2, 2021
@st0012
Copy link
Collaborator

st0012 commented Jul 4, 2021

@jdelStrother I've added an isolated test for ActiveJob patching in #1497. can you modify it and make it fail without your fix?

@st0012 st0012 added this to the 4.7.0 milestone Jul 4, 2021
As soon as ActiveJob::Base is referenced, it applies Rails.application.config.active_job, and any further changes to that config are ignored. By loading ActiveJob::Base before eager_load, it prevents activejob being configured in, eg, config/initializers/new_framework_defaults.rb
@jdelStrother
Copy link
Contributor Author

Sure, I've pushed an update with a test.

4.x automation moved this from In progress to Reviewer approved Jul 8, 2021
Copy link
Collaborator

@st0012 st0012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jdelStrother thanks for the fix 😄

@st0012 st0012 merged commit 68afa88 into getsentry:master Jul 8, 2021
4.x automation moved this from Reviewer approved to Done Jul 8, 2021
@st0012 st0012 changed the title Don't force ActiveJob to load during initialization Use ActiveSupport Lazy Load Hook to Apply ActiveJob Extension Jul 8, 2021
@st0012
Copy link
Collaborator

st0012 commented Jul 8, 2021

@jdelStrother btw I also updated the PR description and changelog entry to make the change more clear to users.

@st0012 st0012 modified the milestones: 4.7.0, 4.6.1 Jul 8, 2021
rsanheim added a commit to simpledotorg/simple-server that referenced this pull request Jul 29, 2021
rsanheim added a commit to simpledotorg/simple-server that referenced this pull request Jul 30, 2021
choznerol added a commit to choznerol/sentry-ruby that referenced this pull request Dec 9, 2021
Similar to the update for ActionCableExtensions in getsentry#1218 and getsentry#1494
st0012 pushed a commit that referenced this pull request Dec 12, 2021
…tion of #1295) (#1638)

* capture exceptions in Action Cable connections and channels

There are 5 types of hooks that Action Cable provides:

* `Connection#connect`
* `Connection#disconnect`
* `Channel#subscribed`
* `Channel#unsubscribed`
* `Channel` actions

Now, any exceptions raised within those hooks are captured by Sentry, and reported as `ActionCable/[...]` transactions. Additional context is included depending on the hook the exception was raised within.

A note/quirk: the Rack env that's included in the scope is from the `Connection`, and therefore has a URL of the cable `mount_path` (usually `/cable`) as well as the headers from that initial connection request.

Additionally, there is not currently a really clean way to hook in and set `user_context`. I don't know if that is a blocker for this integration, but wanted to make sure it was noted.

* Only extend ActionCable when it's defined

Similar to the update for ActionCableExtensions in #1218 and #1494

* test(ActionCable): Assert only 1 event captured:

#1295
#1295

* Remove namespace 'ActionCable/*'

#1295

* Test ActionCable #unsubscribed

#1295

* test(ActionCable): prefer rspec-rails over mini-test

#1295 (comment)

* test(ActionCable): cleanup duplicated set_callback

* docs(CHANGELOG): update #1295 to #1638

Co-authored-by: Alex Robbin <agrobbin@gmail.com>
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 this pull request may close these issues.

sentry + eager_load breaks ActiveJob rescue_from
3 participants