Sha256: 09c57504c68acc7c06d5dbc9f8f06aada95934185f333ba44b31f3fa4828ba76

Contents?: true

Size: 1.06 KB

Versions: 56

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Appsignal
  module Rack
    # @api public
    class GrapeMiddleware < Appsignal::Rack::AbstractMiddleware
      # @api private
      def initialize(app, options = {})
        options[:instrument_event_name] = "process_request.grape"
        options[:report_errors] = lambda { |env| !env["grape.skip_appsignal_error"] }
        super
      end

      private

      def add_transaction_metadata_after(transaction, request)
        endpoint = request.env["api.endpoint"]
        unless endpoint&.options
          super
          return
        end

        options = endpoint.options
        request_method = options[:method].first.to_s.upcase
        klass = options[:for]
        namespace = endpoint.namespace
        namespace = "" if namespace == "/"

        path = options[:path].first.to_s
        path = "/#{path}" if path[0] != "/"
        path = "#{namespace}#{path}"

        transaction.set_action_if_nil("#{request_method}::#{klass}##{path}")

        super

        transaction.set_metadata("path", path)
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
appsignal-4.2.0-java lib/appsignal/rack/grape_middleware.rb
appsignal-4.2.0 lib/appsignal/rack/grape_middleware.rb
appsignal-4.1.3-java lib/appsignal/rack/grape_middleware.rb
appsignal-4.1.3 lib/appsignal/rack/grape_middleware.rb
appsignal-4.1.2-java lib/appsignal/rack/grape_middleware.rb
appsignal-4.1.2 lib/appsignal/rack/grape_middleware.rb
appsignal-4.1.1-java lib/appsignal/rack/grape_middleware.rb
appsignal-4.1.1 lib/appsignal/rack/grape_middleware.rb
appsignal-4.1.0-java lib/appsignal/rack/grape_middleware.rb
appsignal-4.1.0 lib/appsignal/rack/grape_middleware.rb
appsignal-4.0.9-java lib/appsignal/rack/grape_middleware.rb
appsignal-4.0.9 lib/appsignal/rack/grape_middleware.rb
appsignal-4.0.8-java lib/appsignal/rack/grape_middleware.rb
appsignal-4.0.8 lib/appsignal/rack/grape_middleware.rb
appsignal-4.0.7-java lib/appsignal/rack/grape_middleware.rb
appsignal-4.0.7 lib/appsignal/rack/grape_middleware.rb
appsignal-4.0.6-java lib/appsignal/rack/grape_middleware.rb
appsignal-4.0.6 lib/appsignal/rack/grape_middleware.rb
appsignal-4.0.5-java lib/appsignal/rack/grape_middleware.rb
appsignal-4.0.5 lib/appsignal/rack/grape_middleware.rb