def call(env)
      context = { request: ActionDispatch::Request.new(env) }
      sequence = build_sequence(@root_item, context)
      chain = build_request_chain(sequence, context)

      event = build_event(context)

      publish_start(event.dup)
      instrumented_call(event) do
        begin
          response = chain.instrument.call
        ensure
          # We want to populate the response and metadata fields after the middleware
          # chain has completed so that the end of the instrumentation can see them. The
          # simplest way to do this is pass the event by reference to ActiveSupport, then
          # modify the hash to contain this detail before the instrumentation completes.
          #
          # This way, the last finish_handler.coach event will have all the details.
          status = response.try(:first) || STATUS_CODE_FOR_EXCEPTIONS
          event.merge!(
            response: { status: status },
            metadata: context.fetch(:_metadata, {}),
          )
        end
      end
    end
def call(env)
      context = { request: ActionDispatch::Request.new(env) }
      sequence = build_sequence(@root_item, context)
      chain = build_request_chain(sequence, context)

      event = build_event(context)

      publish_start(event.dup)
      instrumented_call(event) do
        begin
          response = chain.instrument.call
        ensure
          # We want to populate the response and metadata fields after the middleware
          # chain has completed so that the end of the instrumentation can see them. The
          # simplest way to do this is pass the event by reference to ActiveSupport, then
          # modify the hash to contain this detail before the instrumentation completes.
          #
          # This way, the last finish_handler.coach event will have all the details.
          status = response.try(:first) || STATUS_CODE_FOR_EXCEPTIONS
          event.merge!(
            response: { status: status },
            metadata: context.fetch(:_metadata, {}),
          )
        end
      end
    end
The Rack interface to handler - builds a middleware chain based on
 the current request, and invokes it.
 rubocop:disable Metrics/MethodLength