Module: Datadog::ErrorTracking::Filters Private

Defined in:
lib/datadog/error_tracking/filters.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Based on configuration, the TracePoint listening to :rescue or :raise may report more handled errors than we want to report. Therefore we need a function to filter the events. As the filter function both depends on configuration and is called numerous time, we generate it during during the initialization of the feature to have the best performance possible.

Class Method Summary collapse

Class Method Details

.datadog_code?(file_path) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


32
33
34
# File 'lib/datadog/error_tracking/filters.rb', line 32

def self.datadog_code?(file_path)
  file_path.include?("lib/datadog/")
end

.file_included?(file_path, instrumented_files) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


41
42
43
# File 'lib/datadog/error_tracking/filters.rb', line 41

def self.file_included?(file_path, instrumented_files)
  instrumented_files.include?(file_path)
end

.generate_filter(to_instrument_scope, handled_errors_include = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Generate the proc used in the TracePoint



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/datadog/error_tracking/filters.rb', line 46

def self.generate_filter(to_instrument_scope, handled_errors_include = nil)
  case to_instrument_scope
  # If DD_ERROR_TRACKING_HANDLED_ERRORS is set
  when "all"
    proc { |file_path| !datadog_code?(file_path) }
  when "user"
    # If DD_ERROR_TRACKING_HANDLED_ERRORS_INCLUDE is set
    if handled_errors_include
      proc { |file_path|
        user_code?(file_path) || file_included?(file_path, handled_errors_include)
      }
    else
      proc { |file_path| user_code?(file_path) }
    end
  when "third_party"
    if handled_errors_include
      proc { |file_path|
        third_party_code?(file_path) || file_included?(file_path, handled_errors_include)
      }
    else
      proc { |file_path| third_party_code?(file_path) }
    end
  else
    # If only DD_ERROR_TRACKING_HANDLED_ERRORS_INCLUDE is set
    proc { |file_path| file_included?(file_path, handled_errors_include) }
  end
end

.get_gem_name(file_path) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/datadog/error_tracking/filters.rb', line 14

def self.get_gem_name(file_path)
  regex = %r{gems/([^/]+)-\d}
  regex_match = regex.match(file_path)
  return unless regex_match

  gem_name = regex_match[1] #: String

  begin
    Gem::Specification.find_by_name(gem_name)
  rescue Gem::MissingSpecError
    nil
  end
end

.third_party_code?(file_path) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/datadog/error_tracking/filters.rb', line 36

def self.third_party_code?(file_path)
  gem_name = get_gem_name(file_path)
  gem_name && gem_name != "datadog"
end

.user_code?(file_path) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


28
29
30
# File 'lib/datadog/error_tracking/filters.rb', line 28

def self.user_code?(file_path)
  !get_gem_name(file_path)
end