-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Support :source_location
tag option for query log tags
#50969
Conversation
end | ||
else | ||
def query_source_location # :nodoc: | ||
LogSubscriber.backtrace_cleaner.clean(caller(1).lazy).first |
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.
I don't think this lazy
make much sense. Might as well explicitly do caller_location(1).each
.
if Thread.respond_to?(:each_caller_location) | ||
def query_source_location # :nodoc: | ||
Thread.each_caller_location do |location| | ||
frame = LogSubscriber.backtrace_cleaner.clean_frame(location) |
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.
frame = LogSubscriber.backtrace_cleaner.clean_frame(location) | |
frame = LogSubscriber.backtrace_cleaner.clean_frame(location.path) |
Might as well pass only the path, no?
@@ -71,7 +72,10 @@ module ActiveRecord | |||
# | |||
# config.active_record.cache_query_log_tags = true | |||
module QueryLogs | |||
mattr_accessor :taggings, instance_accessor: false, default: {} | |||
mattr_accessor :taggings, instance_accessor: false, default: { | |||
line: -> { query_source_location } |
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.
This should be set in activerecord/railtie.rb
like the others, otherwise it risks being overidden by users.
500ba3f
to
74596c5
Compare
Updated, please take a look. |
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.
Looks OK now, but there is a surprising amount of tests failures. I suspect they're not related but might be worth trying a rebase?
@@ -26,6 +26,7 @@ module ActiveRecord | |||
# * +socket+ | |||
# * +db_host+ | |||
# * +database+ | |||
# * +line+ |
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.
Also I wonder if line
really makes sense as a name, as it's not just the line, but the whole location. Maybe location
or source_location
?
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.
I named it after the marginalia's :line
, but yeah, changed it to :source_location
.
CI is still red, but looks like is not related to this PR.
74596c5
to
a87668a
Compare
:line
tag option for query log tags:source_location
tag option for query log tags
It's weird because main is green, and you got the same failures after your rebase. I'll try to check if main is hosed. |
Yeah, similar failures on other PRs... |
Follow up to #42240 (as discussed in #42240 (comment)).
We lost the ability to use the
:line
option with QueryLogs (#42240 (comment)), while there is one in the marginalia. It was costly to use it before in the gem, but we made it fast (basecamp/marginalia#138), so it is not that costly and people deliberately decide if they want to use it.I would like to have the
:line
option (upd: decided to name it as:source_location
), it is very much useful. Without it, if we have a slow db query log, for example, it is very hard to know from which part of the codebase the query was generated. Even having an:action
component, you need to investigate the unfamiliar codebase to find out where the query was triggered.cc @byroot