Sha256: 5ae7417c5c25cd5de6712ff445795255b3b04f1f2dddfe35f1bd44e218cb3a32

Contents?: true

Size: 1.67 KB

Versions: 32

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

require "appsignal"

module Appsignal
  module Integrations
    module HanamiPlugin
      def self.init
        Appsignal.internal_logger.debug("Loading Hanami integration")

        hanami_app_config = ::Hanami.app.config
        Appsignal.config = Appsignal::Config.new(
          hanami_app_config.root || Dir.pwd,
          hanami_app_config.env
        )

        Appsignal.start_logger
        Appsignal.start

        ::Hanami::Action.prepend Appsignal::Integrations::HanamiIntegration if Appsignal.active?
      end
    end
  end
end

module Appsignal::Integrations::HanamiIntegration
  def call(env)
    params = ::Hanami::Action::BaseParams.new(env)
    request = ::Hanami::Action::Request.new(
      :env => env,
      :params => params,
      :sessions_enabled => true
    )

    transaction = Appsignal::Transaction.create(
      SecureRandom.uuid,
      Appsignal::Transaction::HTTP_REQUEST,
      request
    )

    begin
      Appsignal.instrument("process_action.hanami") do
        super.tap do |response|
          transaction.set_metadata("status", response.status.to_s)
        end
      end
    rescue Exception => error # rubocop:disable Lint/RescueException
      transaction.set_error(error)
      transaction.set_metadata("status", "500")
      raise error
    ensure
      transaction.params = request.params.to_h
      transaction.set_action_if_nil(self.class.name)
      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
end

Appsignal::Integrations::HanamiPlugin.init

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
appsignal-3.9.1-java lib/appsignal/integrations/hanami.rb
appsignal-3.9.1 lib/appsignal/integrations/hanami.rb
appsignal-3.9.0-java lib/appsignal/integrations/hanami.rb
appsignal-3.9.0 lib/appsignal/integrations/hanami.rb
appsignal-3.8.1-java lib/appsignal/integrations/hanami.rb
appsignal-3.8.1 lib/appsignal/integrations/hanami.rb
appsignal-3.8.0-java lib/appsignal/integrations/hanami.rb
appsignal-3.8.0 lib/appsignal/integrations/hanami.rb
appsignal-3.7.6-java lib/appsignal/integrations/hanami.rb
appsignal-3.7.6 lib/appsignal/integrations/hanami.rb
appsignal-3.7.2-java lib/appsignal/integrations/hanami.rb
appsignal-3.7.2 lib/appsignal/integrations/hanami.rb
appsignal-3.7.1-java lib/appsignal/integrations/hanami.rb
appsignal-3.7.1 lib/appsignal/integrations/hanami.rb
appsignal-3.7.0-java lib/appsignal/integrations/hanami.rb
appsignal-3.7.0 lib/appsignal/integrations/hanami.rb
appsignal-3.6.5-java lib/appsignal/integrations/hanami.rb
appsignal-3.6.5 lib/appsignal/integrations/hanami.rb
appsignal-3.6.4-java lib/appsignal/integrations/hanami.rb
appsignal-3.6.4 lib/appsignal/integrations/hanami.rb