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.4'
REVISION =

Version-control revision constant

%q$Revision: 569685399b6a $

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
67
68
# 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

	super
end

Instance Method Details

#handle_request(request) ⇒ Object

Mark and time the app.



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
121
122
# File 'lib/strelka/app/newrelic.rb', line 93

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

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

	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',
	}
	return self.perform_action_with_newrelic_trace( options ) do
		super
	end

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

#make_route_name(route) ⇒ Object

Make a normalized transaction name from the specified route.



126
127
128
129
# File 'lib/strelka/app/newrelic.rb', line 126

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

#runObject

Set up the NewRelic agent.



72
73
74
75
# File 'lib/strelka/app/newrelic.rb', line 72

def run( * )
	self.start_newrelic_agent
	super
end

#start_newrelic_agentObject

Starts the New Relic agent in a background thread.



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/strelka/app/newrelic.rb', line 79

def start_newrelic_agent
	options     = {
		framework: :ruby,
		dispatcher: :strelka
	}

	self.log.info "Starting the NewRelic agent with options: %p." % [ options ]
	NewRelic::Agent.manual_start( options )

	return self
end