Skip to content

Commit

Permalink
fix constant scoping when defining modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin George committed Feb 10, 2010
1 parent 40b4ada commit 6974677
Show file tree
Hide file tree
Showing 21 changed files with 155 additions and 88 deletions.
4 changes: 3 additions & 1 deletion lib/new_relic/agent/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
# The NewRelic Agent collects performance data from ruby applications
# in realtime as the application runs, and periodically sends that
# data to the NewRelic server.
module NewRelic::Agent
module NewRelic
module Agent

# The Agent is a singleton that is instantiated when the plugin is
# activated.
Expand Down Expand Up @@ -636,3 +637,4 @@ def default_sql_obfuscator(sql)
end

end
end
9 changes: 7 additions & 2 deletions lib/new_relic/agent/busy_calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
# span the minute boundaries. This module manages accounting of requests not yet
# completed.
#
# Calls are re-entrant. All start calls must be paired with finish calls, or a reset call.
module NewRelic::Agent::BusyCalculator
# Calls are re-entrant. All start calls must be paired with finish
# calls, or a reset call.
module NewRelic
module Agent
module BusyCalculator

extend self

Expand Down Expand Up @@ -84,3 +87,5 @@ def instance_busy_stats
end

end
end
end
6 changes: 5 additions & 1 deletion lib/new_relic/agent/collection_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module NewRelic::Agent::CollectionHelper
module NewRelic
module Agent
module CollectionHelper
# Transform parameter hash into a hash whose values are strictly
# strings
def normalize_params(params)
Expand Down Expand Up @@ -64,3 +66,5 @@ def truncate(string, len=256)
end
end
end
end
end
6 changes: 4 additions & 2 deletions lib/new_relic/agent/error_collector.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

module NewRelic::Agent
module NewRelic
module Agent
class ErrorCollector
include CollectionHelper

Expand Down Expand Up @@ -114,4 +115,5 @@ def log
NewRelic::Control.instance.log
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

module NewRelic::Agent::Instrumentation
module NewRelic
module Agent
module Instrumentation
# == NewRelic instrumentation for controllers
#
# This instrumentation is applied to the action controller by default if the agent
Expand Down Expand Up @@ -384,3 +386,5 @@ def _dispatch_stat

end
end
end
end
26 changes: 17 additions & 9 deletions lib/new_relic/agent/instrumentation/delayed_job_instrumentation.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
require 'new_relic/agent/instrumentation/controller_instrumentation'

module NewRelic::Agent::Instrumentation::DelayedJobInstrumentation
if defined?(Delayed::Job)
module NewRelic
module Agent
module Instrumentation
module DelayedJobInstrumentation

Delayed::Job.class_eval do
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
if self.instance_methods.include?('name')
add_transaction_tracer "invoke_job", :category => 'OtherTransaction/DelayedJob', :path => '#{self.name}'
else
add_transaction_tracer "invoke_job", :category => 'OtherTransaction/DelayedJob'
Delayed::Job.class_eval do
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
if self.instance_methods.include?('name')
add_transaction_tracer "invoke_job", :category => 'OtherTransaction/DelayedJob', :path => '#{self.name}'
else
add_transaction_tracer "invoke_job", :category => 'OtherTransaction/DelayedJob'
end
end

end
end
end
end

end if defined?(Delayed::Job)
end
74 changes: 40 additions & 34 deletions lib/new_relic/agent/instrumentation/sinatra.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,45 @@
module NewRelic::Agent::Instrumentation
# 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.
module Sinatra

include NewRelic::Agent::Instrumentation::ControllerInstrumentation

def route_eval_with_newrelic(&block_arg)
path = unescape(@request.path_info)
name = path
# Go through each route and look for a match
if routes = self.class.routes[@request.request_method]
routes.detect do |pattern, keys, conditions, block|
if block_arg.equal? block
name = pattern.source
if defined?(Sinatra::Base)
module NewRelic
module Agent
module Instrumentation
# 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.
module Sinatra

include NewRelic::Agent::Instrumentation::ControllerInstrumentation

def route_eval_with_newrelic(&block_arg)
path = unescape(@request.path_info)
name = path
# Go through each route and look for a match
if routes = self.class.routes[@request.request_method]
routes.detect do |pattern, keys, conditions, block|
if block_arg.equal? block
name = pattern.source
end
end
end
# strip of leading ^ and / chars and trailing $ and /
name.gsub!(%r{^[/^]*(.*?)[/\$]*$}, '\1')
name = 'root' if name.empty?
perform_action_with_newrelic_trace(:category => :sinatra, :name => name) do
route_eval_without_newrelic(&block_arg)
end
end
end
end
# strip of leading ^ and / chars and trailing $ and /
name.gsub!(%r{^[/^]*(.*?)[/\$]*$}, '\1')
name = 'root' if name.empty?
perform_action_with_newrelic_trace(:category => :sinatra, :name => name) do
route_eval_without_newrelic(&block_arg)

::Sinatra::Base.class_eval do
include NewRelic::Agent::Instrumentation::Sinatra
alias route_eval_without_newrelic route_eval
alias route_eval route_eval_with_newrelic
end

end
end
end

::Sinatra::Base.class_eval do
include NewRelic::Agent::Instrumentation::Sinatra
alias route_eval_without_newrelic route_eval
alias route_eval route_eval_with_newrelic
end

