Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

New instrumentation #8

Merged
merged 2 commits into from

3 participants

@kmullin

opening pull request for visibility.

Commits amend an already Open Pull request #6

without the attached changes, this gem doesn't report metrics to NewRelic.

Env:

  • Rails 2.3
  • Ruby 1.9.3
  • newrelic_rpm (3.5.0.1)
@evanphx evanphx merged commit add0b28 into evanphx:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 14, 2012
  1. @marcelow
Commits on Oct 29, 2012
  1. @kmullin
This page is out of date. Refresh to see the latest.
Showing with 72 additions and 65 deletions.
  1. +72 −65 lib/newrelic_redis/instrumentation.rb
View
137 lib/newrelic_redis/instrumentation.rb
@@ -1,87 +1,94 @@
require 'new_relic/agent/method_tracer'
-require 'redis'
# Redis instrumentation.
# Originally contributed by Ashley Martens of ngmoco
# Rewritten, reorganized, and repackaged by Evan Phoenix
-load_probes =
- !NewRelic::Control.instance['disable_redis'] &&
- ENV['NEWRELIC_ENABLE'].to_s !~ /false|off|no/i
+DependencyDetection.defer do
+ @name = :redis
-# load_probes checked as a post condition
-::Redis::Client.class_eval do
-
- include NewRelic::Agent::MethodTracer
-
- # Support older versions of Redis::Client that used the method
- # +raw_call_command+.
-
- call_method =
- ::Redis::Client.new.respond_to?(:call) ? :call : :raw_call_command
+ depends_on do
+ defined?(::Redis) &&
+ !NewRelic::Control.instance['disable_redis'] &&
+ ENV['NEWRELIC_ENABLE'].to_s !~ /false|off|no/i
+ end
- def call_with_newrelic_trace(*args, &blk)
- if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
- total_metric = 'Database/Redis/allWeb'
- else
- total_metric = 'Database/Redis/allOther'
- end
+ executes do
+ NewRelic::Agent.logger.debug 'Installing Redis Instrumentation'
+ end
- method_name = args[0].is_a?(Array) ? args[0][0] : args[0]
- metrics = ["Database/Redis/#{method_name.to_s.upcase}", total_metric]
+ executes do
+ ::Redis::Client.class_eval do
+ # Support older versions of Redis::Client that used the method
+ # +raw_call_command+.
- self.class.trace_execution_scoped(metrics) do
- start = Time.now
+ call_method = ::Redis::Client.new.respond_to?(:call) ? :call : :raw_call_command
- begin
- call_without_newrelic_trace(*args, &blk)
- ensure
- s = NewRelic::Agent.instance.transaction_sampler
- s.notice_nosql(args.inspect, (Time.now - start).to_f) rescue nil
- end
- end
- end
-
- alias_method :call_without_newrelic_trace, call_method
- alias_method call_method, :call_with_newrelic_trace
-
- # Older versions of Redis handle pipelining completely differently.
- # Don't bother supporting them for now.
- #
- if public_method_defined? :call_pipelined
- def call_pipelined_with_newrelic_trace(commands, *rest)
- if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
- total_metric = 'Database/Redis/allWeb'
- else
- total_metric = 'Database/Redis/allOther'
- end
+ def call_with_newrelic_trace(*args, &blk)
+ if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
+ total_metric = 'Database/Redis/allWeb'
+ else
+ total_metric = 'Database/Redis/allOther'
+ end
- # Report each command as a metric under pipelined, so the user
- # can at least see what all the commands were. This prevents
- # metric namespace explosion.
+ method_name = args[0].is_a?(Array) ? args[0][0] : args[0]
+ metrics = ["Database/Redis/#{method_name.to_s.upcase}", total_metric]
- metrics = ["Database/Redis/Pipelined", total_metric]
+ self.class.trace_execution_scoped(metrics) do
+ start = Time.now
- commands.each do |c|
- name = c.kind_of?(Array) ? c[0] : c
- metrics << "Database/Redis/Pipelined/#{name.to_s.upcase}"
+ begin
+ call_without_newrelic_trace(*args, &blk)
+ ensure
+ s = NewRelic::Agent.instance.transaction_sampler
+ s.notice_nosql(args.inspect, (Time.now - start).to_f) rescue nil
+ end
+ end
end
- self.class.trace_execution_scoped(metrics) do
- start = Time.now
-
- begin
- call_pipelined_without_newrelic_trace commands, *rest
- ensure
- s = NewRelic::Agent.instance.transaction_sampler
- s.notice_nosql(commands.inspect, (Time.now - start).to_f) rescue nil
+ alias_method :call_without_newrelic_trace, call_method
+ alias_method call_method, :call_with_newrelic_trace
+
+ # Older versions of Redis handle pipelining completely differently.
+ # Don't bother supporting them for now.
+ #
+ if public_method_defined? :call_pipelined
+ def call_pipelined_with_newrelic_trace(commands, *rest)
+ if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
+ total_metric = 'Database/Redis/allWeb'
+ else
+ total_metric = 'Database/Redis/allOther'
+ end
+
+ # Report each command as a metric under pipelined, so the user
+ # can at least see what all the commands were. This prevents
+ # metric namespace explosion.
+
+ metrics = ["Database/Redis/Pipelined", total_metric]
+
+ commands.each do |c|
+ name = c.kind_of?(Array) ? c[0] : c
+ metrics << "Database/Redis/Pipelined/#{name.to_s.upcase}"
+ end
+
+ self.class.trace_execution_scoped(metrics) do
+ start = Time.now
+
+ begin
+ call_pipelined_without_newrelic_trace commands, *rest
+ ensure
+ s = NewRelic::Agent.instance.transaction_sampler
+ s.notice_nosql(commands.inspect, (Time.now - start).to_f) rescue nil
+ end
+ end
end
+
+ alias_method :call_pipelined_without_newrelic_trace, :call_pipelined
+ alias_method :call_pipelined, :call_pipelined_with_newrelic_trace
end
end
+ end
+end
- alias_method :call_pipelined_without_newrelic_trace, :call_pipelined
- alias_method :call_pipelined, :call_pipelined_with_newrelic_trace
- end
-end if load_probes
Something went wrong with that request. Please try again.