Skip to content

Easy and unobtrusive method tracing #1197

Description

@norbertnytko

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.

Metadata

Metadata

Assignees

Labels

communityWas opened by a community memberfeature-requestA request for a new feature or change to an existing one

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions