newrelic-grape 1.0.0 → 1.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.
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=documentation
3
+
@@ -0,0 +1,10 @@
1
+ Next Release
2
+ ============
3
+
4
+ * Changed namespace from `Newrelic` to `NewRelic` to be consistent with the RPM gem - [@dblock](https://github.com/dblock).
5
+ * Set `DISABLE_NEW_RELIC_GRAPE` to disable instrumentation - [@dblock](https://github.com/dblock).
6
+
7
+ 1.0.0 (12/18/2012)
8
+ ==================
9
+
10
+ * Initial public release - [@flyerhzm](https://github.com/flyerhzm).
data/Gemfile CHANGED
@@ -2,3 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in newrelic-grape.gemspec
4
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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Newrelic::Grape
1
+ # NewRelic::Grape
2
2
 
3
3
  NewRelic instrument for [grape][0], this is inspired from this [blog post][1].
4
4
 
@@ -20,13 +20,18 @@ Or install it yourself as:
20
20
 
21
21
  That's it.
22
22
 
23
+ ## Disabling Instrumentation
24
+
25
+ Set `disable_grape` in `newrelic.yml` or `ENV['DISABLE_NEW_RELIC_GRAPE']` to disable instrumentation.
26
+
23
27
  ## Contributing
24
28
 
25
29
  1. Fork it
26
30
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
31
+ 3. Update `CHANGELOG.md` describing your changes
32
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 5. Push to the branch (`git push origin my-new-feature`)
34
+ 6. Create new Pull Request
30
35
 
31
36
  [0]: https://github.com/intridea/grape
32
37
  [1]: http://artsy.github.com/blog/2012/11/29/measuring-performance-in-grape-apis-with-new-relic/
data/Rakefile CHANGED
@@ -1 +1,20 @@
1
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)
@@ -1,8 +1,2 @@
1
1
  require "newrelic-grape/version"
2
2
  require "newrelic-grape/instrument"
3
-
4
- module Newrelic
5
- module Grape
6
- # Your code goes here...
7
- end
8
- end
@@ -1,36 +1,40 @@
1
- module NewRelic::Agent::Instrumentation
2
- class Grape < Grape::Middleware::Base
3
- include ControllerInstrumentation
4
-
5
- def call!(env)
6
- @env = env
7
-
8
- @newrelic_request = ::Rack::Request.new(env)
9
- trace_options = {
10
- :category => :rack,
11
- :path => "#{request_method} #{request_path}",
12
- :request => @newrelic_request
13
- }
14
- perform_action_with_newrelic_trace(trace_options) do
15
- @app_response = @app.call(@env)
16
- end
17
- end
1
+ module NewRelic
2
+ module Agent
3
+ module Instrumentation
4
+ class Grape < ::Grape::Middleware::Base
5
+ include ControllerInstrumentation
6
+
7
+ def call!(env)
8
+ @env = env
9
+ @newrelic_request = ::Rack::Request.new(env)
10
+ trace_options = {
11
+ :category => :rack,
12
+ :path => "#{request_method} #{request_path}",
13
+ :request => @newrelic_request
14
+ }
15
+ perform_action_with_newrelic_trace(trace_options) do
16
+ @app_response = @app.call(@env)
17
+ end
18
+ end
19
+
20
+ def request_path
21
+ env['api.endpoint'].routes.first.route_path[1..-1].gsub("/", "-").sub(/\(\.:format\)\z/, "")
22
+ end
23
+
24
+ def request_method
25
+ @newrelic_request.request_method
26
+ end
18
27
 
19
- def request_path
20
- env['api.endpoint'].routes.first.route_path[1..-1].gsub("/", "-").sub(/\(\.:format\)\z/, "")
21
- end
22
-
23
- def request_method
24
- @newrelic_request.request_method
28
+ end
25
29
  end
26
30
  end
27
31
  end
28
32
 
29
- DependencyDetection.defer do
33
+ DependencyDetection.defer do
30
34
  @name = :grape
31
35
 
32
36
  depends_on do
33
- defined?(::Grape) and not ::NewRelic::Control.instance['disable_grape']
37
+ defined?(::Grape) && ! ::NewRelic::Control.instance['disable_grape'] && ! ENV['DISABLE_NEW_RELIC_GRAPE']
34
38
  end
35
39
 
36
40
  executes do
@@ -39,10 +43,10 @@ DependencyDetection.defer do
39
43
 
40
44
  executes do
41
45
  ::Grape::Endpoint.class_eval do
42
- alias_method :origin_build_middleware, :build_middleware
46
+ alias_method :grape_build_middleware, :build_middleware
43
47
 
44
48
  def build_middleware
45
- builder = origin_build_middleware
49
+ builder = grape_build_middleware
46
50
  builder.use ::NewRelic::Agent::Instrumentation::Grape
47
51
  builder
48
52
  end
@@ -1,5 +1,5 @@
1
- module Newrelic
1
+ module NewRelic
2
2
  module Grape
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -5,7 +5,7 @@ require 'newrelic-grape/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
7
  gem.name = "newrelic-grape"
8
- gem.version = Newrelic::Grape::VERSION
8
+ gem.version = NewRelic::Grape::VERSION
9
9
  gem.authors = ["Richard Huang"]
10
10
  gem.email = ["flyerhzm@gmail.com"]
11
11
  gem.description = %q{newrelic instrument for grape}
@@ -16,4 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency(%q<grape>)
21
+ gem.add_runtime_dependency(%q<newrelic_rpm>)
19
22
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe NewRelic::Agent::Instrumentation::Grape do
4
+
5
+ subject { Class.new(Grape::API) }
6
+
7
+ def app
8
+ subject
9
+ end
10
+
11
+ before do
12
+ subject.get :hello do
13
+ "Hello World"
14
+ end
15
+ end
16
+
17
+ it "perform_action_with_newrelic_trace" do
18
+ NewRelic::Agent::Instrumentation::Grape.any_instance.should_receive(:perform_action_with_newrelic_trace).and_yield
19
+ get "/hello"
20
+ last_response.status.should == 200
21
+ last_response.body.should == "Hello World"
22
+ end
23
+
24
+ end
25
+
26
+
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe NewRelic::Grape do
4
+ it "has a version" do
5
+ NewRelic::Grape::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 'grape'
14
+ require 'newrelic_rpm'
15
+ require 'newrelic-grape'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newrelic-grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-18 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: grape
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: newrelic_rpm
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
14
46
  description: newrelic instrument for grape
15
47
  email:
16
48
  - flyerhzm@gmail.com
@@ -19,14 +51,20 @@ extensions: []
19
51
  extra_rdoc_files: []
20
52
  files:
21
53
  - .gitignore
54
+ - .rspec
55
+ - CHANGELOG.md
22
56
  - Gemfile
23
57
  - LICENSE.txt
24
58
  - README.md
25
59
  - Rakefile
60
+ - config/newrelic.yml
26
61
  - lib/newrelic-grape.rb
27
62
  - lib/newrelic-grape/instrument.rb
28
63
  - lib/newrelic-grape/version.rb
29
64
  - newrelic-grape.gemspec
65
+ - spec/newrelic-grape/instrumenter_spec.rb
66
+ - spec/newrelic-grape/version_spec.rb
67
+ - spec/spec_helper.rb
30
68
  homepage: https://github.com/flyerhzm/newrelic-grape
31
69
  licenses: []
32
70
  post_install_message:
@@ -39,17 +77,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
39
77
  - - ! '>='
40
78
  - !ruby/object:Gem::Version
41
79
  version: '0'
80
+ segments:
81
+ - 0
82
+ hash: 240126321961022721
42
83
  required_rubygems_version: !ruby/object:Gem::Requirement
43
84
  none: false
44
85
  requirements:
45
86
  - - ! '>='
46
87
  - !ruby/object:Gem::Version
47
88
  version: '0'
89
+ segments:
90
+ - 0
91
+ hash: 240126321961022721
48
92
  requirements: []
49
93
  rubyforge_project:
50
94
  rubygems_version: 1.8.24
51
95
  signing_key:
52
96
  specification_version: 3
53
97
  summary: newrelic instrument for grape
54
- test_files: []
55
- has_rdoc:
98
+ test_files:
99
+ - spec/newrelic-grape/instrumenter_spec.rb
100
+ - spec/newrelic-grape/version_spec.rb
101
+ - spec/spec_helper.rb