File tree Expand file tree Collapse file tree 3 files changed +31
-3
lines changed
lib/sentry/rails/log_subscribers
dummy/test_rails_app/config
sentry/rails/log_subscribers Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ class ActiveRecordSubscriber < Sentry::Rails::LogSubscriber
3030 # @param event [ActiveSupport::Notifications::Event] The SQL event
3131 def sql ( event )
3232 return unless Sentry . initialized?
33+ return if logger && !logger . info?
3334 return if EXCLUDED_NAMES . include? ( event . payload [ :name ] )
3435
3536 sql = event . payload [ :sql ]
Original file line number Diff line number Diff line change 99require "action_cable/engine"
1010require "active_storage/engine"
1111
12- ActiveRecord ::Base . logger = Logger . new ( nil )
13-
1412module Sentry
1513 module Rails
1614 module Test
@@ -83,7 +81,6 @@ def self.load_test_schema
8381 # This can be inherited and extended by subclasses
8482 def configure
8583 config . root = Test ::Application . root_path
86- config . logger = ActiveSupport ::Logger . new ( nil )
8784 config . active_support . deprecation = :silence
8885 config . hosts = nil
8986 config . secret_key_base = "test 123"
Original file line number Diff line number Diff line change 229229 end
230230 end
231231
232+ context "when logger is silenced" do
233+ before do
234+ make_basic_app do |config , app |
235+ config . enable_logs = true
236+
237+ config . rails . structured_logging . enabled = true
238+ config . rails . structured_logging . subscribers = {
239+ active_record : Sentry ::Rails ::LogSubscribers ::ActiveRecordSubscriber
240+ }
241+ end
242+ end
243+
244+ it "does not log silenced logs" , if : RAILS_VERSION > 5.2 do
245+ # This makes it log only errors
246+ ActiveRecord ::Base . logger . silence { Post . create! }
247+
248+ Post . find ( 1 )
249+
250+ Sentry . get_current_client . flush
251+
252+ expect (
253+ sentry_logs . find { |log | log [ :body ] . include? ( "Database query: Post Create" ) }
254+ ) . to be ( nil )
255+
256+ expect (
257+ sentry_logs . find { |log | log [ :body ] . include? ( "Database query: Post Load" ) }
258+ ) . to_not be ( nil )
259+ end
260+ end
261+
232262 context "when logging is disabled" do
233263 before do
234264 make_basic_app do |config |
You can’t perform that action at this time.
0 commit comments