Skip to content

Commit

Permalink
respect probe max capture depth and attribute count in serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Nov 20, 2024
1 parent b1edd69 commit 0195adb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 3 additions & 1 deletion lib/datadog/di/instrumenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def hook_method(probe, &block)
# Arguments may be mutated by the method, therefore
# they need to be serialized prior to method invocation.
entry_args = if probe.capture_snapshot?
serializer.serialize_args(args, kwargs)
serializer.serialize_args(args, kwargs,
depth: probe.max_capture_depth || settings.dynamic_instrumentation.max_capture_depth,
attribute_count: probe.max_capture_attribute_count || settings.dynamic_instrumentation.max_capture_attribute_count)
end
rv = nil
# Under Ruby 2.6 we cannot just call super(*args, **kwargs)
Expand Down
13 changes: 10 additions & 3 deletions lib/datadog/di/probe_notification_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,29 @@ def build_snapshot(probe, rv: nil, snapshot: nil, path: nil,
arguments: if serialized_entry_args
serialized_entry_args
else
(args || kwargs) && serializer.serialize_args(args, kwargs)
(args || kwargs) && serializer.serialize_args(args, kwargs,
depth: probe.max_capture_depth || settings.dynamic_instrumentation.max_capture_depth,
attribute_count: probe.max_capture_attribute_count || settings.dynamic_instrumentation.max_capture_attribute_count)
end,
throwable: nil,
# standard:enable all
},
return: {
arguments: {
"@return": serializer.serialize_value(rv),
"@return": serializer.serialize_value(rv,
depth: probe.max_capture_depth || settings.dynamic_instrumentation.max_capture_depth,
attribute_count: probe.max_capture_attribute_count || settings.dynamic_instrumentation.max_capture_attribute_count),
},
throwable: nil,
},
}
elsif probe.line?
{
lines: snapshot && {
probe.line_no => {locals: serializer.serialize_vars(snapshot)},
probe.line_no => {locals: serializer.serialize_vars(snapshot,
depth: probe.max_capture_depth || settings.dynamic_instrumentation.max_capture_depth,
attribute_count: probe.max_capture_attribute_count || settings.dynamic_instrumentation.max_capture_attribute_count,
)},
},
}
end
Expand Down
12 changes: 8 additions & 4 deletions lib/datadog/di/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,28 @@ def initialize(settings, redactor, telemetry: nil)
# between positional and keyword arguments. We convert positional
# arguments to keyword arguments ("arg1", "arg2", ...) and ensure
# the positional arguments are listed first.
def serialize_args(args, kwargs)
def serialize_args(args, kwargs,
depth: settings.dynamic_instrumentation.max_capture_depth,
attribute_count: settings.dynamic_instrumentation.max_capture_attribute_count)
counter = 0
combined = args.each_with_object({}) do |value, c|
counter += 1
# Conversion to symbol is needed here to put args ahead of
# kwargs when they are merged below.
c[:"arg#{counter}"] = value
end.update(kwargs)
serialize_vars(combined)
serialize_vars(combined, depth: depth, attribute_count: attribute_count)
end

# Serializes variables captured by a line probe.
#
# These are normally local variables that exist on a particular line
# of executed code.
def serialize_vars(vars)
def serialize_vars(vars,
depth: settings.dynamic_instrumentation.max_capture_depth,
attribute_count: settings.dynamic_instrumentation.max_capture_attribute_count)
vars.each_with_object({}) do |(k, v), agg|
agg[k] = serialize_value(v, name: k)
agg[k] = serialize_value(v, name: k, depth: depth, attribute_count: attribute_count)
end
end

Expand Down

0 comments on commit 0195adb

Please sign in to comment.