skylight 1.3.1 → 1.4.0.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83dd7c6f5a27d456efd3e03bfc08303fea5f1085
4
- data.tar.gz: c7bfa08ec18f46a18b43ae6e2d7e4d568f54d6b1
3
+ metadata.gz: 8a44af3f665e6d0fd8a25dc3d867ea86dae43620
4
+ data.tar.gz: edac70c82631fb57e9990aeeedbb55a62e4111d5
5
5
  SHA512:
6
- metadata.gz: 5b2faf2103731fc3549aa34da956454461703fff11e05d18de2be546b9adab1f0011b96782894d0aea709b03aa1070a5e27421dc8800c92b2f9a5914cdac418b
7
- data.tar.gz: 585d6d962d8473fdf99d5fcc2a97fa97732d9a691e92ffb3e51c4219bdf75fa834f4d7eaefdb96ec9d3a1109616a3e744fd4cb9765829808a7dee8b9a1327482
6
+ metadata.gz: da6cec1e164c3c49cce1239c88efb74f7dca60e0b699aadf051cf97fb2def14a813e0a99badac04c50c2750ab2bd0f420d69fb88fb2421ce92ef4d9a42dc1bb6
7
+ data.tar.gz: 12bc7d82549fc243fd7446892d2387ce635a941d5ae23600713e9b2432d68dbb2b7793e8bcaa369227127b1027d964d1125492f273e89f5e5220813fcf027bed
@@ -1,3 +1,10 @@
1
+ ## 1.4.0-beta (July 13, 2017)
2
+
3
+ * [FEATURE] Add probe for Rack Middlewares. To enable, add 'middleware' to `config.skylight.probes` list.
4
+ * [IMPROVEMENT] Increase limit for items tracked in a requests
5
+ * [IMPROVEMENT] Allow for more fine-grained control over position of Skylight::Middleware
6
+ * [IMPROVEMENT] Avoid processing Skylight::Middleware unnecessarily
7
+
1
8
  ## 1.3.1 (May 17, 2017)
2
9
 
3
10
  * [IMPROVEMENT] Better suggestions in `skylight doctor`.
@@ -1,7 +1,7 @@
1
1
  ---
2
- version: "1.1.0-de45c74"
2
+ version: "1.4.0-7aecded"
3
3
  checksums:
4
- x86-linux: "fbfb6a647701403a11e2e81045dd84b3c55ec7fedf60910bfa372c9bf7ef8b5f"
5
- x86_64-linux: "6958c20cc35bea207f12e65530460dda64ed6a31556a76de8911ae9c604cff93"
6
- x86_64-linux-musl: "65171091e9262755431e52e1b1c3c7e4881c71bbf8ded322aa599f137baecf10"
7
- x86_64-darwin: "238ae95c68a8d4601d2e4e2c2583090750cd70e647c0342f73699ab772b35335"
4
+ x86-linux: "79162dfc4dee8954869d2820e60e8d15d4f4915f66e29bedd15e68030acd5b27"
5
+ x86_64-linux: "117ac0ff29240a518717fcf52f7cd3eeec69a135c481693b8eb259bb4c2b528c"
6
+ x86_64-linux-musl: "bab4030060eb4b83d0543839e0f51b09545d7d5b20c3f7dd35ae6f81f3189499"
7
+ x86_64-darwin: "1c0fdb68c0dde34a1b0842403db2ea2ca6a0de2fb7d729e869f395f6d10383b5"
@@ -38,6 +38,7 @@ module Skylight
38
38
 
39
39
  # @api private
40
40
  TIERS = %w(
41
+ rack
41
42
  api
42
43
  app
43
44
  view
@@ -67,6 +68,12 @@ module Skylight
67
68
  Instrumenter.stop!(*args)
68
69
  end
69
70
 
71
+ # Check tracing
72
+ def self.tracing?
73
+ inst = Instrumenter.instance
74
+ inst && inst.current_trace
75
+ end
76
+
70
77
  # Start a trace
71
78
  def self.trace(endpoint=nil, cat=nil, title=nil)
72
79
  unless inst = Instrumenter.instance
@@ -40,6 +40,17 @@ module Skylight
40
40
  end
41
41
  end
42
42
 
43
+ def self.with_after_close(resp, &block)
44
+ # Responses should be finished but in some situations they aren't
45
+ # e.g. https://github.com/ruby-grape/grape/issues/1041
46
+ if resp.respond_to?(:finish)
47
+ resp = resp.finish
48
+ end
49
+
50
+ resp[2] = BodyProxy.new(resp[2], &block)
51
+ resp
52
+ end
53
+
43
54
  include Util::Logging
44
55
 
45
56
  # For Util::Logging
@@ -51,7 +62,13 @@ module Skylight
51
62
  end
52
63
 
53
64
  def call(env)
54
- if env["REQUEST_METHOD"] == "HEAD"
65
+ # Skylight can handle double tracing, but avoid the BodyProxy if we don't need it
66
+ # This generally shouldn't happen, but older verions of Rails can allow the same
67
+ # middleware to be inserted multiple times
68
+ if Skylight.tracing?
69
+ t { "already tracing, skipping" }
70
+ @app.call(env)
71
+ elsif env["REQUEST_METHOD"] == "HEAD"
55
72
  t { "middleware skipping HEAD" }
56
73
  @app.call(env)
57
74
  else
@@ -60,14 +77,11 @@ module Skylight
60
77
  trace = Skylight.trace "Rack", 'app.rack.request'
61
78
  resp = @app.call(env)
62
79
 
63
- # Responses should be finished but in some situations they aren't
64
- # e.g. https://github.com/ruby-grape/grape/issues/1041
65
- if resp.respond_to?(:finish)
66
- resp = resp.finish
80
+ if trace
81
+ Middleware.with_after_close(resp) { trace.submit }
82
+ else
83
+ resp
67
84
  end
68
-
69
- resp[2] = BodyProxy.new(resp[2]) { trace.submit } if trace
70
- resp
71
85
  rescue Exception
72
86
  t { "middleware exception: #{trace}"}
73
87
  trace.submit if trace
@@ -0,0 +1,51 @@
1
+ module Skylight
2
+ module Probes
3
+ module Middleware
4
+ class Probe
5
+ def install
6
+ ActionDispatch::MiddlewareStack::Middleware.class_eval do
7
+ alias build_without_sk build
8
+ def build(*args)
9
+ sk_instrument_middleware(build_without_sk(*args))
10
+ end
11
+
12
+ def sk_instrument_middleware(middleware)
13
+ return middleware if middleware.is_a?(Skylight::Middleware)
14
+
15
+ # Not sure how this would actually happen
16
+ return middleware if middleware.respond_to?(:call_without_sk)
17
+
18
+ # On Rails 3, ActionDispatch::Session::CookieStore is frozen, for one
19
+ return middleware if middleware.frozen?
20
+
21
+ middleware.instance_eval do
22
+ alias call_without_sk call
23
+ def call(*args, &block)
24
+ trace = Skylight::Instrumenter.try(:instance).try(:current_trace)
25
+ return call_without_sk(*args, &block) unless trace
26
+
27
+ begin
28
+ trace.endpoint = self.class.name
29
+
30
+ span = Skylight.instrument(title: self.class.name, category: "rack.middleware")
31
+ resp = call_without_sk(*args, &block)
32
+
33
+ Skylight::Middleware.with_after_close(resp) { trace.done(span) }
34
+ rescue Exception
35
+ # FIXME: Log this?
36
+ trace.done(span)
37
+ raise
38
+ end
39
+ end
40
+ end
41
+
42
+ middleware
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ register("ActionDispatch::MiddlewareStack::Middleware", "actionpack/action_dispatch", Middleware::Probe.new)
50
+ end
51
+ end
@@ -17,6 +17,10 @@ module Skylight
17
17
  # Also available: excon, redis, sinatra, tilt, sequel
18
18
  config.skylight.probes = ['net_http', 'action_controller', 'action_view', 'grape']
19
19
 
20
+ # The position in the middleware stack to place Skylight
21
+ # Default is first, but can be `{ after: Middleware::Name }` or `{ before: Middleware::Name }`
22
+ config.skylight.middleware_position = 0
23
+
20
24
  initializer 'skylight.configure' do |app|
21
25
  # Load probes even when agent is inactive to catch probe related bugs sooner
22
26
  load_probes
@@ -27,7 +31,7 @@ module Skylight
27
31
  if config
28
32
  begin
29
33
  if Instrumenter.start!(config)
30
- app.middleware.insert 0, Middleware, config: config
34
+ set_middleware_position(app, config)
31
35
  Rails.logger.info "[SKYLIGHT] [#{Skylight::VERSION}] Skylight agent enabled"
32
36
  else
33
37
  Rails.logger.info "[SKYLIGHT] [#{Skylight::VERSION}] Unable to start, see the Skylight logs for more details"
@@ -121,5 +125,31 @@ module Skylight
121
125
  require "skylight/probes/#{p}"
122
126
  end
123
127
  end
128
+
129
+ def middleware_position
130
+ config.skylight.middleware_position.is_a?(Hash) ? config.skylight.middleware_position.symbolize_keys : config.skylight.middleware_position
131
+ end
132
+
133
+ def insert_middleware(app, config)
134
+ if middleware_position.has_key?(:after)
135
+ app.middleware.insert_after(middleware_position[:after], Skylight::Middleware, config: config)
136
+ elsif middleware_position.has_key?(:before)
137
+ app.middleware.insert_before(middleware_position[:before], Skylight::Middleware, config: config)
138
+ else
139
+ raise "The middleware position you have set is invalid. Please be sure `config.skylight.middleware_position` is set up correctly."
140
+ end
141
+ end
142
+
143
+ def set_middleware_position(app, config)
144
+ if middleware_position.is_a?(Integer)
145
+ app.middleware.insert middleware_position, Middleware, config: config
146
+ elsif middleware_position.is_a?(Hash) && middleware_position.keys.count == 1
147
+ insert_middleware(app, config)
148
+ elsif middleware_position.nil?
149
+ app.middleware.insert 0, Middleware, config: config
150
+ else
151
+ raise "The middleware position you have set is invalid. Please be sure `config.skylight.middleware_position` is set up correctly."
152
+ end
153
+ end
124
154
  end
125
155
  end
@@ -1,4 +1,4 @@
1
1
  module Skylight
2
- VERSION = '1.3.1'
2
+ VERSION = '1.4.0-beta'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skylight
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-23 00:00:00.000000000 Z
11
+ date: 2017-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -95,6 +95,7 @@ files:
95
95
  - lib/skylight/probes/excon/middleware.rb
96
96
  - lib/skylight/probes/grape.rb
97
97
  - lib/skylight/probes/httpclient.rb
98
+ - lib/skylight/probes/middleware.rb
98
99
  - lib/skylight/probes/mongo.rb
99
100
  - lib/skylight/probes/mongoid.rb
100
101
  - lib/skylight/probes/moped.rb
@@ -184,9 +185,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
185
  version: 1.9.2
185
186
  required_rubygems_version: !ruby/object:Gem::Requirement
186
187
  requirements:
187
- - - ">="
188
+ - - ">"
188
189
  - !ruby/object:Gem::Version
189
- version: '0'
190
+ version: 1.3.1
190
191
  requirements: []
191
192
  rubyforge_project:
192
193
  rubygems_version: 2.6.11