Sha256: fef04f49d7af0d6bd3c514556df893f81d0e24f7c68b7e05d536124e3f3fe37a

Contents?: true

Size: 1.99 KB

Versions: 5

Compression:

Stored size: 1.99 KB

Contents

require "appsignal"

module Appsignal::Integrations
  module PadrinoPlugin
    def self.init
      Appsignal.logger.info("Loading Padrino (#{Padrino::VERSION}) integration")

      root             = Padrino.mounted_root
      Appsignal.config = Appsignal::Config.new(
        root,
        Padrino.env,
        :log_path => File.join(root, "log")
      )

      Appsignal.start_logger
      Appsignal.start
    end
  end
end

module Padrino::Routing::InstanceMethods
  alias route_without_appsignal route!

  def route!(base = settings, pass_block = nil)
    if !Appsignal.active? || env["sinatra.static_file"]
      route_without_appsignal(base, pass_block)
      return
    end

    transaction = Appsignal::Transaction.create(
      SecureRandom.uuid,
      Appsignal::Transaction::HTTP_REQUEST,
      request
    )
    begin
      Appsignal.instrument("process_action.padrino") do
        route_without_appsignal(base, pass_block)
      end
    rescue => error
      transaction.set_error(error)
      raise error
    ensure
      transaction.set_action(get_payload_action(request))
      transaction.set_metadata("path", request.path)
      transaction.set_metadata("method", request.request_method)
      transaction.set_http_or_background_queue_start
      Appsignal::Transaction.complete_current!
    end
  end

  def get_payload_action(request)
    # Short-circut is there's no request object to obtain information from
    return settings.name.to_s if request.nil?

    # Older versions of Padrino work with a route object
    route_obj = defined?(request.route_obj) && request.route_obj
    if route_obj && route_obj.respond_to?(:original_path)
      return "#{settings.name}:#{request.route_obj.original_path}"
    end

    # Newer versions expose the action / controller on the request class
    request_data = request.respond_to?(:action) ? request.action : request.fullpath
    "#{settings.name}:#{request.controller}##{request_data}"
  end
end

Padrino.after_load do
  Appsignal::Integrations::PadrinoPlugin.init
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
appsignal-2.1.2 lib/appsignal/integrations/padrino.rb
appsignal-2.1.1 lib/appsignal/integrations/padrino.rb
appsignal-2.1.1.beta.1 lib/appsignal/integrations/padrino.rb
appsignal-2.1.0 lib/appsignal/integrations/padrino.rb
appsignal-2.1.0.beta.1 lib/appsignal/integrations/padrino.rb