scout_rails 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.0.7
2
+
3
+ * Sinatra 1.3+ compatibility (alias dispatch! instead of route_eval)
4
+ * Requiring libraries that may not be present in bare-bones Sinatra apps
5
+
1
6
  # 1.0.6
2
7
 
3
8
  * More filtering on transaction sample backtraces
@@ -1,33 +1,41 @@
1
1
  module ScoutRails::Instruments
2
2
  module SinatraInstruments
3
- def route_eval_with_scout_instruments(&blockarg)
4
- path = unescape(@request.path_info)
5
- name = path
6
- # Go through each route and look for a match
7
- if routes = self.class.routes[@request.request_method]
8
- routes.detect do |pattern, keys, conditions, block|
9
- if blockarg.equal? block
10
- name = pattern.source
11
- end
3
+ def dispatch_with_scout_instruments!
4
+ scout_controller_action = "Controller/Sinatra/#{scout_sinatra_controller_name(@request)}"
5
+ self.class.trace(scout_controller_action, :uri => @request.path_info) do
6
+ dispatch_without_scout_instruments!
7
+ end
8
+ end
9
+
10
+ # Iterates through the app's routes, returning the matched route that the request should be
11
+ # grouped under for the metric name.
12
+ #
13
+ # If not found, "unknown" is returned. This prevents a metric explosion.
14
+ #
15
+ # Nice to have: substitute the param pattern (([^/?#]+)) w/the named key (the +key+ param of the block).
16
+ def scout_sinatra_controller_name(request)
17
+ name = 'unknown'
18
+ verb = request.request_method if request && request.respond_to?(:request_method)
19
+ Array(self.class.routes[verb]).each do |pattern, keys, conditions, block|
20
+ if pattern = process_route(pattern, keys, conditions) { pattern.source }
21
+ name = pattern
12
22
  end
13
23
  end
14
24
  name.gsub!(%r{^[/^]*(.*?)[/\$\?]*$}, '\1')
15
- name = 'root' if name.empty?
16
- name = @request.request_method + ' ' + name if @request && @request.respond_to?(:request_method)
17
- scout_controller_action = "Controller/Sinatra/#{name}"
18
- self.class.trace(scout_controller_action, :uri => @request.path_info) do
19
- route_eval_without_scout_instruments(&blockarg)
25
+ if verb
26
+ name = [verb,name].join(' ')
20
27
  end
21
- end # route_eval_with_scout_instrumentss
28
+ name
29
+ end
22
30
  end # SinatraInstruments
23
31
  end # ScoutRails::Instruments
24
32
 
25
- if defined?(::Sinatra) && defined?(::Sinatra::Base)
33
+ if defined?(::Sinatra) && defined?(::Sinatra::Base) && Sinatra::Base.private_method_defined?(:dispatch!)
26
34
  ScoutRails::Agent.instance.logger.debug "Instrumenting Sinatra"
27
35
  ::Sinatra::Base.class_eval do
28
36
  include ScoutRails::Tracer
29
37
  include ::ScoutRails::Instruments::SinatraInstruments
30
- alias route_eval_without_scout_instruments route_eval
31
- alias route_eval route_eval_with_scout_instruments
38
+ alias dispatch_without_scout_instruments! dispatch!
39
+ alias dispatch! dispatch_with_scout_instruments!
32
40
  end
33
41
  end
@@ -1,3 +1,3 @@
1
1
  module ScoutRails
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
data/lib/scout_rails.rb CHANGED
@@ -3,6 +3,9 @@ end
3
3
  require 'socket'
4
4
  require 'set'
5
5
  require 'net/http'
6
+ require 'logger'
7
+ require 'yaml'
8
+ require 'cgi'
6
9
  require File.expand_path('../scout_rails/version.rb', __FILE__)
7
10
  require File.expand_path('../scout_rails/agent.rb', __FILE__)
8
11
  require File.expand_path('../scout_rails/agent/logging.rb', __FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-10-29 00:00:00.000000000 Z
13
+ date: 2012-11-20 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: Monitors a Ruby on Rails application and reports detailed metrics on
16
16
  performance to Scout, a hosted monitoring service.