lib/datadog/di/probe.rb in datadog-2.4.0 vs lib/datadog/di/probe.rb in datadog-2.5.0
- old
+ new
@@ -1,8 +1,9 @@
# frozen_string_literal: true
require_relative "error"
+require_relative "utils"
require_relative "../core/rate_limiter"
module Datadog
module DI
# Encapsulates probe information (as received via remote config)
@@ -29,15 +30,21 @@
#
# Note: only some of the parameter/attribute values are currently validated.
#
# @api private
class Probe
+ KNOWN_TYPES = %i[log].freeze
+
def initialize(id:, type:,
file: nil, line_no: nil, type_name: nil, method_name: nil,
template: nil, capture_snapshot: false, max_capture_depth: nil, rate_limit: nil)
# Perform some sanity checks here to detect unexpected attribute
# combinations, in order to not do them in subsequent code.
+ unless KNOWN_TYPES.include?(type)
+ raise ArgumentError, "Unknown probe type: #{type}"
+ end
+
if line_no && method_name
raise ArgumentError, "Probe contains both line number and method name: #{id}"
end
if type_name && !method_name || method_name && !type_name
@@ -126,8 +133,30 @@
# This case should not be possible because constructor verifies that
# the probe is a method or a line probe.
raise NotImplementedError
end
end
+
+ # Returns whether the provided +path+ matches the user-designated
+ # file (of a line probe).
+ #
+ # If file is an absolute path (i.e., it starts with a slash), the file
+ # must be identical to path to match.
+ #
+ # If file is not an absolute path, the path matches if the file is its suffix,
+ # at a path component boundary.
+ def file_matches?(path)
+ unless file
+ raise ArgumentError, "Probe does not have a file to match against"
+ end
+ Utils.path_matches_suffix?(path, file)
+ end
+
+ # Instrumentation module for method probes.
+ attr_accessor :instrumentation_module
+
+ # Line trace point for line probes. Normally this would be a targeted
+ # trace point.
+ attr_accessor :instrumentation_trace_point
end
end
end