-
-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add query source support to sentry-rails
#2313
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2313 +/- ##
=======================================
Coverage 98.66% 98.66%
=======================================
Files 205 205
Lines 13339 13422 +83
=======================================
+ Hits 13161 13243 +82
- Misses 178 179 +1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this!
We also have an option called db_query_source_threshold_ms
that defaults to 100ms and the source is recorded on the span only if it takes more than that threshold.
Could you also add that?
This change mimics Rails' ActiveRecord::LogSubscriber to extract the source of the query and add it to the span data. The added source information can then be displayed along with the query SQL in the Sentry UI. The feature only works with Ruby 3.2+ and Rails 7.1+.
…shold_ms This avoids the overhead of recording the source in fast queries, which in general don't need to be traced. The threshold is configurable via `config.rails.db_query_source_threshold_ms` and the default is 100ms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ty <3
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.