Class: NewRelic::Agent::Instrumentation::RailsEventLogSubscriber
- Inherits:
-
Object
- Object
- NewRelic::Agent::Instrumentation::RailsEventLogSubscriber
- Defined in:
- lib/new_relic/agent/instrumentation/rails_event_log_subscriber.rb
Constant Summary collapse
- INSTRUMENTATION_NAME =
'RailsEventLogger'
Class Method Summary collapse
- .enabled? ⇒ Boolean
-
.subscribed? ⇒ Boolean
Check if already subscribed to Rails.event.
Instance Method Summary collapse
-
#emit(event) ⇒ Object
Called by Rails.event system for each event.
-
#initialize ⇒ RailsEventLogSubscriber
constructor
A new instance of RailsEventLogSubscriber.
Constructor Details
#initialize ⇒ RailsEventLogSubscriber
Returns a new instance of RailsEventLogSubscriber.
13 14 15 16 |
# File 'lib/new_relic/agent/instrumentation/rails_event_log_subscriber.rb', line 13 def initialize @event_filter = NewRelic::Agent.config[:'instrumentation.rails_event_logger.event_names'] @filter_enabled = !@event_filter.empty? end |
Class Method Details
.enabled? ⇒ Boolean
9 10 11 |
# File 'lib/new_relic/agent/instrumentation/rails_event_log_subscriber.rb', line 9 def self.enabled? NewRelic::Agent.config[:'instrumentation.rails_event_logger'] end |
.subscribed? ⇒ Boolean
Check if already subscribed to Rails.event
31 32 33 34 35 36 37 |
# File 'lib/new_relic/agent/instrumentation/rails_event_log_subscriber.rb', line 31 def self.subscribed? return false unless defined?(Rails) && Rails.respond_to?(:event) # rubocop:disable Performance/RedundantEqualityComparisonBlock Rails.event.subscribers.any? { |sub| sub.is_a?(self) } # rubocop:enable Performance/RedundantEqualityComparisonBlock end |
Instance Method Details
#emit(event) ⇒ Object
Called by Rails.event system for each event
20 21 22 23 24 25 26 27 28 |
# File 'lib/new_relic/agent/instrumentation/rails_event_log_subscriber.rb', line 20 def emit(event) # Filter events if configured return if @filter_enabled && !@event_filter.include?(event[:name]) NewRelic::Agent.record_instrumentation_invocation(INSTRUMENTATION_NAME) NewRelic::Agent.agent.log_event_aggregator.record_rails_event(event) rescue => e NewRelic::Agent.logger.debug("Failed to capture Rails.event: #{e.}") end |