-
Notifications
You must be signed in to change notification settings - Fork 133
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
Update ElasticAPM::SpanHelpers to use ruby2_keywords for argument delegation #1294
Update ElasticAPM::SpanHelpers to use ruby2_keywords for argument delegation #1294
Conversation
Wow, this looks like a great contribution, thank you for the PR! I will make sure CI passes (just the docs left) and review it more thoroughly and then it'll be merged in straight away. |
run elasticsearch-ci/docs |
/test |
Hi folks, can you rebase this on the |
6c5fa56
to
9820f7a
Compare
Sure. I just rebased our branch onto the current elastic:main branch. |
Hi @danarnold, I'm not so familiar with this gem. You're saying that it's included as a core gem for ruby versions 2.7 and higher? |
9820f7a
to
b84bf9e
Compare
Yep, it shouldn't be necessary to specify the gem for versions 2.7 and higher. The ruby post I linked above states this.
You're right, I included ruby2_keywords in the Gemfile instead of the gemspec. I just pushed an updated commit adding ruby2_keywords to the gemspec so we can ensure it's present. |
Hey @danarnold I'd like to avoid adding more gem dependencies, if possible. |
@estolfo I had already searched for a way to limit the dependencies in the gemspec to a specific version of ruby, but I didn't find any, unfortunately. I understand being hesitant to add a new gem dependency. You may find it comforting to see just how minimal of a dependency this gem is: its purpose is really just to enable underlying support inside the ruby language by defining blank wrapper methods (see the source code here). Additionally, the gem isn't from some third party that would have to be relied on for continuing support; this is a gem owned and published by the core ruby language team, and is therefore as solid of a dependency as you can get. As I've alluded to previously, this gem is extremely common as a dependency for many other gems. The compatibility changes introduced with ruby 2.7 and ruby 3 have widespread effects, and many projects have had to make similar changes to ensure that their code doesn't break. The only option to avoid the gem dependency would be to include the code that defines the wrapper methods directly in this gem's source code. Then the code could be wrapped in a conditional which would prevent it from being defined when it isn't necessary. To be honest, though, I can't see how this would be the more elegant solution. It seems to me to be a messier solution than just including the ruby2_keywords gem as a dependency. Regarding your JRuby question: I don't personally have any experience with JRuby. A quick look at the JRuby homepage shows me that the latest release of JRuby, 9.3.8.0, is targeted at compatibility with ruby 2.6.x. Therefore, I don't think these changes would be relevant to JRuby just yet, nor would I expect them to cause any issues with JRuby, since ruby2_keywords is a backwards compatible change for C ruby 2.6.x and previous. I can't speak to the JRuby development team's intentions regarding future versions of JRuby, but it seems that if their goal is compatibility with a given version of C ruby, then I don't see any reason to suspect that they would deviate from that path and create an incompatibility around the argument delegation changes introduced in ruby 2.7 and ruby 3. For current versions of JRuby, running the additional unit test I wrote under JRuby should make it pretty easy to check and confirm that the code is compatible. |
Hi @danarnold thank you for the detailed response and explanation. |
…egation compatibility with ruby >=3.0. add dependency on ruby2_keywords gem for ruby <2.7 compatibility.
b84bf9e
to
d08e1e7
Compare
@estolfo Sure thing. I've just done that. The tests look good on my end. |
🌐 Coverage report
|
/test |
@elasticmachine, run elasticsearch-ci/docs |
Thanks, @danarnold ! |
…egation compatibility with ruby >=3.0. add dependency on ruby2_keywords gem for ruby <2.7 compatibility. (#1294)
What does this pull request do?
This code updates ElasticAPM::SpanHelpers to use ruby2_keywords to properly delegate method arguments in a way that's compatible with all supported versions of ruby.
The included test will raise an ArgumentError in ruby >=3 without these changes.
I've also added the ruby2_keywords gem to the Gemfile for ruby versions <2.7, as the method is not included in those older versions of ruby. The gem is already pulled in by multiple other gems that depend on it, so this isn't effectively adding anything, it's just making it explicit since this project now explicitly depends on it.
Why is it important?
ElasticAPM::SpanHelpers was previously broken with ruby >=3.0 because it uses the legacy format of delegating arguments. In ruby 3, if a method has a mixture of keyword arguments and positional arguments, any methods spanned would raise an ArgumentError. See here and here for more details. Switching to the new argument delegation format in ruby 3, which would be
(*args, **kwargs, &block)
instead of(*args, &block)
, would also fix the issue, but that wouldn't be backwards compatible with ruby versions before 3.0.Checklist
.rubocop.yml
)I have made corresponding changes to the documentationI have updated CHANGELOG.asciidocI have updated supported-technologies.asciidocAdded an API method or config option? Document in which version this will be introduced