Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- Optimize getting query source location in ActiveRecord tracing - this makes tracing up to roughly 40-60% faster depending on the use cases ([#2769](https://github.com/getsentry/sentry-ruby/pull/2769))

### Bug fixes

- Properly skip silenced `ActiveRecord::Base.logger`'s log entries in the ActiveRecord log subscriber ([#2775](https://github.com/getsentry/sentry-ruby/pull/2775))

## 6.1.0

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ActiveRecordSubscriber < Sentry::Rails::LogSubscriber
# @param event [ActiveSupport::Notifications::Event] The SQL event
def sql(event)
return unless Sentry.initialized?
return if logger && !logger.info?
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So, this PR is targeting default which is ERROR, and it should solve the solid_queue silencing being ignored issue. Handling levels is actually a bigger task, because we just default to info right now.

return if EXCLUDED_NAMES.include?(event.payload[:name])

sql = event.payload[:sql]
Expand Down
3 changes: 0 additions & 3 deletions sentry-rails/spec/dummy/test_rails_app/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
require "action_cable/engine"
require "active_storage/engine"

ActiveRecord::Base.logger = Logger.new(nil)

module Sentry
module Rails
module Test
Expand Down Expand Up @@ -83,7 +81,6 @@ def self.load_test_schema
# This can be inherited and extended by subclasses
def configure
config.root = Test::Application.root_path
config.logger = ActiveSupport::Logger.new(nil)
config.active_support.deprecation = :silence
config.hosts = nil
config.secret_key_base = "test 123"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,36 @@
end
end

context "when logger is silenced" do
before do
make_basic_app do |config, app|
config.enable_logs = true

config.rails.structured_logging.enabled = true
config.rails.structured_logging.subscribers = {
active_record: Sentry::Rails::LogSubscribers::ActiveRecordSubscriber
}
end
end

it "does not log silenced logs", if: RAILS_VERSION > 5.2 do
# This makes it log only errors
ActiveRecord::Base.logger.silence { Post.create! }

Post.find(1)

Sentry.get_current_client.flush

expect(
sentry_logs.find { |log| log[:body].include?("Database query: Post Create") }
).to be(nil)

expect(
sentry_logs.find { |log| log[:body].include?("Database query: Post Load") }
).to_not be(nil)
end
end

context "when logging is disabled" do
before do
make_basic_app do |config|
Expand Down
Loading