From ffffce9a70adca5249db19530e1f41aa60f6218c Mon Sep 17 00:00:00 2001 From: Shinnosuke Iwaide <33276384+Iwaide@users.noreply.github.com> Date: Wed, 20 Mar 2024 23:14:14 +0900 Subject: [PATCH] Fix: Get connection from connection_pool instead of ActiveRecord::Base.connection (#2278) --- CHANGELOG.md | 6 ++++++ .../lib/sentry/rails/tracing/active_record_subscriber.rb | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a68fd45c5..ece53ce61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased + +### Bug Fixes + +- Don't instantiate connection in `ActiveRecordSubscriber` ([#2278](https://github.com/getsentry/sentry-ruby/pull/2278)) + ## 5.17.1 ### Bug Fixes diff --git a/sentry-rails/lib/sentry/rails/tracing/active_record_subscriber.rb b/sentry-rails/lib/sentry/rails/tracing/active_record_subscriber.rb index 3eeff2db6..ab25273a9 100644 --- a/sentry-rails/lib/sentry/rails/tracing/active_record_subscriber.rb +++ b/sentry-rails/lib/sentry/rails/tracing/active_record_subscriber.rb @@ -21,8 +21,7 @@ def self.subscribe! span.set_data(:connection_id, payload[:connection_id]) # we fallback to the base connection on rails < 6.0.0 since the payload doesn't have it - base_connection = ActiveRecord::Base.connection - connection ||= base_connection if payload[:connection_id] == base_connection.object_id + connection ||= ActiveRecord::Base.connection_pool.connections.find { |conn| conn.object_id == payload[:connection_id] } end next unless connection