forked from appsignal/appsignal-ruby
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forward keyword arguments on Ruby 2.7 and 3.0 (appsignal#693)
Cherry-picked appsignal#692 on main branch. Update Object instrumentation for Ruby 2.7 and 3.0 so that it doesn't print deprecation warnings on Ruby 2.7 and raises an error on Ruby 3.0. It didn't look broken because we didn't actually test argument forwarding so the tests didn't break for Ruby 3.0. I had to implement it twice, once for Ruby 2.7 and higher, and once for everything older. This is because the two instrumentation methods are incompatible and this is the easiest way to instrument all versions. This means two implementation files and two tests because Ruby 1.9 can't parse the keyword argument syntax introduced in Ruby 2.0. This is an ugly fix, but it's also present for a very short time, since our develop branch already drops support for Ruby 1.9 and we can remove this workaround when this gets merged into the develop branch. I justed wanted to get this merged into the main branch so we can fully support Ruby 3.0 in the Ruby gem 2.x series, rather than only fully support it in the Ruby gem 3.x series. This change should make our Ruby 3.0 support complete. Fixes appsignal#656
Showing
8 changed files
with
413 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
class Object | ||
def self.appsignal_instrument_class_method(method_name, options = {}) | ||
singleton_class.send \ | ||
:alias_method, "appsignal_uninstrumented_#{method_name}", method_name | ||
singleton_class.send(:define_method, method_name) do |*args, &block| | ||
name = options.fetch(:name) do | ||
"#{method_name}.class_method.#{appsignal_reverse_class_name}.other" | ||
end | ||
Appsignal.instrument name do | ||
send "appsignal_uninstrumented_#{method_name}", *args, &block | ||
end | ||
end | ||
end | ||
|
||
def self.appsignal_instrument_method(method_name, options = {}) | ||
alias_method "appsignal_uninstrumented_#{method_name}", method_name | ||
define_method method_name do |*args, &block| | ||
name = options.fetch(:name) do | ||
"#{method_name}.#{appsignal_reverse_class_name}.other" | ||
end | ||
Appsignal.instrument name do | ||
send "appsignal_uninstrumented_#{method_name}", *args, &block | ||
end | ||
end | ||
end | ||
|
||
def self.appsignal_reverse_class_name | ||
return "AnonymousClass" unless name | ||
name.split("::").reverse.join(".") | ||
end | ||
|
||
def appsignal_reverse_class_name | ||
self.class.appsignal_reverse_class_name | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# frozen_string_literal: true | ||
|
||
class Object | ||
if Appsignal::System.ruby_2_7_or_newer? | ||
def self.appsignal_instrument_class_method(method_name, options = {}) | ||
singleton_class.send \ | ||
:alias_method, "appsignal_uninstrumented_#{method_name}", method_name | ||
singleton_class.send(:define_method, method_name) do |*args, **kwargs, &block| | ||
name = options.fetch(:name) do | ||
"#{method_name}.class_method.#{appsignal_reverse_class_name}.other" | ||
end | ||
Appsignal.instrument name do | ||
send "appsignal_uninstrumented_#{method_name}", *args, **kwargs, &block | ||
end | ||
end | ||
end | ||
|
||
def self.appsignal_instrument_method(method_name, options = {}) | ||
alias_method "appsignal_uninstrumented_#{method_name}", method_name | ||
define_method method_name do |*args, **kwargs, &block| | ||
name = options.fetch(:name) do | ||
"#{method_name}.#{appsignal_reverse_class_name}.other" | ||
end | ||
Appsignal.instrument name do | ||
send "appsignal_uninstrumented_#{method_name}", *args, **kwargs, &block | ||
end | ||
end | ||
end | ||
else | ||
def self.appsignal_instrument_class_method(method_name, options = {}) | ||
singleton_class.send \ | ||
:alias_method, "appsignal_uninstrumented_#{method_name}", method_name | ||
singleton_class.send(:define_method, method_name) do |*args, &block| | ||
name = options.fetch(:name) do | ||
"#{method_name}.class_method.#{appsignal_reverse_class_name}.other" | ||
end | ||
Appsignal.instrument name do | ||
send "appsignal_uninstrumented_#{method_name}", *args, &block | ||
end | ||
end | ||
end | ||
|
||
def self.appsignal_instrument_method(method_name, options = {}) | ||
alias_method "appsignal_uninstrumented_#{method_name}", method_name | ||
define_method method_name do |*args, &block| | ||
name = options.fetch(:name) do | ||
"#{method_name}.#{appsignal_reverse_class_name}.other" | ||
end | ||
Appsignal.instrument name do | ||
send "appsignal_uninstrumented_#{method_name}", *args, &block | ||
end | ||
end | ||
end | ||
end | ||
|
||
def self.appsignal_reverse_class_name | ||
return "AnonymousClass" unless name | ||
name.split("::").reverse.join(".") | ||
end | ||
|
||
def appsignal_reverse_class_name | ||
self.class.appsignal_reverse_class_name | ||
end | ||
end |
This file contains 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
Oops, something went wrong.