Tracking a lot of method calls can be cumbersome in complex systems. Imagine repeating over and over the same piece of code for dozens of classes and methods.
# models/foo.rb
class Foo
SPAN_NAME = "method.call"
def bar
Datadog.tracer.trace("method.call", resource: "#{self.class}.#{__method__}") do
execute_awesome_logic
end
end
end
It gives control, but in exchange blurs what's really important here - business logic.
I'd like to propose two alternative approaches.
Well know based on mixin.
# models/foo.rb
class Foo
include Datadog::MethodTracer
trace_method :bar
def bar
execute_awesome_logic
end
end
Or a bit more sophisticated based on IoC principles and inspired by Aspect-oriented programming.
# foo.rb
class Foo
def bar
execute_awesome_logic
end
end
# initializers/method_tracer.rb
# instance based
method_tracer = Datadog::MethodTracer.new
method_tracer.add_method Foo, :bar
# or class based
Datadog::MethodTracer.add_method Foo, :bar
Already have PoC for those two, let me know if it makes sense to include in gem.
Tracking a lot of method calls can be cumbersome in complex systems. Imagine repeating over and over the same piece of code for dozens of classes and methods.
It gives control, but in exchange blurs what's really important here - business logic.
I'd like to propose two alternative approaches.
Well know based on mixin.
Or a bit more sophisticated based on IoC principles and inspired by Aspect-oriented programming.
Already have PoC for those two, let me know if it makes sense to include in gem.