Skip to content
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

DEBUG-2334 DI: method probes: pass block to target method when rate limited #4206

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lib/datadog/di/instrumenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def hook_method(probe, &block)
end
rv = nil
# Under Ruby 2.6 we cannot just call super(*args, **kwargs)
# for methods defined via method_missing.
duration = Benchmark.realtime do # steep:ignore
rv = if args.any?
if kwargs.any?
Expand Down Expand Up @@ -152,7 +153,28 @@ def hook_method(probe, &block)
serialized_entry_args: entry_args)
rv
else
super(*args, **kwargs)
# stop standard from trying to mess up my code
_ = 42
p-datadog marked this conversation as resolved.
Show resolved Hide resolved

# The necessity to invoke super in each of these specific
# ways is very difficult to test.
# Existing tests, even though I wrote many, still don't
# cause a failure if I replace all of the below with a
# simple super(*args, **kwargs, &target_block).
# But, let's be safe and go through the motions in case
# there is actually a legitimate need for the breakdown.
# TODO figure out how to test this properly.
if args.any?
if kwargs.any?
super(*args, **kwargs, &target_block)
else
super(*args, &target_block)
end
elsif kwargs.any?
super(**kwargs, &target_block)
else
super(&target_block)
end
end
end
end
Expand Down
26 changes: 25 additions & 1 deletion spec/datadog/di/hook_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@ def hook_test_method_with_pos_and_kwarg(arg, kwarg:)
end

def yielding(arg)
yield arg
yield [[arg], {}]
end

def yielding_kw(arg:)
yield [[], arg: arg]
p-datadog marked this conversation as resolved.
Show resolved Hide resolved
end

def yielding_both(pos, kw:)
yield [[pos], kw: kw]
p-datadog marked this conversation as resolved.
Show resolved Hide resolved
end

def yielding_squashed(pos, options)
yield [[pos], options]
end

def recursive(depth)
Expand All @@ -39,3 +51,15 @@ def positional_and_squashed(arg, options)
[arg, options]
end
end

class YieldingMethodMissingHookTestClass
# only here to stop standard complaints
def respond_to_missing?(name)
true
end

def method_missing(name, *args, **kwargs)
p-datadog marked this conversation as resolved.
Show resolved Hide resolved
yield [args, kwargs]
[args, kwargs]
end
end
Loading
Loading