newrelic-roda 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 70df10cc3370b5695723b860f740ac300bec405d
4
+ data.tar.gz: 8ff5be219b8d753532b2b8658e236dbb8d26fe75
5
+ SHA512:
6
+ metadata.gz: 99481f106dc1d50fdfed9030b7048d690e5243b4dbc035e5e45e91ce1470b517fc9bbb2564d7e6d66ab064c37532e4488d9473099a6939ff6da9dfaf9ea5635c
7
+ data.tar.gz: cfb1e8949933b90185a6fcd25345674b63bfd55fcc3f6c4883f4502eec276ccf7fd54db6b299f09af4a4c3ae61c7da084368900b7cd63bf6dffc20263d04adb5
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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
18
+ example_app/log
19
+ example_app_with_newrelic_3_8/log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=documentation
3
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Next Release
2
+
3
+ ## 1.0.0 (12/18/2012)
4
+
5
+ * Initial public release - [mikz](https://github.com/mikz)
6
+ * Forked from [newrelic-grape](https://github.com/flyerhzm/newrelic-grape)
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in newrelic-roda.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem "rake", "~> 10.0"
8
+ gem "bundler", "~> 1.0"
9
+ gem "rspec", "~> 2.6"
10
+ gem "rack-test", "~> 0.6.2"
11
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Richard Huang, Michal Cichra
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,70 @@
1
+ # NewRelic::Roda
2
+
3
+ NewRelic instrumentation for the [Roda][0], forked from [newrelic-grape][1].
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'newrelic-roda'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install newrelic-roda
18
+
19
+ If you're using Rails, make sure that you've told rack to start the agent for Roda:
20
+
21
+ # config.ru
22
+ require ::File.expand_path('../config/environment', __FILE__)
23
+
24
+ # You need to manually start the agent
25
+ NewRelic::Agent.manual_start
26
+
27
+ run YourApplication::Application
28
+
29
+
30
+ ## Usage
31
+
32
+ Ensure that you have working NewRelic instrumentation. Add the `newrelic-roda` gem. That's it.
33
+
34
+ ## Disabling Instrumentation
35
+
36
+ Set `disable_roda` in `newrelic.yml` or `ENV['DISABLE_NEW_RELIC_RODA']` to disable instrumentation.
37
+
38
+ ## Testing
39
+
40
+ This gem naturally works in NewRelic developer mode. For more information see the [NewRelic Developer Documentation][2].
41
+
42
+ To ensure instrumentation in tests, check that `perform_action_with_newrelic_trace` is invoked on an instance of `NewRelic::Agent::Instrumentation::Roda` when calling your API.
43
+
44
+ ### RSpec
45
+
46
+ ``` ruby
47
+ describe NewRelic::Agent::Instrumentation::Roda do
48
+ it "traces" do
49
+ NewRelic::Agent::Instrumentation::Roda
50
+ .any_instance
51
+ .should_receive(:perform_action_with_newrelic_trace)
52
+ .and_yield
53
+ get "/ping"
54
+ response.status.should == 200
55
+ end
56
+ end
57
+ ```
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Update `CHANGELOG.md` describing your changes
64
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 5. Push to the branch (`git push origin my-new-feature`)
66
+ 6. Create new Pull Request
67
+
68
+ [0]: https://github.com/jeremyevans/roda
69
+ [1]: https://github.com/flyerhzm/newrelic-grape
70
+ [2]: https://newrelic.com/docs/ruby/developer-mode
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+
11
+ require 'rake'
12
+
13
+ require 'rspec/core'
14
+ require 'rspec/core/rake_task'
15
+
16
+ RSpec::Core::RakeTask.new(:spec) do |spec|
17
+ spec.pattern = FileList['spec/**/*_spec.rb']
18
+ end
19
+
20
+ task default: :spec
@@ -0,0 +1,255 @@
1
+ # Here are the settings that are common to all environments
2
+ common: &default_settings
3
+ # ============================== LICENSE KEY ===============================
4
+
5
+ # You must specify the license key associated with your New Relic
6
+ # account. This key binds your Agent's data to your account in the
7
+ # New Relic service.
8
+ license_key: '<%= ENV["NEW_RELIC_LICENSE_KEY"] %>'
9
+
10
+ # Agent Enabled (Rails Only)
11
+ # Use this setting to force the agent to run or not run.
12
+ # Default is 'auto' which means the agent will install and run only
13
+ # if a valid dispatcher such as Mongrel is running. This prevents
14
+ # it from running with Rake or the console. Set to false to
15
+ # completely turn the agent off regardless of the other settings.
16
+ # Valid values are true, false and auto.
17
+ #
18
+ # agent_enabled: auto
19
+
20
+ # Application Name Set this to be the name of your application as
21
+ # you'd like it show up in New Relic. The service will then auto-map
22
+ # instances of your application into an "application" on your
23
+ # dashboard page. If you want to map this instance into multiple
24
+ # apps, like "AJAX Requests" and "All UI" then specify a semicolon
25
+ # separated list of up to three distinct names, or a yaml list.
26
+ # Defaults to the capitalized RAILS_ENV or RACK_ENV (i.e.,
27
+ # Production, Staging, etc)
28
+ #
29
+ # Example:
30
+ #
31
+ # app_name:
32
+ # - Ajax Service
33
+ # - All Services
34
+ #
35
+ app_name: <%= ENV["NEW_RELIC_APP_NAME"] %>
36
+
37
+ # When "true", the agent collects performance data about your
38
+ # application and reports this data to the New Relic service at
39
+ # newrelic.com. This global switch is normally overridden for each
40
+ # environment below. (formerly called 'enabled')
41
+ monitor_mode: true
42
+
43
+ # Developer mode should be off in every environment but
44
+ # development as it has very high overhead in memory.
45
+ developer_mode: false
46
+
47
+ # The newrelic agent generates its own log file to keep its logging
48
+ # information separate from that of your application. Specify its
49
+ # log level here.
50
+ log_level: info
51
+
52
+ # Optionally set the path to the log file This is expanded from the
53
+ # root directory (may be relative or absolute, e.g. 'log/' or
54
+ # '/var/log/') The agent will attempt to create this directory if it
55
+ # does not exist.
56
+ # log_file_path: 'log'
57
+
58
+ # Optionally set the name of the log file, defaults to 'newrelic_agent.log'
59
+ # log_file_name: 'newrelic_agent.log'
60
+
61
+ # The newrelic agent communicates with the service via http by
62
+ # default. If you want to communicate via https to increase
63
+ # security, then turn on SSL by setting this value to true. Note,
64
+ # this will result in increased CPU overhead to perform the
65
+ # encryption involved in SSL communication, but this work is done
66
+ # asynchronously to the threads that process your application code,
67
+ # so it should not impact response times.
68
+ ssl: false
69
+
70
+ # EXPERIMENTAL: enable verification of the SSL certificate sent by
71
+ # the server. This setting has no effect unless SSL is enabled
72
+ # above. This may block your application. Only enable it if the data
73
+ # you send us needs end-to-end verified certificates.
74
+ #
75
+ # This means we cannot cache the DNS lookup, so each request to the
76
+ # service will perform a lookup. It also means that we cannot
77
+ # use a non-blocking lookup, so in a worst case, if you have DNS
78
+ # problems, your app may block indefinitely.
79
+ # verify_certificate: true
80
+
81
+ # Set your application's Apdex threshold value with the 'apdex_t'
82
+ # setting, in seconds. The apdex_t value determines the buckets used
83
+ # to compute your overall Apdex score.
84
+ # Requests that take less than apdex_t seconds to process will be
85
+ # classified as Satisfying transactions; more than apdex_t seconds
86
+ # as Tolerating transactions; and more than four times the apdex_t
87
+ # value as Frustrating transactions.
88
+ # For more about the Apdex standard, see
89
+ # http://newrelic.com/docs/general/apdex
90
+
91
+ apdex_t: 0.5
92
+
93
+ #============================== Browser Monitoring ===============================
94
+ # New Relic Real User Monitoring gives you insight into the performance real users are
95
+ # experiencing with your website. This is accomplished by measuring the time it takes for
96
+ # your users' browsers to download and render your web pages by injecting a small amount
97
+ # of JavaScript code into the header and footer of each page.
98
+ browser_monitoring:
99
+ # By default the agent automatically injects the monitoring JavaScript
100
+ # into web pages. Set this attribute to false to turn off this behavior.
101
+ auto_instrument: true
102
+
103
+ # Proxy settings for connecting to the service.
104
+ #
105
+ # If a proxy is used, the host setting is required. Other settings
106
+ # are optional. Default port is 8080.
107
+ #
108
+ # proxy_host: hostname
109
+ # proxy_port: 8080
110
+ # proxy_user:
111
+ # proxy_pass:
112
+
113
+
114
+ # Tells transaction tracer and error collector (when enabled)
115
+ # whether or not to capture HTTP params. When true, frameworks can
116
+ # exclude HTTP parameters from being captured.
117
+ # Rails: the RoR filter_parameter_logging excludes parameters
118
+ # Java: create a config setting called "ignored_params" and set it to
119
+ # a comma separated list of HTTP parameter names.
120
+ # ex: ignored_params: credit_card, ssn, password
121
+ capture_params: true
122
+
123
+
124
+ # Transaction tracer captures deep information about slow
125
+ # transactions and sends this to the service once a
126
+ # minute. Included in the transaction is the exact call sequence of
127
+ # the transactions including any SQL statements issued.
128
+ transaction_tracer:
129
+
130
+ # Transaction tracer is enabled by default. Set this to false to
131
+ # turn it off. This feature is only available at the Professional
132
+ # and above product levels.
133
+ enabled: true
134
+
135
+ # Threshold in seconds for when to collect a transaction
136
+ # trace. When the response time of a controller action exceeds
137
+ # this threshold, a transaction trace will be recorded and sent to
138
+ # the service. Valid values are any float value, or (default)
139
+ # "apdex_f", which will use the threshold for an dissatisfying
140
+ # Apdex controller action - four times the Apdex T value.
141
+ transaction_threshold: apdex_f
142
+
143
+ # When transaction tracer is on, SQL statements can optionally be
144
+ # recorded. The recorder has three modes, "off" which sends no
145
+ # SQL, "raw" which sends the SQL statement in its original form,
146
+ # and "obfuscated", which strips out numeric and string literals
147
+ record_sql: obfuscated
148
+
149
+ # Threshold in seconds for when to collect stack trace for a SQL
150
+ # call. In other words, when SQL statements exceed this threshold,
151
+ # then capture and send the current stack trace. This is
152
+ # helpful for pinpointing where long SQL calls originate from
153
+ stack_trace_threshold: 0.500
154
+
155
+ # Determines whether the agent will capture query plans for slow
156
+ # SQL queries. Only supported in mysql and postgres. Should be
157
+ # set to false when using other adapters.
158
+ # explain_enabled: true
159
+
160
+ # Threshold for query execution time below which query plans will not
161
+ # not be captured. Relevant only when `explain_enabled` is true.
162
+ # explain_threshold: 0.5
163
+
164
+ # Error collector captures information about uncaught exceptions and
165
+ # sends them to the service for viewing
166
+ error_collector:
167
+
168
+ # Error collector is enabled by default. Set this to false to turn
169
+ # it off. This feature is only available at the Professional and above
170
+ # product levels
171
+ enabled: true
172
+
173
+ # Rails Only - tells error collector whether or not to capture a
174
+ # source snippet around the place of the error when errors are View
175
+ # related.
176
+ capture_source: true
177
+
178
+ # To stop specific errors from reporting to New Relic, set this property
179
+ # to comma separated values. Default is to ignore routing errors
180
+ # which are how 404's get triggered.
181
+ #
182
+ ignore_errors: ActionController::RoutingError
183
+
184
+ # (Advanced) Uncomment this to ensure the cpu and memory samplers
185
+ # won't run. Useful when you are using the agent to monitor an
186
+ # external resource
187
+ # disable_samplers: true
188
+
189
+ # If you aren't interested in visibility in these areas, you can
190
+ # disable the instrumentation to reduce overhead.
191
+ #
192
+ # disable_view_instrumentation: true
193
+ # disable_activerecord_instrumentation: true
194
+ # disable_memcache_instrumentation: true
195
+ # disable_dj: true
196
+
197
+ # If you're interested in capturing memcache keys as though they
198
+ # were SQL uncomment this flag. Note that this does increase
199
+ # overhead slightly on every memcached call, and can have security
200
+ # implications if your memcached keys are sensitive
201
+ # capture_memcache_keys: true
202
+
203
+ # Certain types of instrumentation such as GC stats will not work if
204
+ # you are running multi-threaded. Please let us know.
205
+ # multi_threaded = false
206
+
207
+ # Application Environments
208
+ # ------------------------------------------
209
+ # Environment specific settings are in this section.
210
+ # For Rails applications, RAILS_ENV is used to determine the environment
211
+ # For Java applications, pass -Dnewrelic.environment <environment> to set
212
+ # the environment
213
+
214
+ # NOTE if your application has other named environments, you should
215
+ # provide newrelic configuration settings for these environments here.
216
+
217
+ development:
218
+ <<: *default_settings
219
+ # Turn off communication to New Relic service in development mode (also
220
+ # 'enabled').
221
+ # NOTE: for initial evaluation purposes, you may want to temporarily
222
+ # turn the agent on in development mode.
223
+ monitor_mode: false
224
+
225
+ # Rails Only - when running in Developer Mode, the New Relic Agent will
226
+ # present performance information on the last 100 transactions you have
227
+ # executed since starting the mongrel.
228
+ # NOTE: There is substantial overhead when running in developer mode.
229
+ # Do not use for production or load testing.
230
+ developer_mode: <%= !!ENV['NEW_RELIC_ID'] %>
231
+
232
+ # Enable textmate links
233
+ # textmate: true
234
+
235
+ test:
236
+ <<: *default_settings
237
+ # It almost never makes sense to turn on the agent when running
238
+ # unit, functional or integration tests or the like.
239
+ monitor_mode: false
240
+
241
+ # Turn on the agent in production for 24x7 monitoring. NewRelic
242
+ # testing shows an average performance impact of < 5 ms per
243
+ # transaction, you you can leave this on all the time without
244
+ # incurring any user-visible performance degradation.
245
+ production:
246
+ <<: *default_settings
247
+ monitor_mode: true
248
+
249
+ # Many applications have a staging environment which behaves
250
+ # identically to production. Support for that environment is provided
251
+ # here. By default, the staging environment has the agent turned on.
252
+ staging:
253
+ <<: *default_settings
254
+ monitor_mode: true
255
+ app_name: <%= ENV["NEW_RELIC_APP_NAME"] %> (Staging)
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rack'
4
+ gem 'roda'
5
+ gem 'newrelic_rpm', '~> 3.9.0'
6
+ gem 'newrelic-roda', path: '..'
7
+
8
+ gem 'pry'
9
+ group :test do
10
+ gem "rspec"
11
+ gem "rack-test", require: "rack/test"
12
+ end
@@ -0,0 +1,29 @@
1
+ Example App
2
+ ================
3
+
4
+ A [Roda](http://github.com/jeremyevans/roda) API mounted on Rack to demonstrate [newrelic-roda](https://github.com/mikz/newrelic-roda).
5
+
6
+ * [ping](api/ping.rb): a hello world example that returns a JSON document
7
+
8
+ Run
9
+ ___
10
+
11
+ ```
12
+ $bundle install
13
+ $rackup
14
+ ```
15
+
16
+ ### Ping
17
+
18
+ Navigate to http://localhost:9292/api/ping with a browser or use `curl`.
19
+
20
+ ```
21
+ $ curl http://localhost:9292/api/ping
22
+
23
+ {"ping":"pong"}
24
+ ```
25
+
26
+ New Relic
27
+ ---------
28
+
29
+ The application is setup with NewRelic w/ Developer Mode. Navigate to http://localhost:9292/newrelic after making some API calls.
@@ -0,0 +1,30 @@
1
+ module Api
2
+ class Ping < Roda
3
+ route do |r|
4
+ r.on 'ping' do
5
+ r.get do
6
+ '{"ping":"pong"}'
7
+ end
8
+ end
9
+
10
+ r.on 'nested/:multi/:stuff' do |multi, stuff|
11
+ { multi => stuff }.to_json
12
+ end
13
+
14
+ r.on ':param' do |param|
15
+ sleep(0.2)
16
+ puts 'slept 0.2'
17
+ r.on ':other' do |other|
18
+ sleep(0.3)
19
+ puts 'slept 0.3'
20
+ r.get do
21
+ sleep(0.4)
22
+ puts 'slept 0.4'
23
+ { param => other }.to_s
24
+ end
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,26 @@
1
+ #$trace = TracePoint.new(:call) do |tp|
2
+ # params = tp.defined_class.instance_method(tp.method_id).parameters
3
+ # arguments = params.map do |(_type, name)|
4
+ # [name, tp.binding.local_variable_get(name)]
5
+ # end
6
+ # p [tp.defined_class, tp.method_id, tp.event, arguments]
7
+ #end
8
+
9
+ module App
10
+ class Api < Roda
11
+
12
+ route do |r|
13
+ # $enabled ||= ($trace.enable; true)
14
+
15
+ r.root do
16
+ 'root route'
17
+ end
18
+
19
+ r.on 'api' do
20
+ sleep(0.1)
21
+ puts 'slept 0.1'
22
+ r.run ::Api::Ping
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path('../config/environment', __FILE__)
2
+
3
+ if defined?(NewRelic)
4
+ if ENV['RACK_ENV'] == 'development'
5
+ puts "Loading NewRelic in developer mode ..."
6
+ #require 'new_relic/rack/developer_mode'
7
+ #use NewRelic::Rack::DeveloperMode
8
+ end
9
+
10
+ NewRelic::Agent.manual_start
11
+ end
12
+
13
+ require 'api'
14
+ run App::Api
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'api'))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'app'))
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+
5
+ require 'boot'
6
+
7
+ Bundler.require :default, ENV['RACK_ENV']
8
+
9
+ Dir[File.expand_path('../../api/*.rb', __FILE__)].each do |f|
10
+ require f
11
+ end
@@ -0,0 +1,2 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
@@ -0,0 +1,3 @@
1
+ ENV['RACK_ENV'] ||= 'test'
2
+
3
+ require File.expand_path('../application', __FILE__)
@@ -0,0 +1,255 @@
1
+ # Here are the settings that are common to all environments
2
+ common: &default_settings
3
+ # ============================== LICENSE KEY ===============================
4
+
5
+ # You must specify the license key associated with your New Relic
6
+ # account. This key binds your Agent's data to your account in the
7
+ # New Relic service.
8
+ license_key: '<%= ENV["NEW_RELIC_LICENSE_KEY"] %>'
9
+
10
+ # Agent Enabled (Rails Only)
11
+ # Use this setting to force the agent to run or not run.
12
+ # Default is 'auto' which means the agent will install and run only
13
+ # if a valid dispatcher such as Mongrel is running. This prevents
14
+ # it from running with Rake or the console. Set to false to
15
+ # completely turn the agent off regardless of the other settings.
16
+ # Valid values are true, false and auto.
17
+ #
18
+ # agent_enabled: auto
19
+
20
+ # Application Name Set this to be the name of your application as
21
+ # you'd like it show up in New Relic. The service will then auto-map
22
+ # instances of your application into an "application" on your
23
+ # dashboard page. If you want to map this instance into multiple
24
+ # apps, like "AJAX Requests" and "All UI" then specify a semicolon
25
+ # separated list of up to three distinct names, or a yaml list.
26
+ # Defaults to the capitalized RAILS_ENV or RACK_ENV (i.e.,
27
+ # Production, Staging, etc)
28
+ #
29
+ # Example:
30
+ #
31
+ # app_name:
32
+ # - Ajax Service
33
+ # - All Services
34
+ #
35
+ app_name: <%= ENV["NEW_RELIC_APP_NAME"] || 'NewRelic::Roda Example Application' %>
36
+
37
+ # When "true", the agent collects performance data about your
38
+ # application and reports this data to the New Relic service at
39
+ # newrelic.com. This global switch is normally overridden for each
40
+ # environment below. (formerly called 'enabled')
41
+ monitor_mode: true
42
+
43
+ # Developer mode should be off in every environment but
44
+ # development as it has very high overhead in memory.
45
+ developer_mode: false
46
+
47
+ # The newrelic agent generates its own log file to keep its logging
48
+ # information separate from that of your application. Specify its
49
+ # log level here.
50
+ log_level: debug
51
+
52
+ # Optionally set the path to the log file This is expanded from the
53
+ # root directory (may be relative or absolute, e.g. 'log/' or
54
+ # '/var/log/') The agent will attempt to create this directory if it
55
+ # does not exist.
56
+ # log_file_path: 'log'
57
+
58
+ # Optionally set the name of the log file, defaults to 'newrelic_agent.log'
59
+ # log_file_name: 'newrelic_agent.log'
60
+
61
+ # The newrelic agent communicates with the service via http by
62
+ # default. If you want to communicate via https to increase
63
+ # security, then turn on SSL by setting this value to true. Note,
64
+ # this will result in increased CPU overhead to perform the
65
+ # encryption involved in SSL communication, but this work is done
66
+ # asynchronously to the threads that process your application code,
67
+ # so it should not impact response times.
68
+ ssl: false
69
+
70
+ # EXPERIMENTAL: enable verification of the SSL certificate sent by
71
+ # the server. This setting has no effect unless SSL is enabled
72
+ # above. This may block your application. Only enable it if the data
73
+ # you send us needs end-to-end verified certificates.
74
+ #
75
+ # This means we cannot cache the DNS lookup, so each request to the
76
+ # service will perform a lookup. It also means that we cannot
77
+ # use a non-blocking lookup, so in a worst case, if you have DNS
78
+ # problems, your app may block indefinitely.
79
+ # verify_certificate: true
80
+
81
+ # Set your application's Apdex threshold value with the 'apdex_t'
82
+ # setting, in seconds. The apdex_t value determines the buckets used
83
+ # to compute your overall Apdex score.
84
+ # Requests that take less than apdex_t seconds to process will be
85
+ # classified as Satisfying transactions; more than apdex_t seconds
86
+ # as Tolerating transactions; and more than four times the apdex_t
87
+ # value as Frustrating transactions.
88
+ # For more about the Apdex standard, see
89
+ # http://newrelic.com/docs/general/apdex
90
+
91
+ apdex_t: 0.5
92
+
93
+ #============================== Browser Monitoring ===============================
94
+ # New Relic Real User Monitoring gives you insight into the performance real users are
95
+ # experiencing with your website. This is accomplished by measuring the time it takes for
96
+ # your users' browsers to download and render your web pages by injecting a small amount
97
+ # of JavaScript code into the header and footer of each page.
98
+ browser_monitoring:
99
+ # By default the agent automatically injects the monitoring JavaScript
100
+ # into web pages. Set this attribute to false to turn off this behavior.
101
+ auto_instrument: true
102
+
103
+ # Proxy settings for connecting to the service.
104
+ #
105
+ # If a proxy is used, the host setting is required. Other settings
106
+ # are optional. Default port is 8080.
107
+ #
108
+ # proxy_host: hostname
109
+ # proxy_port: 8080
110
+ # proxy_user:
111
+ # proxy_pass:
112
+
113
+
114
+ # Tells transaction tracer and error collector (when enabled)
115
+ # whether or not to capture HTTP params. When true, frameworks can
116
+ # exclude HTTP parameters from being captured.
117
+ # Rails: the RoR filter_parameter_logging excludes parameters
118
+ # Java: create a config setting called "ignored_params" and set it to
119
+ # a comma separated list of HTTP parameter names.
120
+ # ex: ignored_params: credit_card, ssn, password
121
+ capture_params: true
122
+
123
+
124
+ # Transaction tracer captures deep information about slow
125
+ # transactions and sends this to the service once a
126
+ # minute. Included in the transaction is the exact call sequence of
127
+ # the transactions including any SQL statements issued.
128
+ transaction_tracer:
129
+
130
+ # Transaction tracer is enabled by default. Set this to false to
131
+ # turn it off. This feature is only available at the Professional
132
+ # and above product levels.
133
+ enabled: true
134
+
135
+ # Threshold in seconds for when to collect a transaction
136
+ # trace. When the response time of a controller action exceeds
137
+ # this threshold, a transaction trace will be recorded and sent to
138
+ # the service. Valid values are any float value, or (default)
139
+ # "apdex_f", which will use the threshold for an dissatisfying
140
+ # Apdex controller action - four times the Apdex T value.
141
+ transaction_threshold: apdex_f
142
+
143
+ # When transaction tracer is on, SQL statements can optionally be
144
+ # recorded. The recorder has three modes, "off" which sends no
145
+ # SQL, "raw" which sends the SQL statement in its original form,
146
+ # and "obfuscated", which strips out numeric and string literals
147
+ record_sql: obfuscated
148
+
149
+ # Threshold in seconds for when to collect stack trace for a SQL
150
+ # call. In other words, when SQL statements exceed this threshold,
151
+ # then capture and send the current stack trace. This is
152
+ # helpful for pinpointing where long SQL calls originate from
153
+ stack_trace_threshold: 0.500
154
+
155
+ # Determines whether the agent will capture query plans for slow
156
+ # SQL queries. Only supported in mysql and postgres. Should be
157
+ # set to false when using other adapters.
158
+ # explain_enabled: true
159
+
160
+ # Threshold for query execution time below which query plans will not
161
+ # not be captured. Relevant only when `explain_enabled` is true.
162
+ # explain_threshold: 0.5
163
+
164
+ # Error collector captures information about uncaught exceptions and
165
+ # sends them to the service for viewing
166
+ error_collector:
167
+
168
+ # Error collector is enabled by default. Set this to false to turn
169
+ # it off. This feature is only available at the Professional and above
170
+ # product levels
171
+ enabled: true
172
+
173
+ # Rails Only - tells error collector whether or not to capture a
174
+ # source snippet around the place of the error when errors are View
175
+ # related.
176
+ capture_source: true
177
+
178
+ # To stop specific errors from reporting to New Relic, set this property
179
+ # to comma separated values. Default is to ignore routing errors
180
+ # which are how 404's get triggered.
181
+ #
182
+ ignore_errors: ActionController::RoutingError
183
+
184
+ # (Advanced) Uncomment this to ensure the cpu and memory samplers
185
+ # won't run. Useful when you are using the agent to monitor an
186
+ # external resource
187
+ # disable_samplers: true
188
+
189
+ # If you aren't interested in visibility in these areas, you can
190
+ # disable the instrumentation to reduce overhead.
191
+ #
192
+ # disable_view_instrumentation: true
193
+ # disable_activerecord_instrumentation: true
194
+ # disable_memcache_instrumentation: true
195
+ # disable_dj: true
196
+
197
+ # If you're interested in capturing memcache keys as though they
198
+ # were SQL uncomment this flag. Note that this does increase
199
+ # overhead slightly on every memcached call, and can have security
200
+ # implications if your memcached keys are sensitive
201
+ # capture_memcache_keys: true
202
+
203
+ # Certain types of instrumentation such as GC stats will not work if
204
+ # you are running multi-threaded. Please let us know.
205
+ # multi_threaded = false
206
+
207
+ # Application Environments
208
+ # ------------------------------------------
209
+ # Environment specific settings are in this section.
210
+ # For Rails applications, RAILS_ENV is used to determine the environment
211
+ # For Java applications, pass -Dnewrelic.environment <environment> to set
212
+ # the environment
213
+
214
+ # NOTE if your application has other named environments, you should
215
+ # provide newrelic configuration settings for these environments here.
216
+
217
+ development:
218
+ <<: *default_settings
219
+ # Turn off communication to New Relic service in development mode (also
220
+ # 'enabled').
221
+ # NOTE: for initial evaluation purposes, you may want to temporarily
222
+ # turn the agent on in development mode.
223
+ monitor_mode: false
224
+
225
+ # Rails Only - when running in Developer Mode, the New Relic Agent will
226
+ # present performance information on the last 100 transactions you have
227
+ # executed since starting the mongrel.
228
+ # NOTE: There is substantial overhead when running in developer mode.
229
+ # Do not use for production or load testing.
230
+ developer_mode: true
231
+
232
+ # Enable textmate links
233
+ # textmate: true
234
+
235
+ test:
236
+ <<: *default_settings
237
+ # It almost never makes sense to turn on the agent when running
238
+ # unit, functional or integration tests or the like.
239
+ monitor_mode: false
240
+
241
+ # Turn on the agent in production for 24x7 monitoring. NewRelic
242
+ # testing shows an average performance impact of < 5 ms per
243
+ # transaction, you you can leave this on all the time without
244
+ # incurring any user-visible performance degradation.
245
+ production:
246
+ <<: *default_settings
247
+ monitor_mode: true
248
+
249
+ # Many applications have a staging environment which behaves
250
+ # identically to production. Support for that environment is provided
251
+ # here. By default, the staging environment has the agent turned on.
252
+ staging:
253
+ <<: *default_settings
254
+ monitor_mode: true
255
+ app_name: <%= ENV["NEW_RELIC_APP_NAME"] %> (Staging)
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Api::Ping do
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ App::Api
8
+ end
9
+
10
+ it 'ping' do
11
+ get '/api/ping'
12
+ expect(last_response.status).to eq(200)
13
+ expect(last_response.body).to eq({ ping: 'pong' }.to_json)
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ ENV['RACK_ENV'] ||= 'test'
2
+ require 'rack/test'
3
+ require File.expand_path('../../config/environment', __FILE__)
4
+ require 'api'
5
+
6
+ RSpec.configure do |config|
7
+ config.mock_with :rspec
8
+ config.expect_with :rspec
9
+ config.raise_errors_for_deprecations!
10
+ end
@@ -0,0 +1,2 @@
1
+ require "newrelic-roda/version"
2
+ require "newrelic-roda/instrument"
@@ -0,0 +1,107 @@
1
+ require 'new_relic/agent/instrumentation'
2
+ require 'new_relic/agent/instrumentation/controller_instrumentation'
3
+ require 'new_relic/agent/instrumentation/sinatra/transaction_namer'
4
+
5
+ require 'roda'
6
+
7
+ module NewRelic
8
+ module Agent
9
+ module Instrumentation
10
+ module Roda
11
+ TransactionNamer = NewRelic::Agent::Instrumentation::Sinatra::TransactionNamer
12
+
13
+ module RequestMethods
14
+ include ::NewRelic::Agent::MethodTracer
15
+ add_method_tracer :match_all
16
+
17
+ private
18
+
19
+ def if_match(args, &block)
20
+ instrumented = proc do |*captures|
21
+ params = { env.fetch('new_relic.roda').last => captures }
22
+ @scope.perform_action_with_newrelic_trace(category: :controller, params: params) do
23
+ yield(*captures)
24
+ end
25
+ end
26
+ super(args, &instrumented)
27
+ end
28
+
29
+ def match_all(args)
30
+ if all = super
31
+ (env['new_relic.roda'] ||= [nil]) << args
32
+ end
33
+ all
34
+ end
35
+
36
+ def block_result(result)
37
+ begin
38
+ txn_name = _route_name
39
+ unless txn_name.nil?
40
+ ::NewRelic::Agent::Transaction.set_default_transaction_name(
41
+ "#{self.class.name}/#{txn_name}", :category => :sinatra)
42
+ end
43
+ rescue => e
44
+ ::NewRelic::Agent.logger.debug("Failed during route_eval to set transaction name", e)
45
+ end
46
+
47
+ super
48
+ end
49
+
50
+ def _route_name
51
+ "#{request_method} #{env.fetch('new_relic.roda',['/']).join('/')}"
52
+ end
53
+ end
54
+
55
+ module InstanceMethods
56
+ def self.included(base)
57
+ base.include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
58
+ end
59
+
60
+ def call(env, &block)
61
+ super
62
+ rescue => error
63
+ ::NewRelic::Agent.notice_error(error)
64
+ raise error
65
+ end
66
+
67
+ def _route(&block)
68
+ perform_action_with_newrelic_trace(:category => :controller,
69
+ :params => @_request.params) do
70
+ super
71
+ end
72
+ end
73
+
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ DependencyDetection.defer do
81
+ @name = :roda
82
+
83
+ depends_on do
84
+ defined?(::Roda) && ! ::NewRelic::Control.instance['disable_roda'] && ! ENV['DISABLE_NEW_RELIC_RODA']
85
+ end
86
+
87
+ executes do
88
+ NewRelic::Agent.logger.debug 'Installing Roda instrumentation'
89
+ Roda::RodaPlugins.register_plugin(:new_relic, NewRelic::Agent::Instrumentation::Roda)
90
+ Roda.plugin(:new_relic)
91
+ end
92
+
93
+ executes do
94
+ end
95
+
96
+ executes do
97
+ NewRelic::Agent::Instrumentation::MiddlewareProxy.class_eval do
98
+ def self.needs_wrapping?(target)
99
+ (
100
+ !target.respond_to?(:_nr_has_middleware_tracing) &&
101
+ !is_sinatra_app?(target) &&
102
+ !target.is_a?(Proc)
103
+ )
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,5 @@
1
+ module NewRelic
2
+ module Roda
3
+ VERSION = '1.0.0.pre1'
4
+ end
5
+ 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-roda/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'newrelic-roda'
8
+ gem.version = NewRelic::Roda::VERSION
9
+ gem.authors = ['Michal Cichra', "Richard Huang"]
10
+ gem.email = ['m@o2h.cz', "flyerhzm@gmail.com"]
11
+ gem.description = %q{newrelic instrument for roda}
12
+ gem.summary = %q{newrelic instrument for roda}
13
+ gem.homepage = 'https://github.com/mikz/newrelic-roda'
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_runtime_dependency 'roda'
21
+ gem.add_runtime_dependency 'newrelic_rpm'
22
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe NewRelic::Agent::Instrumentation::Roda do
4
+
5
+ subject(:app) { Class.new(Roda) }
6
+
7
+ def route(&block)
8
+ app.route(&block)
9
+ end
10
+
11
+ context 'root' do
12
+ before do
13
+ route do |r|
14
+ r.root do
15
+ 'Root!'
16
+ end
17
+ end
18
+ end
19
+
20
+ it 'perform_action_with_newrelic_trace' do
21
+ #NewRelic::Agent::Instrumentation::Roda.any_instance
22
+ # .should_receive(:perform_action_with_newrelic_trace)
23
+ # .with(hash_including(path: 'GET hello'))
24
+ # .and_yield
25
+
26
+ get '/'
27
+ expect(last_response.status).to eq 200
28
+ expect(last_response.body).to eq 'Root!'
29
+ end
30
+ end
31
+
32
+ context 'nested routes' do
33
+ before do
34
+ route do |r|
35
+ r.on 'hello' do
36
+ r.is do
37
+ r.get do
38
+ 'Hello!'
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ context 'in path' do
46
+ it 'perform_action_with_newrelic_trace' do
47
+ #NewRelic::Agent::Instrumentation::Roda.any_instance
48
+ # .should_receive(:perform_action_with_newrelic_trace)
49
+ # .with(hash_including(path: 'GET v1-hello'))
50
+ # .and_yield
51
+
52
+ get '/hello'
53
+
54
+ expect(last_response.status).to eq 200
55
+ expect(last_response.body).to eq 'Hello!'
56
+ end
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe NewRelic::Roda do
4
+ it "has a version" do
5
+ NewRelic::Roda::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rack/test'
5
+
6
+ RSpec.configure do |config|
7
+ config.include Rack::Test::Methods
8
+ config.before do
9
+ DependencyDetection.detect!
10
+ end
11
+ end
12
+
13
+ require 'roda'
14
+ require 'newrelic_rpm'
15
+ require 'newrelic-roda'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: newrelic-roda
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre1
5
+ platform: ruby
6
+ authors:
7
+ - Michal Cichra
8
+ - Richard Huang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-11-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: roda
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: newrelic_rpm
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: newrelic instrument for roda
43
+ email:
44
+ - m@o2h.cz
45
+ - flyerhzm@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - ".rspec"
52
+ - CHANGELOG.md
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - config/newrelic.yml
58
+ - example_app/Gemfile
59
+ - example_app/README.md
60
+ - example_app/api/ping.rb
61
+ - example_app/app/api.rb
62
+ - example_app/config.ru
63
+ - example_app/config/application.rb
64
+ - example_app/config/boot.rb
65
+ - example_app/config/environment.rb
66
+ - example_app/config/newrelic.yml
67
+ - example_app/spec/api/ping_spec.rb
68
+ - example_app/spec/spec_helper.rb
69
+ - lib/newrelic-roda.rb
70
+ - lib/newrelic-roda/instrument.rb
71
+ - lib/newrelic-roda/version.rb
72
+ - newrelic-grape.gemspec
73
+ - spec/newrelic-roda/instrumenter_spec.rb
74
+ - spec/newrelic-roda/version_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: https://github.com/mikz/newrelic-roda
77
+ licenses: []
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">"
91
+ - !ruby/object:Gem::Version
92
+ version: 1.3.1
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: newrelic instrument for roda
99
+ test_files:
100
+ - spec/newrelic-roda/instrumenter_spec.rb
101
+ - spec/newrelic-roda/version_spec.rb
102
+ - spec/spec_helper.rb