Skip to content

Merge & Rename 2 Rack middlewares#1147

Merged
st0012 merged 2 commits intomasterfrom
merge-middlewares
Dec 15, 2020
Merged

Merge & Rename 2 Rack middlewares#1147
st0012 merged 2 commits intomasterfrom
merge-middlewares

Conversation

@st0012
Copy link
Copy Markdown
Contributor

@st0012 st0012 commented Dec 15, 2020

  1. Merge Tracing & CaptureException middlewares
  2. Rename CaptureException to CaptureExceptions to follow other Rails middlewares' naming convention, like ActionDispatch::ShowExceptions

@st0012 st0012 added this to the 4.1.0 milestone Dec 15, 2020
@st0012 st0012 self-assigned this Dec 15, 2020
@codecov-io
Copy link
Copy Markdown

codecov-io commented Dec 15, 2020

Codecov Report

Merging #1147 (e497568) into master (7454957) will increase coverage by 0.39%.
The diff coverage is 98.78%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1147      +/-   ##
==========================================
+ Coverage   97.74%   98.13%   +0.39%     
==========================================
  Files         189       64     -125     
  Lines        7804     3276    -4528     
==========================================
- Hits         7628     3215    -4413     
+ Misses        176       61     -115     
Impacted Files Coverage Δ
sentry-ruby/lib/sentry/rack/capture_exceptions.rb 90.62% <84.61%> (ø)
sentry-ruby/lib/sentry/rack.rb 100.00% <100.00%> (ø)
...ry-ruby/spec/sentry/rack/capture_exception_spec.rb 100.00% <100.00%> (ø)
...ntry-raven/lib/raven/processor/removestacktrace.rb
...aven/integrations/rails/controller_methods_spec.rb
...ven/spec/raven/processors/removestacktrace_spec.rb
sentry-raven/lib/raven/client.rb
sentry-raven/lib/raven/instance.rb
sentry-rails/spec/sentry/rails/tracing_spec.rb
...ven/breadcrumbs/active_support_breadcrumbs_spec.rb
... and 110 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 7454957...e497568. Read the comment docs.

1. Merge Tracing & CaptureException middlewares
2. Rename `CaptureException` to `CaptureExceptions` to
follow other Rails middlewares' naming convention, like `ActionDispatch::ShowExceptions`
@st0012 st0012 merged commit f546b3a into master Dec 15, 2020
@st0012 st0012 deleted the merge-middlewares branch December 15, 2020 14:49
@st0012 st0012 changed the title Merge 2 Rack middlewares Merge & Rename 2 Rack middlewares Dec 17, 2020
@agrobbin
Copy link
Copy Markdown
Contributor

@st0012 when Dependabot tried to bump us to Sentry 4.1.0 (from 4.0.1), we started getting constant loading errors:

NameError: uninitialized constant Sentry::Rack::CaptureException
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in `block in load_missing_constant'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/active_support.rb:9:in `without_bootsnap_cache'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/active_support.rb:80:in `rescue in load_missing_constant'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/active_support.rb:59:in `load_missing_constant'
./vendor/bundle/ruby/2.7.0/gems/sentry-rails-4.0.0/lib/sentry/rails/capture_exception.rb:3:in `<module:Rails>'
./vendor/bundle/ruby/2.7.0/gems/sentry-rails-4.0.0/lib/sentry/rails/capture_exception.rb:2:in `<module:Sentry>'
./vendor/bundle/ruby/2.7.0/gems/sentry-rails-4.0.0/lib/sentry/rails/capture_exception.rb:1:in `<main>'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
./vendor/bundle/ruby/2.7.0/gems/sentry-rails-4.0.0/lib/sentry/rails/railtie.rb:2:in `<main>'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
./vendor/bundle/ruby/2.7.0/gems/sentry-rails-4.0.0/lib/sentry/rails.rb:3:in `<main>'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
./vendor/bundle/ruby/2.7.0/gems/sentry-rails-4.0.0/lib/sentry-rails.rb:2:in `<main>'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
./vendor/bundle/ruby/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
./config/application.rb:22:in `<top (required)>'
./Rakefile:6:in `require_relative'
./Rakefile:6:in `<top (required)>'
./vendor/bundle/ruby/2.7.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'

I wonder if there is a load order issue here that needs to be resolved with an explicit require 'sentry/rack/capture_exceptions in Sentry::Rails::CaptureExceptions.

@st0012
Copy link
Copy Markdown
Contributor Author

st0012 commented Dec 18, 2020

@agrobbin it's because your sentry-rails is still on 4.0.0. I think you can solve this by upgrading sentry-rails to 4.1.0.

@agrobbin
Copy link
Copy Markdown
Contributor

Ohhhh! The downside of Dependabot only upgrading 1 dependency at a time. Sorry for the noise!

@st0012
Copy link
Copy Markdown
Contributor Author

st0012 commented Dec 18, 2020

@agrobbin no worries, glad to help 😄

@agrobbin
Copy link
Copy Markdown
Contributor

agrobbin commented Dec 18, 2020

I wonder, does this indicate that the gemspec dependencies of sentry-rails and sentry-sidekiq are too loose? If the gems are going to be more in lockstep with one another, maybe the version constraint should be ~> 4.1.0 instead of >= 4.1.0 (or, even more restrictive, = 4.1.0).

@st0012
Copy link
Copy Markdown
Contributor Author

st0012 commented Dec 18, 2020

that's a good point, let me see if I can patch a release for that 👍

@st0012
Copy link
Copy Markdown
Contributor Author

st0012 commented Dec 18, 2020

I've added a PR for this #1159. I'll wait until next week for the 4.1.1 to see if there are other fixes I can ship along with.

