Skip to content

Commit

Permalink
Improved support for Camping framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Kayser committed Mar 5, 2010
1 parent dad1d1a commit 4f58aa3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Version 1.0.2

Improved Camping support

* Version 1.0.1

Removed DelayedJob, put back in core agent
Expand Down
12 changes: 12 additions & 0 deletions lib/new_relic/control/camping.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'new_relic/control/ruby'
# This is the framework control object for Camping apps.
# It is loaded by virtue of detecting 'camping' as the framework
# in the rpm_contrib/detection/camping.rb file. It gets loaded
# by the new_relic/control.rb file.
class NewRelic::Control::Camping < NewRelic::Control::Ruby
def init_config(options)
super
@local_env.dispatcher = 'camping'
self['app_name'] ||= 'Camping Application'
end
end
23 changes: 23 additions & 0 deletions lib/rpm_contrib/detection/camping.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Detect when running under camping and set the framework and dispatcher.

module NewRelic
class LocalEnvironment
module Camping
def discover_framework
if defined?(::Camping)
puts "framework is camping"
@framework = 'camping'
else
super
end
end
def discover_dispatcher
super
if defined?(::Camping) && @dispatcher.nil?
@dispatcher = 'camping'
end
end
end
end
end

55 changes: 17 additions & 38 deletions lib/rpm_contrib/instrumentation/camping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,33 @@ module RPMContrib
module Instrumentation
# == Instrumentation for Camping
# To instrument all controllers do the following:
# 1. Add the necessary NewRelic-specific requires in your require section
# 1. Add require 'rpm_contrib' after loading camping.
# 2. Add an include at the end of your main Camping app module
# 3. Add a call to NewRelic::Agent.manual_start at the end of the file to start the agent
# 4. Run the following command to get the NewRelic license key to use: heroku config -all
# 5. Create a newrelic.yml under the /config folder with the following content:
# 3. Run the following command to get the NewRelic license key to use: heroku config -all
# 4. Create a newrelic.yml under the /config folder with the following content:
#
# common: &default_settings
# license_key: 'PASTE THE VALUE OF NEW_RELIC_LICENSE_KEY HERE'
# agent_enabled: true
# app_name: PASTE THE NAME OF YOUR CAMPING APP HERE
# enabled: true
# common: &default_settings
# license_key: 'PASTE THE VALUE OF NEW_RELIC_LICENSE_KEY HERE'
# app_name: PASTE THE NAME OF YOUR CAMPING APP HERE
# monitor_mode: true
#
# production:
# <<: *default_settings
# enabled: true
# production:
# <<: *default_settings
#
# Camping code example:
# -------------------------------------------------------------------------------------
#
# Camping code example:
# --------------------------------------------------------------------------------------
# require "newrelic_rpm"
# require 'new_relic/agent/agent'
# require 'new_relic/agent/instrumentation/controller_instrumentation'
# require 'new_relic/agent/instrumentation/camping'
#
# Camping.goes :NewRelicCampingTest
#
# module NewRelicCampingTest
# # your code
# # your code
#
# include NewRelic::Agent::Instrumentation::Camping
#
# include NewRelic::Agent::Instrumentation::ControllerInstrumentation
# include NewRelic::Agent::Instrumentation::Camping
# end
#
# NewRelic::Agent.manual_start
#

module Camping
Expand All @@ -49,23 +43,8 @@ def self.included(mod)
# we need to evaluate "weld" the NewRelic plugin in the context of the new Base

(Kernel.const_get(mod.name)::Base).module_eval do

# Add the new method to the Camping app's Base module
# since the Camping::Base module is being included
# in every Camping controller

def service_with_newrelic(*args)
perform_action_with_newrelic_trace(:category => :rack) do
service_without_newrelic(*args)
end
end

# Alias the "standard" service method
# so we can provide a level of indirection
# to perform the tracing for NewRelic

alias service_without_newrelic service
alias service service_with_newrelic
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
add_transaction_tracer :service
end
end

Expand Down

0 comments on commit 4f58aa3

Please sign in to comment.