module Mmtrix::Agent::Instrumentation::Sinatra
Mmtrix
instrumentation for Sinatra
applications. Sinatra
actions will appear in the UI similar to controller actions, and have breakdown charts and transaction traces.
The actions in the UI will correspond to the pattern expression used to match them, not directly to full URL’s.
Public Class Methods
# File lib/mmtrix/agent/instrumentation/sinatra.rb, line 82 def self.included(clazz) clazz.extend(ClassMethods) end
Public Instance Methods
# File lib/mmtrix/agent/instrumentation/sinatra.rb, line 162 def dispatch_and_notice_errors_with_mmtrix dispatch_without_mmtrix ensure # Will only see an error raised if :show_exceptions is true, but # will always see them in the env hash if they occur had_error = env.has_key?('sinatra.error') ::Mmtrix::Agent.notice_error(env['sinatra.error']) if had_error end
# File lib/mmtrix/agent/instrumentation/sinatra.rb, line 141 def dispatch_with_mmtrix #THREAD_LOCAL_ACCESS request_params = get_request_params filtered_params = ParameterFiltering::apply_filters(request.env, request_params || {}) name = TransactionNamer.initial_transaction_name(request) perform_action_with_mmtrix_trace(:category => :sinatra, :name => name, :params => filtered_params) do dispatch_and_notice_errors_with_mmtrix end end
# File lib/mmtrix/agent/instrumentation/sinatra.rb, line 171 def do_not_trace? Ignorer.should_ignore?(self, :routes) end
# File lib/mmtrix/agent/instrumentation/sinatra.rb, line 153 def get_request_params begin @request.params rescue => e Mmtrix::Agent.logger.debug("Failed to get params from Rack request.", e) nil end end
Overrides ControllerInstrumentation
implementation
# File lib/mmtrix/agent/instrumentation/sinatra.rb, line 176 def ignore_apdex? Ignorer.should_ignore?(self, :apdex) end
Overrides ControllerInstrumentation
implementation
# File lib/mmtrix/agent/instrumentation/sinatra.rb, line 181 def ignore_enduser? Ignorer.should_ignore?(self, :enduser) end
Expected method for supporting ControllerInstrumentation
# File lib/mmtrix/agent/instrumentation/sinatra.rb, line 78 def mmtrix_request_headers(_) request.env end
Capture last route we’ve seen. Will set for transaction on route_eval
# File lib/mmtrix/agent/instrumentation/sinatra.rb, line 111 def process_route_with_mmtrix(*args, &block) begin env["mmtrix.last_route"] = args[0] rescue => e ::Mmtrix::Agent.logger.debug("Failed determining last route in Sinatra", e) end process_route_without_mmtrix(*args, &block) end
If a transaction name is already set, this call will tromple over it. This is intentional, as typically passing to a separate route is like an entirely separate transaction, so we pick up the new name.
If we’re ignored, this remains safe, since set_transaction_name care for the gating on the transaction’s existence for us.
# File lib/mmtrix/agent/instrumentation/sinatra.rb, line 127 def route_eval_with_mmtrix(*args, &block) begin txn_name = TransactionNamer.transaction_name_for_route(env, request) unless txn_name.nil? ::Mmtrix::Agent::Transaction.set_default_transaction_name( "#{self.class.name}/#{txn_name}", :sinatra) end rescue => e ::Mmtrix::Agent.logger.debug("Failed during route_eval to set transaction name", e) end route_eval_without_mmtrix(*args, &block) end