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

sentry-rails dependency on rails is too big #1362

Closed
nirvdrum opened this issue Mar 24, 2021 · 11 comments
Closed

sentry-rails dependency on rails is too big #1362

nirvdrum opened this issue Mar 24, 2021 · 11 comments

Comments

@nirvdrum
Copy link

Describe the bug

The sentry-rails gem has a dependency on rails itself. This forces loading the entirety of Rails, which is unnecessary in many applications (e.g., API mode). The immediate issue is it's forcing the loading of Active Storage, which is in the middle of dealing with a major licensing issue. Since we're not using Active Storage, we could avoid the licensing issue by not loading it in the first place, but sentry-rails is forcing it.

I'd suggest only depending on the parts that sentry-rails actually needs to load itself. I think you could go a step further and remove the dependency entirely. If someone is adding sentry-rails to a non-Rails application, a runtime exception due to not being able to load a Rails class ought to be sufficient. I don't think this needs to be enforced by the gemspec.

To Reproduce

Add sentry-rails to a Rails API-only project and only load the components you need. E.g.,

RAILS_VERSION = '6.1.3'

gem 'actioncable', RAILS_VERSION
gem 'actionpack', RAILS_VERSION
gem 'actionview', RAILS_VERSION
gem 'activemodel', RAILS_VERSION
gem 'activerecord', RAILS_VERSION
gem 'activesupport', RAILS_VERSION
gem 'railties', RAILS_VERSION

Expected behavior

I'd expect only the Rails dependencies I've specified have been loaded.

Actual behavior

sentry-rails forces a dependency on every component of Rails.

Environment

  • Ruby Version: 2.7.2p137
  • SDK Version: 4.2.2
  • Integration Versions (if any):
  • e.g. Rails 6.0, Sidekiq 6.1.2

Raven Config

This is not necessary but could be helpful.

Raven.configure do |config|
  # the config you're using, without DSN and other sensitive data
end
@st0012
Copy link
Collaborator

st0012 commented Mar 24, 2021

it's on the way 🙂 #1352

@nirvdrum
Copy link
Author

@st0012 Thanks. I looked quickly, but missed that issue and PR. Great to hear. This is an immediate problem due to the mimemagic/activestorage licensing issue I mentioned in the issue body.

@jlrosenberg
Copy link

Curious what the timeline on this is? Is there any chance that this could be released today? Right now we can either remove sentry-rails and our sentry reporting from our application, or we can't release due the mimemagic/activestorage issue.

@mediafinger
Copy link

mediafinger commented Mar 24, 2021

I am here for the same reason. While trying to work around the mimemagic yanking mess, I was about to replace in our app' Gemfile:

gem "rails", "~> 6.0.3"

with

rails_version = "6.0.3"
gem "actionpack", "~> #{rails_version}"
gem "activejob", "~> #{rails_version}"
gem "activemodel", "~> #{rails_version}"
gem "activerecord", "~> #{rails_version}"
gem "railties", "~> #{rails_version}"

only to then realize that sentry-rails is depending on the entirety of rails. It is great to see you are working already on a solution.

My intuition tells me you could just replace the rails dependency with actionpack, but looking at the open PR, you want to take it even one step further.

@nirvdrum
Copy link
Author

nirvdrum commented Mar 24, 2021

I reviewed @st0012's PR, which looked good to me, and then linked in his branch with:

gem "sentry-rails", git: "https://github.com/getsentry/sentry-ruby.git", branch: "minimize-sentry-rails-requirement", glob: "sentry-rails/*.gemspec"

It's not a fantastic solution, but it let me move on with my day.

@st0012
Copy link
Collaborator

st0012 commented Mar 25, 2021

@nirvdrum did you find any issue when using it? I didn't release it right away because I was (and still am) worrying about if there's any issue it introduces.

@nirvdrum
Copy link
Author

@st0012 So far, so good. I haven't tested extensively though. The Rails app booted and our extensive test suite passed. I need to induce some errors and see if the reporting still works.

@st0012
Copy link
Collaborator

