newrelic-httpclient 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ log/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1,7 @@
1
+ script: "bundle exec ruby test/test_newrelic_httpclient.rb"
2
+
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - ruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in newrelic_httpclient.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Yuki Nishijima
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # NewRelic instrumentation for HTTPClient
2
+
3
+ **`newrelic-httpclient`** allows transactions to show time spent inside httpclient requests.
4
+
5
+ [![Build Status](https://travis-ci.org/yuki24/newrelic-httpclient.png?branch=master)](https://travis-ci.org/yuki24/newrelic-httpclient)
6
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/yuki24/newrelic-httpclient)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'newrelic-httpclient'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install newrelic-httpclient
21
+
22
+ ## Todo
23
+
24
+ * Allow to show time spent inside asynchronous requests
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
33
+
34
+ ## Copyright
35
+ Copyright (c) 2012 Yuki Nishijima. See LICENSE.md for further details.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require 'newrelic_httpclient/instrumentation'
2
+ require 'newrelic_httpclient/version'
@@ -0,0 +1,35 @@
1
+ require 'new_relic/agent/method_tracer'
2
+
3
+ DependencyDetection.defer do
4
+ @name = :httpclient
5
+
6
+ depends_on do
7
+ defined?(::HTTPClient) &&
8
+ !NewRelic::Control.instance['disable_httpclient'] &&
9
+ ENV['NEWRELIC_ENABLE'].to_s !~ /false|off|no/i
10
+ end
11
+
12
+ executes do
13
+ NewRelic::Agent.logger.debug 'Installing HTTPClient Instrumentation'
14
+ end
15
+
16
+ executes do
17
+ ::HTTPClient.class_eval do
18
+ def do_get_block_with_newrelic_trace(req, proxy, conn, &block)
19
+ host = req.http_header.request_uri.host
20
+ method = req.http_header.request_method
21
+ metrics = ["External/#{host}/HTTPClient/#{method}", "External/#{host}/all", "External/all"]
22
+ if NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction?
23
+ metrics << "External/allWeb"
24
+ else
25
+ metrics << "External/allOther"
26
+ end
27
+ self.class.trace_execution_scoped metrics do
28
+ do_get_block_without_newrelic_trace(req, proxy, conn, &block)
29
+ end
30
+ end
31
+ alias do_get_block_without_newrelic_trace do_get_block
32
+ alias do_get_block do_get_block_with_newrelic_trace
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module NewrelicHttpclient
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'newrelic_httpclient/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "newrelic-httpclient"
8
+ gem.version = NewrelicHttpclient::VERSION
9
+ gem.authors = ["Yuki Nishijima"]
10
+ gem.email = ["mail@yukinishijima.net"]
11
+ gem.description = %q{newrelic-httpclient allows transactions to show time spent inside httpclient requests}
12
+ gem.summary = %q{NewRelic instrumentation for HttpClient}
13
+ gem.homepage = "https://github.com/yuki24/newrelic-httpclient"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "newrelic_rpm"
21
+ gem.add_development_dependency "httpclient"
22
+ end
@@ -0,0 +1,48 @@
1
+ require 'test/unit'
2
+ require 'httpclient'
3
+ require 'newrelic/httpclient'
4
+
5
+ class TestNewRelicHttpclient < Test::Unit::TestCase
6
+ include NewRelic::Agent::Instrumentation::ControllerInstrumentation
7
+
8
+ def setup
9
+ NewRelic::Agent.manual_start
10
+ @engine = NewRelic::Agent.instance.stats_engine
11
+ @engine.clear_stats
12
+
13
+ @client = HTTPClient.new
14
+ end
15
+
16
+ def assert_metrics(*m)
17
+ m.each do |x|
18
+ assert @engine.metrics.include?(x), "#{x} not in metrics"
19
+ end
20
+ end
21
+
22
+ def test_get
23
+ response = @client.get("http://www.google.com/index.html")
24
+
25
+ assert_match /<head>/i, response.body
26
+ assert_metrics "External/all",
27
+ "External/www.google.com/HTTPClient/GET",
28
+ "External/allOther",
29
+ "External/www.google.com/all"
30
+ end
31
+
32
+ def test_post
33
+ response = @client.post("http://www.google.com/index.html")
34
+
35
+ assert_metrics "External/all",
36
+ "External/www.google.com/HTTPClient/POST",
37
+ "External/allOther",
38
+ "External/www.google.com/all"
39
+ end
40
+
41
+ def test_ignore
42
+ NewRelic::Agent.disable_all_tracing do
43
+ @client.get("http://www.google.com/index.html")
44
+ end
45
+
46
+ assert_equal 0, @engine.metrics.size
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: newrelic-httpclient
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yuki Nishijima
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: newrelic_rpm
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: httpclient
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: newrelic-httpclient allows transactions to show time spent inside httpclient
47
+ requests
48
+ email:
49
+ - mail@yukinishijima.net
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .travis.yml
56
+ - Gemfile
57
+ - LICENSE.md
58
+ - README.md
59
+ - Rakefile
60
+ - lib/newrelic/httpclient.rb
61
+ - lib/newrelic_httpclient/instrumentation.rb
62
+ - lib/newrelic_httpclient/version.rb
63
+ - newrelic-httpclient.gemspec
64
+ - test/test_newrelic_httpclient.rb
65
+ homepage: https://github.com/yuki24/newrelic-httpclient
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.24
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: NewRelic instrumentation for HttpClient
89
+ test_files:
90
+ - test/test_newrelic_httpclient.rb