end if defined?(Sinatra::Base)
end
4 changes: 3 additions & 1 deletion lib/new_relic/agent/method_tracer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'new_relic/control'
module NewRelic::Agent
module NewRelic
module Agent
# This module contains class methods added to support installing custom
# metric tracers and executing for individual metrics.
#
Expand Down Expand Up @@ -346,3 +347,4 @@ def _sanitize_name(name)
end
end
end
end
6 changes: 5 additions & 1 deletion lib/new_relic/agent/samplers/cpu_sampler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module NewRelic::Agent::Samplers
module NewRelic
module Agent
module Samplers
class CpuSampler < NewRelic::Agent::Sampler
attr_reader :last_time
def initialize
Expand Down Expand Up @@ -47,4 +49,6 @@ def poll
end
end
end
end
end

6 changes: 5 additions & 1 deletion lib/new_relic/agent/samplers/delayed_job_lock_sampler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module NewRelic::Agent::Samplers
module NewRelic
module Agent
module Samplers
class DelayedJobLockSampler < NewRelic::Agent::Sampler
def initialize
super :delayed_job_lock
Expand Down Expand Up @@ -29,3 +31,5 @@ def poll
end
end
end
end
end
6 changes: 5 additions & 1 deletion lib/new_relic/agent/samplers/memory_sampler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module NewRelic::Agent::Samplers
module NewRelic
module Agent
module Samplers

class MemorySampler < NewRelic::Agent::Sampler
attr_accessor :sampler
Expand Down Expand Up @@ -139,3 +141,5 @@ def to_s
end
end
end
end
end
8 changes: 6 additions & 2 deletions lib/new_relic/agent/samplers/mongrel_sampler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module NewRelic::Agent::Samplers
module NewRelic
module Agent
module Samplers
# NewRelic Instrumentation for Mongrel - tracks the queue length of the mongrel server.
class MongrelSampler < NewRelic::Agent::Sampler
def initialize
Expand All @@ -20,4 +22,6 @@ def poll
end
end
end
end
end
end
end
32 changes: 17 additions & 15 deletions lib/new_relic/agent/stats_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
require 'new_relic/agent/stats_engine/samplers'
require 'new_relic/agent/stats_engine/transactions'

module NewRelic::Agent
class StatsEngine
include MetricStats
include Samplers
include Transactions

def initialize
# Makes the unit tests happy
Thread::current[:newrelic_scope_stack] = nil
spawn_sampler_thread
module NewRelic
module Agent
class StatsEngine
include MetricStats
include Samplers
include Transactions

def initialize
# Makes the unit tests happy
Thread::current[:newrelic_scope_stack] = nil
spawn_sampler_thread
end

def log
NewRelic::Control.instance.log
end

end

def log
NewRelic::Control.instance.log
end

end
end
4 changes: 3 additions & 1 deletion lib/new_relic/agent/stats_engine/metric_stats.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module NewRelic::Agent
module NewRelic
module Agent
class StatsEngine
module MetricStats
# The stats hash hashes either a metric name for an unscoped metric,
Expand Down Expand Up @@ -114,3 +115,4 @@ def stats_hash
end
end
end
end
4 changes: 3 additions & 1 deletion lib/new_relic/agent/stats_engine/samplers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module NewRelic::Agent
module NewRelic
module Agent
class StatsEngine
module Shim # :nodoc:
def add_sampler(*args); end
Expand Down Expand Up @@ -72,3 +73,4 @@ def periodic_samplers
end
end
end
end
4 changes: 3 additions & 1 deletion lib/new_relic/agent/stats_engine/transactions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module NewRelic::Agent
module NewRelic
module Agent
class StatsEngine

# Defines methods that stub out the stats engine methods
Expand Down Expand Up @@ -145,3 +146,4 @@ def scope_stack
end
end
end
end
5 changes: 3 additions & 2 deletions lib/new_relic/agent/transaction_sampler.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

module NewRelic::Agent
module NewRelic
module Agent

class TransactionSampler

Expand Down Expand Up @@ -313,3 +313,4 @@ def sample

end
end
end
4 changes: 3 additions & 1 deletion lib/new_relic/agent/worker_loop.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module NewRelic::Agent
module NewRelic
module Agent

# A worker loop executes a set of registered tasks on a single thread.
# A task is a proc or block with a specified call period in seconds.
Expand Down Expand Up @@ -115,3 +116,4 @@ def execute
end
end
end
end
16 changes: 9 additions & 7 deletions lib/new_relic/metrics.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module NewRelic::Metrics
CONTROLLER = "Controller"
DISPATCHER = "HttpDispatcher"
ACTIVE_RECORD = "ActiveRecord"
USER_TIME = "CPU/User Time"
MEMORY = "Memory/Physical"
end
module NewRelic
module Metrics
CONTROLLER = "Controller"
DISPATCHER = "HttpDispatcher"
ACTIVE_RECORD = "ActiveRecord"
USER_TIME = "CPU/User Time"
MEMORY = "Memory/Physical"
end
end
6 changes: 4 additions & 2 deletions lib/new_relic/rack/metric_app.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'fileutils'
module NewRelic::Rack
module NewRelic
module Rack
class MetricApp
def initialize(options)
if options[:install]
Expand Down Expand Up @@ -53,4 +54,5 @@ def call(env)
response.finish
end
end
end
end
end
Loading

0 comments on commit 6974677

Please sign in to comment.