module OneApm::Agent::Instrumentation::Sinatra
OneApm
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/one_apm/inst/framework/sinatra.rb, line 79 def self.included(clazz) clazz.extend(ClassMethods) end
Public Instance Methods
# File lib/one_apm/inst/framework/sinatra.rb, line 159 def dispatch_and_notice_errors_with_oneapm dispatch_without_oneapm 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') OneApm::Manager.notice_error(env['sinatra.error']) if had_error end
# File lib/one_apm/inst/framework/sinatra.rb, line 138 def dispatch_with_oneapm request_params = get_request_params filtered_params = OneApm::Support::ParameterFiltering.apply_filters(request.env, request_params || {}) name = TransactionNamer.initial_transaction_name(request) perform_action_with_oneapm_trace(:category => :sinatra, :name => name, :params => filtered_params) do dispatch_and_notice_errors_with_oneapm end end
# File lib/one_apm/inst/framework/sinatra.rb, line 168 def do_not_trace? Ignorer.should_ignore?(self, :routes) end
# File lib/one_apm/inst/framework/sinatra.rb, line 150 def get_request_params begin @request.params rescue => e OneApm::Manager.logger.debug("Failed to get params from Rack request.", e) nil end end
Overrides TransactionBase
implementation
# File lib/one_apm/inst/framework/sinatra.rb, line 173 def ignore_apdex? Ignorer.should_ignore?(self, :apdex) end
Overrides TransactionBase
implementation
# File lib/one_apm/inst/framework/sinatra.rb, line 178 def ignore_enduser? Ignorer.should_ignore?(self, :enduser) end
Expected method for supporting TransactionBase
# File lib/one_apm/inst/framework/sinatra.rb, line 75 def oneapm_request_headers(_) request.env end
Capture last route we've seen. Will set for transaction on route_eval
# File lib/one_apm/inst/framework/sinatra.rb, line 108 def process_route_with_oneapm(*args, &block) begin env["oneapm.last_route"] = args[0] rescue => e OneApm::Manager.logger.debug("Failed determining last route in Sinatra", e) end process_route_without_oneapm(*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/one_apm/inst/framework/sinatra.rb, line 124 def route_eval_with_oneapm(*args, &block) begin txn_name = TransactionNamer.transaction_name_for_route(env, request) unless txn_name.nil? ::OneApm::Transaction.set_default_transaction_name( "#{self.class.name}/#{txn_name}", :sinatra) end rescue => e OneApm::Manager.logger.debug("Failed during route_eval to set transaction name", e) end route_eval_without_oneapm(*args, &block) end