@agrobbin
Copy link
Copy Markdown
Contributor

@st0012 awesome! Actually, there might be another small bug. I haven't had a chance to dig into it too much yet, but even after updating sentry-rails (and sentry-sidekiq), we are getting exceptions in CI, and based on the stack trace, I wonder if it's actually also related to this PR:

     NoMethodError:
       undefined method `event_id' for false:FalseClass
     Shared Example Group: "an unauthorized response" called from ./spec/requests/webhooks/slack_spec.rb:390
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/sentry-ruby-4.1.0/lib/sentry/hub.rb:113:in `capture_event'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/sentry-ruby-4.1.0/lib/sentry/hub.rb:85:in `capture_exception'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/sentry-ruby-4.1.0/lib/sentry-ruby.rb:119:in `capture_exception'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/sentry-ruby-4.1.0/lib/sentry/rack/capture_exceptions.rb:28:in `rescue in block in call'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/sentry-ruby-4.1.0/lib/sentry/rack/capture_exceptions.rb:22:in `block in call'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/sentry-ruby-4.1.0/lib/sentry/hub.rb:50:in `with_scope'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/sentry-ruby-4.1.0/lib/sentry-ruby.rb:103:in `with_scope'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/sentry-ruby-4.1.0/lib/sentry/rack/capture_exceptions.rb:14:in `call'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-cors-1.1.1/lib/rack/cors.rb:100:in `call'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/railties-6.0.3.4/lib/rails/engine.rb:527:in `call'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-test-1.1.0/lib/rack/mock_session.rb:29:in `request'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-test-1.1.0/lib/rack/test.rb:266:in `process_request'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/rack-test-1.1.0/lib/rack/test.rb:119:in `request'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.4/lib/action_dispatch/testing/integration.rb:270:in `process'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.4/lib/action_dispatch/testing/integration.rb:24:in `post'
     # /usr/local/var/rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/actionpack-6.0.3.4/lib/action_dispatch/testing/integration.rb:359:in `block (2 levels) in <module:Runner>'

Sorry for occupying your entire morning!

st0012 added a commit that referenced this pull request Dec 18, 2020
Here's a full description on the issue
#1147 (comment)
@st0012
Copy link
Copy Markdown
Contributor Author

st0012 commented Dec 18, 2020

@agrobbin thank you so much (and sorry) that you caught this bug 🙇 I've addressed it in #1161

st0012 added a commit that referenced this pull request Dec 18, 2020
@agrobbin
Copy link
Copy Markdown
Contributor

No worries, thanks @st0012!

@dentarg
Copy link
Copy Markdown
Contributor

dentarg commented Dec 21, 2020

@st0012 is the new Sentry Ruby SDK not following SemVer?

@st0012
Copy link
Copy Markdown
Contributor Author

st0012 commented Dec 21, 2020

@dentarg sorry that this change broke the semver spec, but this one was quite tough to call.

let me explain it a bit: there's a bug (#1153) that requires this breaking change. but given that we've just released v4, bumping it to v5 right away without any major functional changes seems to be more confusing. and the other consideration is that if the users also use sentry-rails (which are the majority of our users), he/she won't need to perform this change manually. these are why I decided not to bump it to 5.0.

but I also know that the migration is not smooth and can be disappointing to some people, like @agrobbin's report above (sorry 😢). so I added #1159 #1160 with the hope to improve this and future upgrade's experience. and we'll be working harder to avoid similar situations from happening again.

so my answer is: we'll try to follow it as closely as possible, and I'm sorry for breaking it this time. such issues should happen less and less after the new SDK is becoming more stable (which will be soon, I promise).

@dentarg
Copy link
Copy Markdown
Contributor

dentarg commented Dec 21, 2020

@st0012 thanks for trying to explain but I have a hard time understanding a decision like the above if one has any intention to respect SemVer. Not wanting to release a new major version without new major features sounds to me like marketing. I can understand that as reason, but it doesn't squash with SemVer – I think you should be honest about that.

I don't think it is confusing to release a new major version when there's breaking changes, people will read the changelog and understand what's happening. Encountering breaking changes when not updating the major version, that's confusing (unless you know the gem doesn't respect SemVer, then you are more careful).

I understand (hope) that you wont reason the same when sentry-ruby has been out for longer, and you probably thought you could get away with this as many users haven't switched yet.

I'll connect this PR with the documentation updates getsentry/sentry-docs#2791 that shows what changed with 4.1.0.

Sentry.clone_hub_to_current_thread

Sentry.with_scope do |scope|
scope.clear_breadcrumbs
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this still needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@matthieuprat it's a way to make sure the request scope doesn't contain any pre-existed data. of course, it can be improved. does this approach cause any issue in your app?

Copy link
Copy Markdown

@matthieuprat matthieuprat Nov 4, 2021

Choose a reason for hiding this comment

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

My apologies, I should have provided more context with my question in the first place!

It doesn't cause any issues on our side. I was asking merely because we drew inspiration from that middleware to track errors in our custom job runner and we weren't sure whether this particular line was relevant to us. I also thought that maybe this PR actually made it unnecessary because the clone_hub_to_current_thread method was now being called for every request.

In fact, my understanding from your answer is that we do need it, otherwise, the breadcrumbs could include data from before the main hub was cloned for the first time.

Out of curiosity, why aren't we doing the same thing in the ActiveJob integration?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@matthieuprat sorry for the delay. it's because I didn't see the same breadcrumb data slipped into AJ events. I didn't dig into the reason though so I may be wrong.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No worries! OK, makes sense. (I haven't tested the AJ integration myself so can't tell whether this is an actual issue.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants