Sha256: 7793ef36e15667076f868d5403143597297592a46d1d8e1d3efa97791f6a3a10

Contents?: true

Size: 1.26 KB

Versions: 25

Compression:

Stored size: 1.26 KB

Contents

require 'rack'

module Appsignal
  module Rack
    class SinatraInstrumentation
      def initialize(app, options = {})
        Appsignal.logger.debug 'Initializing Appsignal::Rack::SinatraInstrumentation'
        @app, @options = app, options
      end

      def call(env)
        ActiveSupport::Notifications.instrument(
          'process_action.sinatra',
          raw_payload(env)
        ) do |payload|
          begin
            @app.call(env)
          ensure
            # This information is available only after the
            # request has been processed by Sinatra.
            payload[:action] = env['sinatra.route']
          end
        end
      ensure
        # In production newer versions of Sinatra don't raise errors, but store
        # them in the sinatra.error env var.
        Appsignal::Transaction.current.add_exception(env['sinatra.error']) if env['sinatra.error']
      end

      def raw_payload(env)
        request = @options.fetch(:request_class, ::Sinatra::Request).new(env)
        params = request.public_send(@options.fetch(:params_method, :params))
        {
          :params  => params,
          :session => request.session,
          :method  => request.request_method,
          :path    => request.path
        }
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
appsignal-0.12.beta.31 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.30 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.29 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.28 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.27 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.26 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.25 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.24 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.23 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.22 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.21 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.20 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.19 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.18 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.17 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.16 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.15 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.14 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.13 lib/appsignal/rack/sinatra_instrumentation.rb
appsignal-0.12.beta.12 lib/appsignal/rack/sinatra_instrumentation.rb