ghazel-rpm_contrib 1.0.13.1 → 1.0.13.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ if defined?(::Curl) and not NewRelic::Control.instance['disable_curb']
2
+ Curl::Easy.class_eval do
3
+ def host
4
+ URI.parse(self.url).host
5
+ end
6
+
7
+ # TODO: http, http_delete, http_get, http_post, http_head, http_put
8
+ def perform_with_newrelic_trace(*args, &block)
9
+ metrics = ["External/#{host}/Curl::Easy","External/#{host}/all"]
10
+ if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
11
+ metrics << "External/allWeb"
12
+ else
13
+ metrics << "External/allOther"
14
+ end
15
+ self.class.trace_execution_scoped metrics do
16
+ perform_without_newrelic_trace(*args, &block)
17
+ end
18
+ end
19
+ alias perform_without_newrelic_trace perform
20
+ alias perform perform_with_newrelic_trace
21
+ end
22
+
23
+ Curl::Multi.class_eval do
24
+ # TODO: http
25
+ def perform_with_newrelic_trace(*args, &block)
26
+ metrics = ["External/Curl::Multi"]
27
+ if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
28
+ metrics << "External/allWeb"
29
+ else
30
+ metrics << "External/allOther"
31
+ end
32
+ self.class.trace_execution_scoped metrics do
33
+ perform_without_newrelic_trace(*args, &block)
34
+ end
35
+ end
36
+ alias perform_without_newrelic_trace perform
37
+ alias perform perform_with_newrelic_trace
38
+ end
39
+ end
data/test/test_curb.rb ADDED
@@ -0,0 +1,66 @@
1
+ require "#{File.dirname(__FILE__)}/helper"
2
+ require 'curb'
3
+
4
+ class NewRelic::Agent::NetInstrumentationTest < Test::Unit::TestCase
5
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
6
+ def setup
7
+ NewRelic::Agent.manual_start
8
+ @engine = NewRelic::Agent.instance.stats_engine
9
+ @engine.clear_stats
10
+ end
11
+ def test_get
12
+ curl = Curl::Easy.new('http://www.google.com/index.html')
13
+ curl.perform
14
+ assert_match /<head>/, curl.body_str
15
+ assert_equal %w[External/www.google.com/Curl::Easy External/Curl::Multi
16
+ External/allOther External/www.google.com/all].sort,
17
+ @engine.metrics.sort
18
+ end
19
+
20
+ def test_multi
21
+ multi = Curl::Multi.new
22
+ curl1 = Curl::Easy.new('http://www.google.com/index.html')
23
+ multi.add curl1
24
+ curl2 = Curl::Easy.new('http://www.yahoo.com/')
25
+ multi.add curl2
26
+ multi.perform
27
+ assert_match /<head>/, curl1.body_str
28
+ assert_match /<head>/, curl2.body_str
29
+ assert_equal %w[External/Curl::Multi External/allOther].sort,
30
+ @engine.metrics.sort
31
+ end
32
+
33
+ def test_background
34
+ perform_action_with_newrelic_trace("task", :category => :task) do
35
+ curl = Curl::Easy.new('http://www.google.com/index.html')
36
+ curl.perform
37
+ assert_match /<head>/, curl.body_str
38
+ end
39
+ assert_equal %w[External/Curl::Multi
40
+ External/Curl::Multi:OtherTransaction/Background/NewRelic::Agent::NetInstrumentationTest/task
41
+ External/www.google.com/Curl::Easy External/allOther External/www.google.com/all
42
+ External/www.google.com/Curl::Easy:OtherTransaction/Background/NewRelic::Agent::NetInstrumentationTest/task].sort,
43
+ @engine.metrics.select{|m| m =~ /^External/}.sort
44
+ end
45
+
46
+ def test_transactional
47
+ perform_action_with_newrelic_trace("task") do
48
+ curl = Curl::Easy.new('http://www.google.com/index.html')
49
+ curl.perform
50
+ assert_match /<head>/, curl.body_str
51
+ end
52
+ assert_equal %w[External/Curl::Multi
53
+ External/Curl::Multi:Controller/NewRelic::Agent::NetInstrumentationTest/task
54
+ External/www.google.com/Curl::Easy External/allWeb External/www.google.com/all
55
+ External/www.google.com/Curl::Easy:Controller/NewRelic::Agent::NetInstrumentationTest/task].sort,
56
+ @engine.metrics.select{|m| m =~ /^External/}.sort
57
+ end
58
+ def test_ignore
59
+ NewRelic::Agent.disable_all_tracing do
60
+ curl = Curl::Easy.new('http://www.google.com/index.html')
61
+ curl.http_post('data')
62
+ end
63
+ assert_equal 0, @engine.metrics.size
64
+ end
65
+
66
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghazel-rpm_contrib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.13.1
4
+ version: 1.0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill Kayser
@@ -47,6 +47,7 @@ files:
47
47
  - lib/rpm_contrib/instrumentation/aws/s3.rb
48
48
  - lib/rpm_contrib/instrumentation/camping.rb
49
49
  - lib/rpm_contrib/instrumentation/cassandra.rb
50
+ - lib/rpm_contrib/instrumentation/curb.rb
50
51
  - lib/rpm_contrib/instrumentation/mongo_mapper.rb
51
52
  - lib/rpm_contrib/instrumentation/mongoid.rb
52
53
  - lib/rpm_contrib/instrumentation/paperclip.rb
@@ -93,5 +94,6 @@ summary: Contributed Instrumentation for New Relic RPM
93
94
  test_files:
94
95
  - test/helper.rb
95
96
  - test/schema.rb
97
+ - test/test_curb.rb
96
98
  - test/test_mongoid.rb
97
99
  - test/test_redis.rb