shrinerb / shrine

File Attachment toolkit for Ruby applications

Home Page:https://shrinerb.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot disable logging without ActiveSupport

musaffa opened this issue · comments

Brief Description

The ruby projects I work don't depend on ActiveSupport. When I try to disable logging with Shrine.plugin :instrumentation, log_subscriber: nil, it raises an error for missing ActiveSupport constant.

Expected behavior

Disabling Shrine instrumentation should work without ActiveSupport

System configuration

Ruby version: 3.1.2

Shrine version: 3.4.0

Thanks for the report!

If it was convenient for you to include the exact error message and stack trace that's printed out, that would be helpful!

The relevant part of the error message and stack trace:

lib/shrine/plugins/instrumentation.rb:15:in `configure': uninitialized constant ActiveSupport (NameError)

   uploader.opts[:instrumentation][:notifications] ||= ::ActiveSupport::Notifications

Setting log_subscriber to nil doesn't disable instrumentation, it only disables the subscriber that listens on events and prints them out. The instrumentation is useful in itself, because it allows other code to hook into those events, which is useful for monitoring tools such as Skylight.

If you wanted to disable instrumentation, you should not load the instrumentation plugin. Or you can use dry-monitor instead of Active Support.

What would be the best way to get just the logging provided by the instrumentation plugin, but without an instrumentation subscriber?

It was trying to disable logging in test. I know it's possible to load test environment without the instrumentation plugin.

I wonder whether ActiveSupport::Notification as the default notification provider can be removed. Users can be required provide their preferred notification provider, be it's dry-monitor or Active Support. But this will be a breaking change.

Even though it's an implicit dependency, it's also the only Rails related dependency in Rails independent Shrine plugins. So I thought it would be really nice if this dependency could be removed.

What would be the best way to get just the logging provided by the instrumentation plugin, but without an instrumentation subscriber?

You can't currently, the log subscriber receives an event object, which comes from ActiveSupport/dry-monitor, so logging depends on instrumentation. So far, nobody requested logging to be decoupled from instrumentation.

I wonder whether ActiveSupport::Notification as the default notification provider can be removed. Users can be required provide their preferred notification provider, be it's dry-monitor or Active Support. But this will be a breaking change.

Even though it's an implicit dependency, it's also the only Rails related dependency in Rails independent Shrine plugins. So I thought it would be really nice if this dependency could be removed.

It was a conscious decision to default to Active Support, given that most applications are Rails applications, and some non-Rails applications use Active Support. For these applications, I wanted the convenience of not having to specify the notifications provider.

What we can do is improve the error message when Active Support is not installed, as a missing ActiveSupport constant error is not the most user-friendly. If you agree, I would gladly accept a PR for this.

I'm a little busy at this moment. When I become free, I'll submit a PR. Please keep this issue open.