st0012 commented Mar 25, 2021

fyi it's now on the master branch now. I'll make a pre-release version today and keep you notified here.

@st0012
Copy link
Collaborator

st0012 commented Mar 25, 2021

sentry-rails 4.3.3.pre.beta.0 has been released. please give it a try and provide some feedback (like does it work at all?), so I can make it an official release as soon as possible 🙂

Cruikshanks added a commit to DEFRA/sroc-tcm-admin that referenced this issue Mar 25, 2021
First, scan [Dependency on mimemagic 0.3.x no longer valid](rails/rails#41750) for context!

In summary, **rails** depends on **activestorage** which depends on **marcel** which depends on **mimemagic**. Yesterday, the author of **mimemagic** was informed it was in violation of the GPL license. So, they chose to

- yank all versions up to and including 0.3.5 from rubygems
- release a new version under the GPL
- archive the project for all further changes/issues/pr's etc

Via the dependency chain Rails relies on **mimemagic 0.3.5** so new installs of Rails are now broken. It also can't just pull in the new version due to the clash with the GPL license.

Efforts are afoot to resolve the issue.

- A [fork of mimemagic](https://github.com/jellybob/mimemagic) which relies on the GPL source data being already installed and read at run time
- Updating **marcel** to use [MiniMime](rails/marcel#25) and [ruby-magic](rails/marcel#26) instead of **mimemagic**

Till the community has settled on a solution though, we need a fix in the short term. Ours is based on

- What the Dept. for Education team have done in [early-careers-framework](DFE-Digital/early-careers-framework#178)
- What Sentry are doing [in their app](getsentry/sentry-ruby#1362)

Instead of referencing `rails` in the `Gemfile` they are referencing just the parts needed and excluding `activestorage` and anything with a dependency on it.

This change does exactly the same thing.
@st0012
Copy link
Collaborator

st0012 commented Mar 26, 2021

hey everyone 👋 since I haven’t seen any issue report for the pre release, I’ll assume it works fine and make a 4.3.3 release today 🙂

@st0012
Copy link
Collaborator

st0012 commented Mar 26, 2021

close because version 4.3.3 has been released

@st0012 st0012 closed this as completed Mar 26, 2021
@st0012 st0012 added this to the sentry-rails-4.3.3 milestone Mar 26, 2021
@st0012 st0012 added this to To do in 4.x via automation Mar 26, 2021
Cruikshanks added a commit to DEFRA/sroc-tcm-admin that referenced this issue Mar 26, 2021
First, scan [Dependency on mimemagic 0.3.x no longer valid](rails/rails#41750) for context!

In summary, **Rails** depends on **activestorage** which depends on **marcel** which depends on **mimemagic**. Yesterday, the author of **mimemagic** was informed it was in violation of the [GPL license](https://choosealicense.com/licenses/gpl-3.0/). So, they chose to

- yank all versions up to and including 0.3.5 from rubygems
- release a new version under the GPL
- archive the project for all further changes/issues/pr's etc

Via the dependency chain **Rails** relies on **mimemagic 0.3.5** so new installs of **Rails** are now broken. It also can't just pull in the new version due to the clash with the GPL license.

Efforts are afoot to resolve the issue.

- A [fork of mimemagic](https://github.com/jellybob/mimemagic) which relies on the GPL source data being already installed and read at run time
- Updating **marcel** to use [MiniMime](rails/marcel#25) and [ruby-magic](rails/marcel#26) instead of **mimemagic**

Till the community has settled on a solution though, we need a fix in the short term. Ours is based on

- What the Dept. for Education team have done in [early-careers-framework](DFE-Digital/early-careers-framework#178)
- What Sentry are doing [in their app](getsentry/sentry-ruby#1362)

Instead of referencing `rails` in the `Gemfile` they are referencing just the parts needed and excluding `activestorage` and anything with a dependency on it.

This change does exactly the same thing.
@st0012 st0012 moved this from To do to Done in 4.x Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4.x
  
Done
Development

No branches or pull requests

4 participants