Sha256: 671113ebe018191c130d809085d7460d0fe6d940dff19b25e173e06fa3942fec

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require "appsignal"
require "appsignal/rack/hanami_middleware"

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

        hanami_app_config = ::Hanami.app.config

        unless Appsignal.active?
          Appsignal.config = Appsignal::Config.new(
            hanami_app_config.root || Dir.pwd,
            hanami_app_config.env
          )
          Appsignal.start
        end

        return unless Appsignal.active?

        hanami_app_config.middleware.use(
          ::Rack::Events,
          [Appsignal::Rack::EventHandler.new]
        )
        hanami_app_config.middleware.use(Appsignal::Rack::HanamiMiddleware)

        ::Hanami::Action.prepend Appsignal::Integrations::HanamiIntegration
      end
    end

    # @api private
    module HanamiIntegration
      def call(env)
        super
      ensure
        transaction = env[::Appsignal::Rack::APPSIGNAL_TRANSACTION]

        transaction&.set_action_if_nil(self.class.name)
      end
    end
  end
end

Appsignal::Integrations::HanamiPlugin.init unless Appsignal.testing?

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
appsignal-3.11.0-java lib/appsignal/integrations/hanami.rb
appsignal-3.11.0 lib/appsignal/integrations/hanami.rb
appsignal-3.10.0-java lib/appsignal/integrations/hanami.rb
appsignal-3.10.0 lib/appsignal/integrations/hanami.rb
appsignal-3.9.3-java lib/appsignal/integrations/hanami.rb
appsignal-3.9.3 lib/appsignal/integrations/hanami.rb