Module: NewRelic::Agent::Instrumentation::Sinatra

Includes:
ControllerInstrumentation
Defined in:
lib/new_relic/agent/instrumentation/sinatra.rb

Overview

NewRelic 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. HTTP operations are not distinguished. Multiple matches will all be tracked as separate actions.

Defined Under Namespace

Modules: NewRelic

Instance Method Summary collapse

Methods included from ControllerInstrumentation

included, #newrelic_metric_path, #perform_action_with_newrelic_trace

Instance Method Details

#dispatch_and_notice_errors_with_newrelicObject



57
58
59
60
61
62
63
64
# File 'lib/new_relic/agent/instrumentation/sinatra.rb', line 57

def dispatch_and_notice_errors_with_newrelic
  dispatch_without_newrelic
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')
  ::NewRelic::Agent.notice_error(env['sinatra.error']) if had_error
end

#dispatch_with_newrelicObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/new_relic/agent/instrumentation/sinatra.rb', line 38

def dispatch_with_newrelic
  # We're trying to determine the transaction name via Sinatra's
  # process_route, but calling it here misses Sinatra's normal error handling.
  #
  # Relies on transaction_name to always safely return a value for us
  txn_name = NewRelic.transaction_name(self.class.routes, @request) do |pattern, keys, conditions|
    result = process_route(pattern, keys, conditions) do
      pattern.source
    end
    result if result.class == String
  end

  perform_action_with_newrelic_trace(:category => :sinatra,
                                     :name => txn_name,
                                     :params => @request.params) do
    dispatch_and_notice_errors_with_newrelic
  end
end

#newrelic_request_headersObject

Define Request Header accessor for Sinatra



67
68
69
# File 'lib/new_relic/agent/instrumentation/sinatra.rb', line 67

def newrelic_request_headers
  request.env
end