Module: Strelka::App::NewRelic

Extended by:
Configurability, Plugin
Includes:
NewRelic::Agent::Instrumentation::ControllerInstrumentation
Defined in:
lib/strelka/app/newrelic.rb

Overview

Strelka::App plugin module for reporting application performance to New Relic.

Constant Summary collapse

VERSION =

Library version constant

'0.0.1'
REVISION =

Version-control revision constant

%q$Revision: 16e6c9702fe8 $

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configure(config = nil) ⇒ Object

Configurability API – configure this class with the appropriate section of the universal config when it’s installed.



57
58
59
60
61
62
63
64
65
66
# File 'lib/strelka/app/newrelic.rb', line 57

def self::configure( config=nil )
	if config
		logger = Loggability[ NewRelic ]
		ra_logger = NewRelic::Agent::AgentLogger.new( {:log_level => 'debug'}, '', logger )
		NewRelic::Agent.logger = ra_logger

		self.log.info "Applying NewRelic config: %p" % [ config.to_hash ]
		NewRelic::Agent.config.apply_config( config.to_hash, 1 )
	end
end

Instance Method Details

#handle_request(request) ⇒ Object

Mark and time the app.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/strelka/app/newrelic.rb', line 89

def handle_request( request )
	self.log.debug "[:newrelic] Instrumenting with NewRelic."

	txname = if !request.notes[:routing][:route].empty?
			note = request.notes[:routing][:route]
			self.log.debug "Making route name out of the route notes: %p" % [ note ]
			self.make_route_name( note )
		else
			self.log.debug "Making route name out of the verb (%p) and app path (%p)" %
				[ request.verb, request.app_path ]
				"handle_request"
		end

	options = {
		name:     txname.to_s,
		request:  request,
		category: 'Controller/Strelka',
	}
	response = self.perform_action_with_newrelic_trace( options ) do
		super
	end

	response.notes[:rum_header] = NewRelic::Agent.browser_timing_header
	response.notes[:rum_footer] = NewRelic::Agent.browser_timing_footer

	self.log.debug "  response notes: %p" % [ response.notes ]

	return response
rescue => err
	NewRelic::Agent.notice_error( err.message )
	raise
end

#make_route_name(route) ⇒ Object

Make a normalized transaction name from the specified route.



124
125
126
127
# File 'lib/strelka/app/newrelic.rb', line 124

def make_route_name( route )
	action_method = route[:action] or return '(Unknown)'
	return action_method.name
end

#runObject

Set up the NewRelic agent.



70
71
72
73
# File 'lib/strelka/app/newrelic.rb', line 70

def run( * )
	self.start_newrelic_agent
	super
end

#start_newrelic_agentObject

Starts the New Relic agent in a background thread.



77
78
79
80
81
82
83
84
85
# File 'lib/strelka/app/newrelic.rb', line 77

def start_newrelic_agent
	environment = if self.class.in_devmode? then 'development' else 'production' end
	options     = { env: environment, dispatcher: :strelka }

	self.log.info "Starting the NewRelic agent."
	NewRelic::Agent.manual_start( options )

	return self
end