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

agent_context[R]
periodic_callbacks[RW]
transaction_callbacks[RW]

Public Class Methods

add_periodic_callback(callback) click to toggle source

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
add_transaction_callback(callback) click to toggle source

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
agent_context() click to toggle source
# File lib/scout_apm/extensions/config.rb, line 77
def self.agent_context
  ScoutApm::Agent.instance.context
end
new(agent_context) click to toggle source
# 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

logger() click to toggle source
# File lib/scout_apm/extensions/config.rb, line 81
def logger
  agent_context.logger
end
run_periodic_callbacks(reporting_period, metadata) click to toggle source

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
run_transaction_callbacks(converter_results, context, scope_layer) click to toggle source

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