Sha256: 2d7d1805a5969b6643e5b2b9f0214b1cdeab0cb763690f06c7ddad559cf6ec55

Contents?: true

Size: 1.66 KB

Versions: 26

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require "appsignal"

module Appsignal
  module Integrations
    module HanamiPlugin
      def self.init
        Appsignal.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.send(: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

26 entries across 26 versions & 1 rubygems

Version Path
appsignal-3.3.11-java lib/appsignal/integrations/hanami.rb
appsignal-3.3.11 lib/appsignal/integrations/hanami.rb
appsignal-3.4.0-java lib/appsignal/integrations/hanami.rb
appsignal-3.4.0 lib/appsignal/integrations/hanami.rb
appsignal-3.3.10-java lib/appsignal/integrations/hanami.rb
appsignal-3.3.10 lib/appsignal/integrations/hanami.rb
appsignal-3.3.9-java lib/appsignal/integrations/hanami.rb
appsignal-3.3.9 lib/appsignal/integrations/hanami.rb
appsignal-3.3.8-java lib/appsignal/integrations/hanami.rb
appsignal-3.3.8 lib/appsignal/integrations/hanami.rb
appsignal-3.3.7-java lib/appsignal/integrations/hanami.rb
appsignal-3.3.7 lib/appsignal/integrations/hanami.rb
appsignal-3.3.6-java lib/appsignal/integrations/hanami.rb
appsignal-3.3.6 lib/appsignal/integrations/hanami.rb
appsignal-3.3.5-java lib/appsignal/integrations/hanami.rb
appsignal-3.3.5 lib/appsignal/integrations/hanami.rb
appsignal-3.3.4-java lib/appsignal/integrations/hanami.rb
appsignal-3.3.4 lib/appsignal/integrations/hanami.rb
appsignal-3.3.3-java lib/appsignal/integrations/hanami.rb
appsignal-3.3.3 lib/appsignal/integrations/hanami.rb