Skip to content
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

fix: instrumentation/active_record: add :allow_retry option to find_by_sql patch #915

Conversation

andrewn617
Copy link
Contributor

@andrewn617 andrewn617 commented Mar 26, 2024

Rails 7.2 (rails/rails@eabcff2) introduces the :allow_retry option for the find_by_sql method, so we need to add it to this patch to maintain compatibility. The patch doesn't use the method's args, so we can just use (...) to avoid this problem.

To check the Rails version, I had to add rails as a development dependency. I added it in the gemspec and set the minimum version to 6.1 following the pattern I saw in the other libraries in this repo (for example).

Copy link

linux-foundation-easycla bot commented Mar 26, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: andrewn617 / name: Andrew Novoselac (8869502)
  • ✅ login: kaylareopelle / name: Kayla Reopelle (she/her) (0070364)
  • ✅ login: arielvalentin / name: Ariel Valentin (f9aef75)

@andrewn617 andrewn617 force-pushed the fix-find-by-sql-patch-for-rails-7.2 branch 2 times, most recently from 0a3ac84 to 4d79b29 Compare March 26, 2024 21:17
@dmathieu
Copy link
Member

Do we need the condition?
If we provide the new option no matter the rails version, and someone is using a version lower than 7.2, super will fail just as it would if the instrumentation wasn't there.

@arielvalentin
Copy link
Collaborator

Do we need the condition?

If we provide the new option no matter the rails version, and someone is using a version lower than 7.2, super will fail just as it would if the instrumentation wasn't there.

I think we do. We must honor the monkey patched class method signatures.

Without that condition, the side effect will be changing the public API to add an option that does not exist. Though it will be backward compatible it will confuse end users and if they disable the instrumentation it will break their application.

I am not keen on the if statements and would probably prefer mixing in separate modules depending on the gem versions but I'd like the original author @robertlaurin to weigh in on that.

@andrewn617 andrewn617 force-pushed the fix-find-by-sql-patch-for-rails-7.2 branch from 4d79b29 to a35e2cb Compare March 27, 2024 13:52
…_sql patch

Rails 7.2 (rails/rails@eabcff2) introduces the :allow_retry option for this method, so we need to add it to this patch to maintain compatibility.
@andrewn617 andrewn617 force-pushed the fix-find-by-sql-patch-for-rails-7.2 branch from a35e2cb to 8869502 Compare March 27, 2024 13:52
@arielvalentin arielvalentin changed the title instrumentation/active_record: add :allow_retry option to find_by_sql patch fix: instrumentation/active_record: add :allow_retry option to find_by_sql patch Mar 27, 2024
@@ -18,7 +18,7 @@ class << base

# Contains ActiveRecord::Querying to be patched
module ClassMethods
def find_by_sql(sql, binds = [], preparable: nil, &block)
def find_by_sql(...)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other methods here that need the same treatment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it does not look like it.

Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @andrewn617! Are there existing tests that cover this change?

@andrewn617
Copy link
Contributor Author

Thank you, @andrewn617! Are there existing tests that cover this change?

@kaylareopelle I think now that we are just using (...) there is nothing to test, since it is just ruby functionality to forward all the args to when calling super.

@arielvalentin
Copy link
Collaborator

@andrewn617 I did miss @kaylareopelle comment about adding code coverage.

Would you kindly add a test that uses allow_retry as a parameter to ensure we do not introduce a regression in the future?

@arielvalentin
Copy link
Collaborator

arielvalentin commented Apr 2, 2024

hmmm actually this is edge rails so we cannot really test this at the moment.

@arielvalentin arielvalentin merged commit eabc134 into open-telemetry:main Apr 2, 2024
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants