Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Sep 24, 2024
1 parent 7185b77 commit 4855b8d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/datadog/di/hook_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ def hook_method(cls_name, meth_name, rate_limiter: nil)
id = next_id
serializer = self.serializer

mod = Module.new
mod.define_method(meth_name) do |*args, **kwargs|
# Arguments may be mutated by the method, therefore
# they need to be serialized prior to method invocation.
serialized_args = serializer.serialize_args(args, kwargs)
rv = nil
duration = Benchmark.realtime do
rv = saved.bind(self).call(*args, **kwargs)
end
# The method itself is not part of the stack trace because
# we are getting the stack trace from outside of the method.
# Add the method in manually as the top frame.
loc = saved.source_location
method_frame = "#{loc.first}:#{loc.last}:in `#{meth_name}'"
callers = [method_frame] + caller
yield rv: rv, duration: duration, callers: callers, serialized_args: serialized_args
rv
end

cls.class_eval do
saved = instance_method(meth_name)

Expand Down

0 comments on commit 4855b8d

Please sign in to comment.