Add query source support to sentry-rails#2313
Merged
sl0thentr0py merged 4 commits intomasterfrom May 31, 2024
Merged
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
|
sl0thentr0py
requested changes
May 27, 2024
Member
sl0thentr0py
left a comment
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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::LogSubscriberbut doesn't depend on it.There are several requirements for this feature to work:
Thread.each_caller_locationto minimise the performance impactActiveSupport::BacktraceCleaner#clean_frameconfig.rails.enable_db_query_sourceis set totrue(default)sentry-rails'sActiveRecordSubscriberis included in theconfig.rails.tracing_subscriberslist (default)And to reduce the feature's overhead, only queries that exceed
config.rails.db_query_source_threshold_mswill have source recorded, which is set to 100ms by default.