-
Notifications
You must be signed in to change notification settings - Fork 226
fix!: activerecord find_by_sql spans on Rails 7.0+ #1184
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
Merged
kaylareopelle
merged 9 commits into
open-telemetry:main
from
mrsimo:instrumentation-activerecord-find-by-sql
Oct 22, 2024
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b6e0d2f
fix: activerecord find_by_sql spans on Rails 7.0+
mrsimo fbce9bc
tests: fix create_table call
mrsimo beff0cb
tests: rubocop tweak
mrsimo 18c3d5a
Merge branch 'main' into instrumentation-activerecord-find-by-sql
arielvalentin 73b1f82
feat: call spans that produce reads `query`
mrsimo 049c179
Merge branch 'main' into instrumentation-activerecord-find-by-sql
mrsimo 1f30c80
Refactor patching to use define_method
mrsimo f45ab3c
Merge branch 'main' into instrumentation-activerecord-find-by-sql
mrsimo f5aad40
Merge branch 'main' into instrumentation-activerecord-find-by-sql
kaylareopelle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
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 get what you're saying about the naming! If we change the name of the span, we should consider marking this update as a breaking change since all 7.0 spans would now have a new name.
I like your suggestion of
queryfor 7.0+ spans since they don't roll up tofind_by_sql.Unfortunately, instrumentation often has to resort to private methods to get the data users want, so
_query_by_sqlprobably wouldn't be too much of a shock and perhaps easier for a user to connect the dots.I'd love to hear other opinions!
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 feel like
query(or similar) would be the most stable for the future. Since we're hooking onto internal AR methods, it's possible we might need to change methods, needing a breaking change every time.The downside is that all other spans being generated have the name of the method we're hooking into, so it would be a bit inconsistent. We could make it configurable?
As a user of this instrumentation I'd lean towards something more generic and stable. I usually have the
mysql2ortrilogyspans with details about the exact query that ran, and as a developer I'd need to open the rails code to know what_query_by_sqleven is. Even thefind_by_sqlwas a bit confusing, I didn't know all reads (used to) go through that method.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.
Nice, I'm leaning toward
querynow too!I hesitate to make it configurable. We have some configuration around span naming for ActiveSupport::Notifications in some of our Rails-related instrumentation gems, but in this scenario, since the span is not related to ActiveSupport::Notifications, I think having a single, consistent name would be best.
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 pushed a change to use
queryinstead offind_by_sql. Spans are now calledUser query,Account query, etc. I'm liking it!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.
Great to hear! Would you mind updating the PR title to mark this as a breaking change? I think this'll help anyone who uses
find_by_sqlin their observability backends know to update things accordingly.It can be marked as a breaking change by updating the title to start with
fix!:instead offix:If you don't think this should be a breaking change, let me know and we can discuss it further.
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.
Done! Totally agree that it's a breaking change.