class ScoutApm::Extensions::Config
!!! Extensions
are a 0.x level API and breakage is expected as the API is refined. Extensions
fan out data collected by the agent to additional services.
Attributes
Public Class Methods
Adds a callback that runs when the per-minute report data is sent to Scout. These run in a background thread so external HTTP calls are OK. callback
must be an object that responds to a +call(reporting_period, metadata)+ method.
Example: ScoutApm::Extensions::Config.add_periodic_callback
(Proc.new { |reporting_period, metadata| … })
# File lib/scout_apm/extensions/config.rb, line 29 def self.add_periodic_callback(callback) agent_context.extensions.periodic_callbacks << callback end
Adds a new callback that runs after a transaction completes. These run inline during the request and thus should add minimal overhead. For example, a transaction callback should NOT make inline HTTP calls to outside services. callback
must be an object that respond to a +call(payload)+ method.
Example: ScoutApm::Extensions::Config.add_transaction_callback
(Proc.new { |payload| puts “Duration: #{payload.duration_ms}” })
payload
is a ScoutApm::Extensions::TransactionCallbackPayload
object.
# File lib/scout_apm/extensions/config.rb, line 19 def self.add_transaction_callback(callback) agent_context.extensions.transaction_callbacks << callback end
# File lib/scout_apm/extensions/config.rb, line 77 def self.agent_context ScoutApm::Agent.instance.context end
# File lib/scout_apm/extensions/config.rb, line 33 def initialize(agent_context) @agent_context = agent_context @transaction_callbacks = [] @periodic_callbacks = [] end
Public Instance Methods
# File lib/scout_apm/extensions/config.rb, line 81 def logger agent_context.logger end
Runs each reporting period callback. Each callback runs inside a begin/rescue block so a broken callback doesn't prevent other callbacks from executing or reporting data from being sent.
# File lib/scout_apm/extensions/config.rb, line 42 def run_periodic_callbacks(reporting_period, metadata) return unless periodic_callbacks.any? periodic_callbacks.each do |callback| begin callback.call(reporting_period, metadata) rescue => e logger.warn "Error running reporting callback extension=#{callback}" logger.info e.message logger.debug e.backtrace end end end
Runs each transaction callback. Each callback runs inside a begin/rescue block so a broken callback doesn't prevent other callbacks from executing or the transaction from being recorded.
# File lib/scout_apm/extensions/config.rb, line 59 def run_transaction_callbacks(converter_results, context, scope_layer) # It looks like layer_finder.scope = nil when a Sidekiq job is retried return unless scope_layer return unless transaction_callbacks.any? payload = ScoutApm::Extensions::TransactionCallbackPayload.new(agent_context,converter_results,context,scope_layer) transaction_callbacks.each do |callback| begin callback.call(payload) rescue => e logger.warn "Error running transaction callback extension=#{callback}" logger.info e.message logger.debug e.backtrace end end end