Module: FiltersTracer

Defined in:
lib/filters_tracer.rb,
lib/filters_tracer/version.rb

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.configurationFiltersTracer::Configuration



31
32
33
# File 'lib/filters_tracer.rb', line 31

def configuration
  @configuration ||= Configuration.new
end

.configure {|config| ... } ⇒ void

This method returns an undefined value.

Examples:

FiltersTracer.configure do |config|
  config.logger = MyCustomLogger.new
end

Yields:

  • (config)

Yield Parameters:



26
27
28
# File 'lib/filters_tracer.rb', line 26

def configure
  yield configuration
end

.loggerLogger

Returns:

  • (Logger)


36
37
38
# File 'lib/filters_tracer.rb', line 36

def logger
  configuration.logger
end

.register_all_subcontrollers(controller) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/filters_tracer.rb', line 71

def register_all_subcontrollers(controller)
  if controller.class != Class
    logger.error "===== [Failure] Could not register #{controller}(#{controller.class}) ====="
    return
  end

  self.register_controller(controller)
  controller.descendants.each do |sub_controller|
    self.register_controller(sub_controller)
  end
end

.register_controller(controller) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/filters_tracer.rb', line 40

def register_controller(controller)
  if controller.class != Class
    logger.error "===== [Failure] Could not register #{controller}(#{controller.class}) ====="
    return
  end

  unless controller.method_defined?(:_process_action_callbacks)
    logger.error "===== [Failure] #{controller} is not a traceable controller ====="
    logger.error "===== This is probably because either #{controller} is not a Rails controller or because the current version of Rails is not compatible with 'rails_filters_tracer' gem."
    return
  end

  begin
    controller.class_eval do
      self.include ::NewRelic::Agent::MethodTracer
      self._process_action_callbacks().send(:chain).each do |callback|
        case callback.raw_filter
        when Symbol
          self.add_method_tracer callback.raw_filter
        end
      end
    end
  rescue
    logger.error "===== [Failure] Filters of actions in #{controller_str} would not be traced properly.  ====="
    logger.error "===== This is probably because either the current version of Rails or NewRelic::Agent is not compatible with 'rails_filters_tracer' gem."
    return
  end

  logger.info "===== [Success] Filters of all actions in #{controller} will be reported to the New Relic server ====="
end