File tree Expand file tree Collapse file tree 2 files changed +14
-21
lines changed
lib/sentry/rails/log_subscribers
spec/sentry/rails/log_subscribers Expand file tree Collapse file tree 2 files changed +14
-21
lines changed Original file line number Diff line number Diff line change @@ -74,18 +74,9 @@ def build_log_message(statement_name)
7474 def extract_db_config ( payload )
7575 connection = payload [ :connection ]
7676
77- if payload [ :connection_id ] && !connection
78- connection = ActiveRecord ::Base . connection_pool . connections . find do |conn |
79- conn . object_id == payload [ :connection_id ]
80- end
81- end
82-
8377 return unless connection
8478
8579 extract_db_config_from_connection ( connection )
86- rescue => e
87- Sentry . configuration . sdk_logger . debug ( "Failed to extract db config: #{ e . message } " )
88- nil
8980 end
9081
9182 def add_db_config_attributes ( attributes , db_config )
Original file line number Diff line number Diff line change 5959 end
6060 end
6161
62- describe "database configuration extraction" do
63- it "includes database configuration in log attributes" do
64- Post . create!
62+ if Rails . version . to_f >= 7.2
63+ describe "database configuration extraction" do
64+ it "includes database configuration in log attributes" do
65+ Post . create!
6566
66- Sentry . get_current_client . flush
67+ Sentry . get_current_client . flush
6768
68- log_event = sentry_logs . find do |log |
69- log [ :body ] &.include? ( "Database query" ) &&
70- log [ :attributes ] &.dig ( :sql , :value ) &.include? ( "INSERT" )
71- end
69+ log_event = sentry_logs . find do |log |
70+ log [ :body ] &.include? ( "Database query" ) &&
71+ log [ :attributes ] &.dig ( :sql , :value ) &.include? ( "INSERT" )
72+ end
7273
73- expect ( log_event ) . not_to be_nil
74+ expect ( log_event ) . not_to be_nil
7475
75- attributes = log_event [ :attributes ]
76- expect ( attributes [ :db_system ] [ :value ] ) . to eq ( "sqlite3" )
77- expect ( attributes [ :db_name ] [ :value ] ) . to eq ( "db" )
76+ attributes = log_event [ :attributes ]
77+ expect ( attributes [ :db_system ] [ :value ] ) . to eq ( "sqlite3" )
78+ expect ( attributes [ :db_name ] [ :value ] ) . to eq ( "db" )
79+ end
7880 end
7981 end
8082
You can’t perform that action at this time.
0 commit comments