net-http-instrumentation 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in net-http-instrumentation.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'newrelic_rpm'
8
+ gem 'sinatra'
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Felix Gilcher
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Net::Http::Instrumentation
2
+
3
+ Adds additional instrumentation for Net::HTTP. Currently adds detailed information about times spent in HTTP Requests in NewRelic transaction traces.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'net-http-instrumentation'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install net-http-instrumentation
18
+
19
+ ## Usage
20
+
21
+ Just require the instrumentation file after requiring net/http and newelic_prm. See the sample for details.
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ require "net-http-instrumentation/version"
2
+ require 'new_relic/agent/method_tracer'
3
+ require 'net/http' # we need to enforce that net/http is loaded before we rig the instrumentation
4
+
5
+
6
+ Net::HTTP.class_eval do
7
+ include NewRelic::Agent::MethodTracer
8
+ add_method_tracer :connect, 'Custom/Net/Http/connect', :metric => false
9
+ end
10
+
11
+ Net::HTTPGenericRequest.class_eval do
12
+ include NewRelic::Agent::MethodTracer
13
+ add_method_tracer :exec, 'Custom/Net/Http/HTTPGenericRequest/exec', :metric => false
14
+ end
15
+
16
+ Net::HTTPResponse.class_eval do
17
+ include NewRelic::Agent::MethodTracer
18
+ add_method_tracer :read_body, 'Custom/Net/Http/HTTPResponse/read_body', :metric => false
19
+ end
@@ -0,0 +1,7 @@
1
+ module Net
2
+ module Http
3
+ module Instrumentation
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/net-http-instrumentation/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Felix Gilcher"]
6
+ gem.email = ["felix.gilcher@asquera.de"]
7
+ gem.description = %q{Provide some instrumentation for Net::HTTP}
8
+ gem.summary = %q{Provide some instrumentation for Net::HTTP}
9
+ gem.homepage = "https://github.com/Asquera/net-http-instrumentation"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "net-http-instrumentation"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Net::Http::Instrumentation::VERSION
17
+ end
data/test/app.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'sinatra'
2
+ require 'net/http'
3
+ require 'newrelic_rpm'
4
+ require 'cgi'
5
+ require 'new_relic/rack/developer_mode'
6
+ require 'net/http/instrumentation/newrelic_rpm'
7
+
8
+ use NewRelic::Rack::DeveloperMode
9
+
10
+ get '/test' do
11
+ res = Net::HTTP.get('www.google.com', '/')
12
+ res
13
+ end
data/test/log/.gitkeep ADDED
File without changes
data/test/newrelic.yml ADDED
@@ -0,0 +1,265 @@
1
+ #
2
+ # This file configures the New Relic Ruby Agent, New Relic monitors
3
+ # Rails applications with deep visibility and low overhead. For more
4
+ # information, visit www.newrelic.com
5
+ #
6
+ # Generated July 23, 2012, for version 3.4.0.1
7
+ #
8
+ #
9
+
10
+
11
+ # Here are the settings that are common to all environments
12
+ common: &default_settings
13
+ # ============================== LICENSE KEY ===============================
14
+
15
+ # You must specify the license key associated with your New Relic
16
+ # account. This key binds your Agent's data to your account in the
17
+ # New Relic service.
18
+ license_key: '<PASTE LICENSE KEY HERE>'
19
+
20
+ # Agent Enabled (Rails Only)
21
+ # Use this setting to force the agent to run or not run.
22
+ # Default is 'auto' which means the agent will install and run only
23
+ # if a valid dispatcher such as Mongrel is running. This prevents
24
+ # it from running with Rake or the console. Set to false to
25
+ # completely turn the agent off regardless of the other settings.
26
+ # Valid values are true, false and auto.
27
+ #
28
+ # agent_enabled: auto
29
+
30
+ # Application Name Set this to be the name of your application as
31
+ # you'd like it show up in New Relic. The service will then auto-map
32
+ # instances of your application into an "application" on your
33
+ # dashboard page. If you want to map this instance into multiple
34
+ # apps, like "AJAX Requests" and "All UI" then specify a semicolon
35
+ # separated list of up to three distinct names, or a yaml list.
36
+ # Defaults to the capitalized RAILS_ENV or RACK_ENV (i.e.,
37
+ # Production, Staging, etc)
38
+ #
39
+ # Example:
40
+ #
41
+ # app_name:
42
+ # - Ajax Service
43
+ # - All Services
44
+ #
45
+ app_name: ["Sinatra Test App"]
46
+
47
+ # When "true", the agent collects performance data about your
48
+ # application and reports this data to the New Relic service at
49
+ # newrelic.com. This global switch is normally overridden for each
50
+ # environment below. (formerly called 'enabled')
51
+ monitor_mode: true
52
+
53
+ # Developer mode should be off in every environment but
54
+ # development as it has very high overhead in memory.
55
+ developer_mode: false
56
+
57
+ # The newrelic agent generates its own log file to keep its logging
58
+ # information separate from that of your application. Specify its
59
+ # log level here.
60
+ log_level: info
61
+
62
+ # Optionally set the path to the log file This is expanded from the
63
+ # root directory (may be relative or absolute, e.g. 'log/' or
64
+ # '/var/log/') The agent will attempt to create this directory if it
65
+ # does not exist.
66
+ # log_file_path: 'log'
67
+
68
+ # Optionally set the name of the log file, defaults to 'newrelic_agent.log'
69
+ # log_file_name: 'newrelic_agent.log'
70
+
71
+ # The newrelic agent communicates with the service via http by
72
+ # default. If you want to communicate via https to increase
73
+ # security, then turn on SSL by setting this value to true. Note,
74
+ # this will result in increased CPU overhead to perform the
75
+ # encryption involved in SSL communication, but this work is done
76
+ # asynchronously to the threads that process your application code,
77
+ # so it should not impact response times.
78
+ ssl: false
79
+
80
+ # EXPERIMENTAL: enable verification of the SSL certificate sent by
81
+ # the server. This setting has no effect unless SSL is enabled
82
+ # above. This may block your application. Only enable it if the data
83
+ # you send us needs end-to-end verified certificates.
84
+ #
85
+ # This means we cannot cache the DNS lookup, so each request to the
86
+ # service will perform a lookup. It also means that we cannot
87
+ # use a non-blocking lookup, so in a worst case, if you have DNS
88
+ # problems, your app may block indefinitely.
89
+ # verify_certificate: true
90
+
91
+ # Set your application's Apdex threshold value with the 'apdex_t'
92
+ # setting, in seconds. The apdex_t value determines the buckets used
93
+ # to compute your overall Apdex score.
94
+ # Requests that take less than apdex_t seconds to process will be
95
+ # classified as Satisfying transactions; more than apdex_t seconds
96
+ # as Tolerating transactions; and more than four times the apdex_t
97
+ # value as Frustrating transactions.
98
+ # For more about the Apdex standard, see
99
+ # http://newrelic.com/docs/general/apdex
100
+
101
+ apdex_t: 0.5
102
+
103
+ #============================== Browser Monitoring ===============================
104
+ # New Relic Real User Monitoring gives you insight into the performance real users are
105
+ # experiencing with your website. This is accomplished by measuring the time it takes for
106
+ # your users' browsers to download and render your web pages by injecting a small amount
107
+ # of JavaScript code into the header and footer of each page.
108
+ browser_monitoring:
109
+ # By default the agent automatically injects the monitoring JavaScript
110
+ # into web pages. Set this attribute to false to turn off this behavior.
111
+ auto_instrument: true
112
+
113
+ # Proxy settings for connecting to the service.
114
+ #
115
+ # If a proxy is used, the host setting is required. Other settings
116
+ # are optional. Default port is 8080.
117
+ #
118
+ # proxy_host: hostname
119
+ # proxy_port: 8080
120
+ # proxy_user:
121
+ # proxy_pass:
122
+
123
+
124
+ # Tells transaction tracer and error collector (when enabled)
125
+ # whether or not to capture HTTP params. When true, frameworks can
126
+ # exclude HTTP parameters from being captured.
127
+ # Rails: the RoR filter_parameter_logging excludes parameters
128
+ # Java: create a config setting called "ignored_params" and set it to
129
+ # a comma separated list of HTTP parameter names.
130
+ # ex: ignored_params: credit_card, ssn, password
131
+ capture_params: false
132
+
133
+
134
+ # Transaction tracer captures deep information about slow
135
+ # transactions and sends this to the service once a
136
+ # minute. Included in the transaction is the exact call sequence of
137
+ # the transactions including any SQL statements issued.
138
+ transaction_tracer:
139
+
140
+ # Transaction tracer is enabled by default. Set this to false to
141
+ # turn it off. This feature is only available at the Professional
142
+ # and above product levels.
143
+ enabled: true
144
+
145
+ # Threshold in seconds for when to collect a transaction
146
+ # trace. When the response time of a controller action exceeds
147
+ # this threshold, a transaction trace will be recorded and sent to
148
+ # the service. Valid values are any float value, or (default)
149
+ # "apdex_f", which will use the threshold for an dissatisfying
150
+ # Apdex controller action - four times the Apdex T value.
151
+ transaction_threshold: apdex_f
152
+
153
+ # When transaction tracer is on, SQL statements can optionally be
154
+ # recorded. The recorder has three modes, "off" which sends no
155
+ # SQL, "raw" which sends the SQL statement in its original form,
156
+ # and "obfuscated", which strips out numeric and string literals
157
+ record_sql: obfuscated
158
+
159
+ # Threshold in seconds for when to collect stack trace for a SQL
160
+ # call. In other words, when SQL statements exceed this threshold,
161
+ # then capture and send the current stack trace. This is
162
+ # helpful for pinpointing where long SQL calls originate from
163
+ stack_trace_threshold: 0.500
164
+
165
+ # Determines whether the agent will capture query plans for slow
166
+ # SQL queries. Only supported in mysql and postgres. Should be
167
+ # set to false when using other adapters.
168
+ # explain_enabled: true
169
+
170
+ # Threshold for query execution time below which query plans will not
171
+ # not be captured. Relevant only when `explain_enabled` is true.
172
+ # explain_threshold: 0.5
173
+
174
+ # Error collector captures information about uncaught exceptions and
175
+ # sends them to the service for viewing
176
+ error_collector:
177
+
178
+ # Error collector is enabled by default. Set this to false to turn
179
+ # it off. This feature is only available at the Professional and above
180
+ # product levels
181
+ enabled: true
182
+
183
+ # Rails Only - tells error collector whether or not to capture a
184
+ # source snippet around the place of the error when errors are View
185
+ # related.
186
+ capture_source: true
187
+
188
+ # To stop specific errors from reporting to New Relic, set this property
189
+ # to comma separated values. Default is to ignore routing errors
190
+ # which are how 404's get triggered.
191
+ #
192
+ ignore_errors: ActionController::RoutingError
193
+
194
+ # (Advanced) Uncomment this to ensure the cpu and memory samplers
195
+ # won't run. Useful when you are using the agent to monitor an
196
+ # external resource
197
+ # disable_samplers: true
198
+
199
+ # If you aren't interested in visibility in these areas, you can
200
+ # disable the instrumentation to reduce overhead.
201
+ #
202
+ # disable_view_instrumentation: true
203
+ # disable_activerecord_instrumentation: true
204
+ # disable_memcache_instrumentation: true
205
+ # disable_dj: true
206
+
207
+ # If you're interested in capturing memcache keys as though they
208
+ # were SQL uncomment this flag. Note that this does increase
209
+ # overhead slightly on every memcached call, and can have security
210
+ # implications if your memcached keys are sensitive
211
+ # capture_memcache_keys: true
212
+
213
+ # Certain types of instrumentation such as GC stats will not work if
214
+ # you are running multi-threaded. Please let us know.
215
+ # multi_threaded = false
216
+
217
+ # Application Environments
218
+ # ------------------------------------------
219
+ # Environment specific settings are in this section.
220
+ # For Rails applications, RAILS_ENV is used to determine the environment
221
+ # For Java applications, pass -Dnewrelic.environment <environment> to set
222
+ # the environment
223
+
224
+ # NOTE if your application has other named environments, you should
225
+ # provide newrelic configuration settings for these environments here.
226
+
227
+ development:
228
+ <<: *default_settings
229
+ # Turn off communication to New Relic service in development mode (also
230
+ # 'enabled').
231
+ # NOTE: for initial evaluation purposes, you may want to temporarily
232
+ # turn the agent on in development mode.
233
+ monitor_mode: false
234
+
235
+ # Rails Only - when running in Developer Mode, the New Relic Agent will
236
+ # present performance information on the last 100 transactions you have
237
+ # executed since starting the mongrel.
238
+ # NOTE: There is substantial overhead when running in developer mode.
239
+ # Do not use for production or load testing.
240
+ developer_mode: true
241
+
242
+ # Enable textmate links
243
+ # textmate: true
244
+
245
+ test:
246
+ <<: *default_settings
247
+ # It almost never makes sense to turn on the agent when running
248
+ # unit, functional or integration tests or the like.
249
+ monitor_mode: false
250
+
251
+ # Turn on the agent in production for 24x7 monitoring. NewRelic
252
+ # testing shows an average performance impact of < 5 ms per
253
+ # transaction, you you can leave this on all the time without
254
+ # incurring any user-visible performance degradation.
255
+ production:
256
+ <<: *default_settings
257
+ monitor_mode: true
258
+
259
+ # Many applications have a staging environment which behaves
260
+ # identically to production. Support for that environment is provided
261
+ # here. By default, the staging environment has the agent turned on.
262
+ staging:
263
+ <<: *default_settings
264
+ monitor_mode: true
265
+ app_name: ["Sinatra Test App"]
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: net-http-instrumentation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Felix Gilcher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Provide some instrumentation for Net::HTTP
15
+ email:
16
+ - felix.gilcher@asquera.de
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - lib/net-http-instrumentation/version.rb
27
+ - lib/net/http/instrumentation/newrelic_rpm.rb
28
+ - net-http-instrumentation.gemspec
29
+ - test/app.rb
30
+ - test/log/.gitkeep
31
+ - test/newrelic.yml
32
+ homepage: https://github.com/Asquera/net-http-instrumentation
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.24
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Provide some instrumentation for Net::HTTP
56
+ test_files:
57
+ - test/app.rb
58
+ - test/log/.gitkeep
59
+ - test/newrelic.yml
60
+ has_rdoc: