This PR adds query source information to the tracing spans captured by sentry-rails's ActiveSupportSubscriber, which should be picked up by Sentry and displayed like:
There are several requirements for this feature to work:
Ruby 3.2+ because we need Thread.each_caller_location to minimise the performance impact
Rails 7.1+ because we need ActiveSupport::BacktraceCleaner#clean_frame
config.rails.enable_db_query_source is set to true (default)
sentry-rails's ActiveRecordSubscriber is included in the config.rails.tracing_subscribers list (default)
And to reduce the feature's overhead, only queries that exceed config.rails.db_query_source_threshold_ms will have source recorded, which is set to 100ms by default.
Closes #2242
This PR adds query source information to the tracing spans captured by
sentry-rails
'sActiveSupportSubscriber
, which should be picked up by Sentry and displayed like:The implementation is inspired by Rails'
ActiveRecord::LogSubscriber
but doesn't depend on it.There are several requirements for this feature to work:
Thread.each_caller_location
to minimise the performance impactActiveSupport::BacktraceCleaner#clean_frame
config.rails.enable_db_query_source
is set totrue
(default)sentry-rails
'sActiveRecordSubscriber
is included in theconfig.rails.tracing_subscribers
list (default)And to reduce the feature's overhead, only queries that exceed
config.rails.db_query_source_threshold_ms
will have source recorded, which is set to 100ms by default.