Class: Appsignal::Rack::InstrumentationMiddleware

Inherits:
AbstractMiddleware show all
Defined in:
lib/appsignal/rack/instrumentation_middleware.rb

Overview

Rack instrumentation middleware.

This Ruby gem automatically instruments several Rack based libraries, like Rails and Sinatra. This middleware does not need to be added manually to these frameworks.

This instrumentation middleware will wrap an app and report how long the request and response took, report errors that occurred in the app, and report metadata about the request method and path.

The action name for the endpoint is not set by default, which is required for performance monitoring. Set the action name in each endpoint using the Helpers::Instrumentation#set_action helper.

If multiple of these middlewares, or AbstractMiddleware subclasses are present in an app, only the top middleware will report errors from apps and other middleware.

This middleware is best used in combination with the EventHandler.

Examples:

# config.ru
require "appsignal"
# Configure and start AppSignal

# Add the EventHandler first
use ::Rack::Events, [Appsignal::Rack::EventHandler.new]
# Add the instrumentation middleware second
use Appsignal::Rack::InstrumentationMiddleware

# Other middleware

# Start app

Customize instrumentation event category

use Appsignal::Rack::InstrumentationMiddleware,
  :instrument_event_name => "custom.goup"

Disable error reporting for this middleware

use Appsignal::Rack::InstrumentationMiddleware, :report_errors => false

Always report errors, even when wrapped by other instrumentation middleware

use Appsignal::Rack::InstrumentationMiddleware, :report_errors => true

Disable error reporting for this middleware based on the request env

use Appsignal::Rack::InstrumentationMiddleware,
  :report_errors => lambda { |env| env["some_key"] == "some value" }

See Also:

Constant Summary

Constants inherited from AbstractMiddleware

AbstractMiddleware::DEFAULT_ERROR_REPORTING

Instance Method Summary collapse

Methods inherited from AbstractMiddleware

#call

Constructor Details

#initialize(app, options = {}) ⇒ InstrumentationMiddleware

Returns a new instance of InstrumentationMiddleware.



56
57
58
59
# File 'lib/appsignal/rack/instrumentation_middleware.rb', line 56

def initialize(app, options = {})
  options[:instrument_event_name] ||= "process_request_middleware.rack"
  super
end