diff --git a/lib/datadog/di/instrumenter.rb b/lib/datadog/di/instrumenter.rb index e9fea6b74e7..0907c30bf34 100644 --- a/lib/datadog/di/instrumenter.rb +++ b/lib/datadog/di/instrumenter.rb @@ -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) diff --git a/lib/datadog/di/probe_notification_builder.rb b/lib/datadog/di/probe_notification_builder.rb index 2f058eaadd7..e7110187e51 100644 --- a/lib/datadog/di/probe_notification_builder.rb +++ b/lib/datadog/di/probe_notification_builder.rb @@ -65,14 +65,18 @@ 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, }, @@ -80,7 +84,10 @@ def build_snapshot(probe, rv: nil, snapshot: nil, path: 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 diff --git a/lib/datadog/di/serializer.rb b/lib/datadog/di/serializer.rb index 8801a2862b3..0e231f88e51 100644 --- a/lib/datadog/di/serializer.rb +++ b/lib/datadog/di/serializer.rb @@ -82,7 +82,9 @@ 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 @@ -90,16 +92,18 @@ def serialize_args(args, kwargs) # 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