Class: AppsignalExtensions::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/appsignal_extensions/middleware.rb

Overview

Used to open an Appsignal transaction, but to let the callee close it when it is done. The standard Rack middleware for Appsignal closes the transaction as soon as the response triplet gets returned, we need to keep the transaction open as long as the response is being read.

Defined Under Namespace

Classes: Close, NullTransaction, TransactionClosingBody

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Creates a new Appsignal middleware handler with the given Rack app as a callee

Parameters:

  • app (#call)

    the Rack app



64
65
66
# File 'lib/appsignal_extensions/middleware.rb', line 64

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Array

Calls the application, captures errors, sets up wrappers and so forth

Parameters:

  • env (Hash)

    the Rack env

Returns:

  • (Array)

    the Rack response triplet from upstream



72
73
74
75
76
77
78
79
80
# File 'lib/appsignal_extensions/middleware.rb', line 72

def call(env)
  request = ::Rack::Request.new(env)
  env['action_dispatch.request_id'] ||= SecureRandom.uuid
  if Appsignal.active?
    call_with_appsignal(env, request)
  else
    call_with_null_transaction(env, request)
  end
end