From 335f1daddcfc17e02329a4ff8c02455b0bb448ee Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 24 Sep 2025 10:59:59 -0400 Subject: [PATCH 1/2] permit line no & method name at the same time --- lib/datadog/di/probe.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/datadog/di/probe.rb b/lib/datadog/di/probe.rb index ca4088a60da..e235da3e388 100644 --- a/lib/datadog/di/probe.rb +++ b/lib/datadog/di/probe.rb @@ -46,6 +46,17 @@ def initialize(id:, type:, raise ArgumentError, "Unknown probe type: #{type}" end + # TODO Probe should be inferred to be a line probe if the specification + # contains a line number. This how Java tracer works and Go tracer + # is implementing the same behavior, and Go will have all 3 fields + # (file path, line number and method name) for line probes. + # Do not raise if line number and method name both exist - instead + # treat the probe as a line probe. + # + # In the future we want to provide type name and method name to line + # probes, so that the library can verify that the instrumented line + # is in the method that the frontend showed to the user when the + # user created the probe. if line_no && method_name raise ArgumentError, "Probe contains both line number and method name: #{id}" end From 8087c658085af067ad8d71ba0ba8726563fd1f21 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 24 Sep 2025 11:25:24 -0400 Subject: [PATCH 2/2] implement --- lib/datadog/di/probe.rb | 19 ++++++------------- spec/datadog/di/probe_spec.rb | 7 +++---- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/lib/datadog/di/probe.rb b/lib/datadog/di/probe.rb index e235da3e388..c04e7a59d2d 100644 --- a/lib/datadog/di/probe.rb +++ b/lib/datadog/di/probe.rb @@ -46,7 +46,7 @@ def initialize(id:, type:, raise ArgumentError, "Unknown probe type: #{type}" end - # TODO Probe should be inferred to be a line probe if the specification + # Probe should be inferred to be a line probe if the specification # contains a line number. This how Java tracer works and Go tracer # is implementing the same behavior, and Go will have all 3 fields # (file path, line number and method name) for line probes. @@ -57,9 +57,6 @@ def initialize(id:, type:, # probes, so that the library can verify that the instrumented line # is in the method that the frontend showed to the user when the # user created the probe. - if line_no && method_name - raise ArgumentError, "Probe contains both line number and method name: #{id}" - end if line_no && !file raise ArgumentError, "Probe contains line number but not file: #{id}" @@ -69,6 +66,10 @@ def initialize(id:, type:, raise ArgumentError, "Partial method probe definition: #{id}" end + if line_no.nil? && method_name.nil? + raise ArgumentError, "Unhandled probe type: neither method nor line probe: #{id}" + end + @id = id @type = type @file = file @@ -82,14 +83,6 @@ def initialize(id:, type:, @max_capture_attribute_count = max_capture_attribute_count @condition = condition - # These checks use instance methods that have more complex logic - # than checking a single argument value. To avoid duplicating - # the logic here, use the methods and perform these checks after - # instance variable assignment. - unless method? || line? - raise ArgumentError, "Unhandled probe type: neither method nor line probe: #{id}" - end - @rate_limit = rate_limit || (@capture_snapshot ? 1 : 5000) @rate_limiter = Datadog::Core::TokenBucket.new(@rate_limit) @@ -140,7 +133,7 @@ def line? # Returns whether the probe is a method probe. def method? - !!(type_name && method_name) + line_no.nil? end # Returns the line number associated with the probe, raising diff --git a/spec/datadog/di/probe_spec.rb b/spec/datadog/di/probe_spec.rb index 4aa41809452..88403759bfe 100644 --- a/spec/datadog/di/probe_spec.rb +++ b/spec/datadog/di/probe_spec.rb @@ -89,10 +89,9 @@ type_name: "foo", method_name: "bar", file: "baz", line_no: 4) end - it "raises ArgumentError" do - expect do - probe - end.to raise_error(ArgumentError, /both line number and method name/) + it "creates a line probe" do + expect(probe.line?).to be true + expect(probe.method?).to be false end end end