skylight 1.6.1 → 1.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '08db1b03b0415378e94cba4a1e93f3856bec795769a3bee7786942fdfdb77a30'
4
- data.tar.gz: 294a813cdcf2cfc7b343f7a2c2126628101c1c1a2b320e58c5286d79a5ded016
3
+ metadata.gz: 55eaebadf3fb220c9b3dbccdfc9a7a24daff7eda6775b89e58ea5fe0e2a1ba56
4
+ data.tar.gz: 894eb4d03f6b66ca6301884c98f754f0d03dbdb416e40a662b34733e2c5c19f5
5
5
  SHA512:
6
- metadata.gz: 9c5d6044ebeb3d41030716f10642a422c0e3346be27b7820edefc4e0d0abd006b773686cf9a231f7f8300c22db2dd15e76175a18340f4d86aa11170199e7d799
7
- data.tar.gz: 851f31e79a7e4d0924c6c02292a1aaf84c424f72dc8f0cfd6235f570a6358d7abb855df31e24bd0dc36c5ead5efc72a4ac78591195e9cd032deddeb2a46511bd
6
+ metadata.gz: 9e18ee5d48433c0bdb42090e975ccffbd28b34e179a77f252048bccc27669f41b08a6648aabc55b79eac2158ee57ac74b3308f22bc8ff25e2da1d50efe552073
7
+ data.tar.gz: d346a3b7a24e4453324273320c8400d998302a4c658957aef9274fd40f8735c2f33f8245e6ef33ed1dbc39ac081b0fb7bee7addce81f02c4c1457257bf3cddb7
@@ -1,3 +1,12 @@
1
+ ## 1.7.0 (April 24, 2018)
2
+
3
+ * [FEATURE] New API for loading Probes. Example: `Skylight.probe(:excon')`
4
+ * [FEATURE] New API for enabling non-default Normalizers. Example: `Skylight.enable_normalizer('active_job')`
5
+ * [DEPRECATION] Support for Rails versions prior to 4.2
6
+ * [DEPRECATION] Support for Tilt versions prior to 1.4.1
7
+ * [DEPRECATION] Support for Sinatra versions prior to 1.4
8
+ * [DEPRECATION] Support for Grape versions prior to 0.13.0
9
+
1
10
  ## 1.6.1 (April 12, 2018)
2
11
 
3
12
  * [IMPROVEMENT] Include endpoint name in error logging
@@ -1,7 +1,9 @@
1
1
  require 'skylight/version'
2
+ require 'skylight/deprecation'
2
3
 
3
4
  # Root Skylight namespace
4
5
  module Skylight
6
+
5
7
  # @api private
6
8
  TRACE_ENV_KEY = 'SKYLIGHT_ENABLE_TRACE_LOGS'.freeze
7
9
 
@@ -11,6 +13,10 @@ module Skylight
11
13
  # Specifically check for Railtie since we've had at least one case of a
12
14
  # customer having Rails defined without having all of Rails loaded.
13
15
  if defined?(Rails::Railtie)
16
+ if Gem::Version.new(Rails.version) < Gem::Version.new('4.2.0')
17
+ DEPRECATOR.deprecation_warning("Support for Rails versions before 4.2")
18
+ end
19
+
14
20
  require 'skylight/railtie'
15
21
  end
16
22
 
@@ -59,6 +65,14 @@ module Skylight
59
65
  # @api private
60
66
  DEFAULT_OPTIONS = { category: DEFAULT_CATEGORY }
61
67
 
68
+ def self.probe(*args)
69
+ Probes.probe(*args)
70
+ end
71
+
72
+ def self.enable_normalizer(*names)
73
+ Normalizers.enable(*names)
74
+ end
75
+
62
76
  # Start instrumenting
63
77
  def self.start!(*args)
64
78
  Instrumenter.start!(*args)
@@ -0,0 +1,55 @@
1
+ require 'active_support/deprecation'
2
+
3
+ module Skylight
4
+ SKYLIGHT_GEM_ROOT = File.expand_path("../../..", __FILE__) + "/"
5
+
6
+ if ActiveSupport::Deprecation.respond_to?(:new)
7
+ class Deprecation < ActiveSupport::Deprecation
8
+ private
9
+
10
+ def ignored_callstack(path)
11
+ path.start_with?(SKYLIGHT_GEM_ROOT)
12
+ end
13
+ end
14
+ else
15
+ # Rails 3.x
16
+ class Deprecation
17
+ attr_accessor :silenced
18
+ attr_reader :deprecation_horizon, :gem_name
19
+
20
+ def initialize(deprecation_horizon, gem_name)
21
+ @deprecation_horizon = deprecation_horizon
22
+ @gem_name = gem_name
23
+ end
24
+
25
+ # Silence deprecation warnings within the block.
26
+ def silence
27
+ old_silenced, @silenced = @silenced, true
28
+ yield
29
+ ensure
30
+ @silenced = old_silenced
31
+ end
32
+
33
+ def deprecation_warning(deprecated_method_name, message = nil)
34
+ return if silenced
35
+
36
+ msg = "#{deprecated_method_name} is deprecated and will be removed from #{gem_name} #{deprecation_horizon}"
37
+ case message
38
+ when Symbol then msg << " (use #{message} instead)"
39
+ when String then msg << " (#{message})"
40
+ end
41
+
42
+ ActiveSupport::Deprecation.warn(msg, extract_callstack(caller))
43
+ end
44
+
45
+ private
46
+
47
+ def extract_callstack(callstack)
48
+ filtered = callstack.reject { |line| line.start_with?(SKYLIGHT_GEM_ROOT) }
49
+ filtered.empty? ? callstack : filtered
50
+ end
51
+ end
52
+ end
53
+
54
+ DEPRECATOR = Deprecation.new('2.0', 'skylight')
55
+ end
@@ -7,29 +7,47 @@ module Skylight
7
7
 
8
8
  DEFAULT = Default.new
9
9
 
10
- def self.register(name, klass)
11
- (@registry ||= {})[name] = klass
12
- klass
10
+ def self.registry
11
+ @registry ||= {}
12
+ end
13
+
14
+ def self.register(name, klass, opts)
15
+ enabled = opts[:enabled] != false
16
+ registry[name] = [klass, enabled]
17
+ end
18
+
19
+ def self.enable(*names)
20
+ names.each do |name|
21
+ matches = registry.select{|n,_| n =~ /(^|\.)#{name}$/ }
22
+ raise ArgumentError, "no normalizers match #{name}" if matches.empty?
23
+ matches.each{|k,v| v[1] = true }
24
+ end
13
25
  end
14
26
 
15
27
  def self.build(config)
16
28
  normalizers = {}
17
29
 
18
- (@registry || {}).each do |k, klass|
30
+ registry.each do |key, (klass, enabled)|
31
+ if !enabled
32
+ # For now we use anyway, but in 2.0 we'll stop using disabled normalizers
33
+ DEPRECATOR.deprecation_warning("Enabling non-default normalizers via `require`",
34
+ "use `Skylight.enable_normalizer('#{key}')` instead")
35
+ end
36
+
19
37
  unless klass.method_defined?(:normalize)
20
38
  # TODO: Warn
21
39
  next
22
40
  end
23
41
 
24
- normalizers[k] = klass.new(config)
42
+ normalizers[key] = klass.new(config)
25
43
  end
26
44
 
27
45
  Container.new(normalizers)
28
46
  end
29
47
 
30
48
  class Normalizer
31
- def self.register(name)
32
- Normalizers.register(name, self)
49
+ def self.register(name, opts={})
50
+ Normalizers.register(name, self, opts)
33
51
  end
34
52
 
35
53
  attr_reader :config
@@ -47,6 +65,7 @@ module Skylight
47
65
  end
48
66
  end
49
67
 
68
+ # FIXME: Move this elsewhere
50
69
  # Base Normalizer for Rails rendering
51
70
  class RenderNormalizer < Normalizer
52
71
  include Util::AllocationFree
@@ -2,7 +2,7 @@ module Skylight
2
2
  module Normalizers
3
3
  module ActiveJob
4
4
  class EnqueueAt < Normalizer
5
- register "enqueue_at.active_job"
5
+ register "enqueue_at.active_job", enabled: false
6
6
 
7
7
  CAT = "other.job.enqueue_at".freeze
8
8
 
@@ -1,10 +1,13 @@
1
+ require 'pathname'
2
+
1
3
  module Skylight
2
4
  # @api private
3
5
  module Probes
4
6
  class ProbeRegistration
5
- attr_reader :klass_name, :require_paths, :probe
7
+ attr_reader :name, :klass_name, :require_paths, :probe
6
8
 
7
- def initialize(klass_name, require_paths, probe)
9
+ def initialize(name, klass_name, require_paths, probe)
10
+ @name = name
8
11
  @klass_name = klass_name
9
12
  @require_paths = Array(require_paths)
10
13
  @probe = probe
@@ -15,6 +18,34 @@ module Skylight
15
18
  end
16
19
  end
17
20
 
21
+ def self.available
22
+ unless @available
23
+ root = Pathname.new(File.expand_path("../probes", __FILE__))
24
+ @available = {}
25
+ Dir["#{root}/**/*.rb"].each do |f|
26
+ name = Pathname.new(f).relative_path_from(root).sub_ext('').to_s
27
+ @available[name] = "skylight/probes/#{name}"
28
+ end
29
+ end
30
+ @available
31
+ end
32
+
33
+ def self.probe(*probes)
34
+ unknown = probes.map(&:to_s) - available.keys
35
+ unless unknown.empty?
36
+ raise ArgumentError, "unknown probes: #{unknown.join(', ')}"
37
+ end
38
+
39
+ probes.each do |p|
40
+ begin
41
+ @via_api = true
42
+ require available[p.to_s]
43
+ ensure
44
+ @via_api = false
45
+ end
46
+ end
47
+ end
48
+
18
49
  def self.require_hooks
19
50
  @require_hooks ||= {}
20
51
  end
@@ -27,8 +58,13 @@ module Skylight
27
58
  !!Skylight::Util::Inflector.safe_constantize(klass_name)
28
59
  end
29
60
 
30
- def self.register(*args)
31
- registration = ProbeRegistration.new(*args)
61
+ def self.register(name, *args)
62
+ unless @via_api
63
+ DEPRECATOR.deprecation_warning("Enabling probes via `require` alone",
64
+ "use `Skylight.probe(:#{name})` instead")
65
+ end
66
+
67
+ registration = ProbeRegistration.new(name, *args)
32
68
 
33
69
  if is_available?(registration.klass_name)
34
70
  installed[registration.klass_name] = registration
@@ -59,6 +59,6 @@ module Skylight
59
59
  end
60
60
  end
61
61
 
62
- register("ActionController::Instrumentation", "action_controller/metal/instrumentation", ActionController::Probe.new)
62
+ register(:action_controller, "ActionController::Instrumentation", "action_controller/metal/instrumentation", ActionController::Probe.new)
63
63
  end
64
64
  end
@@ -38,6 +38,6 @@ module Skylight
38
38
  end
39
39
  end
40
40
 
41
- register("ActionView::TemplateRenderer", "action_view", ActionView::Probe.new)
41
+ register(:action_view, "ActionView::TemplateRenderer", "action_view", ActionView::Probe.new)
42
42
  end
43
43
  end
@@ -50,6 +50,6 @@ module Skylight
50
50
  end
51
51
  end
52
52
 
53
- register("ActiveModel::Serializer", "active_model/serializer", ActiveModelSerializers::Probe.new)
53
+ register(:active_model_serializers, "ActiveModel::Serializer", "active_model/serializer", ActiveModelSerializers::Probe.new)
54
54
  end
55
55
  end
@@ -32,6 +32,6 @@ module Skylight
32
32
  end
33
33
  end
34
34
 
35
- register("Elasticsearch", "elasticsearch", Elasticsearch::Probe.new)
35
+ register(:elasticsearch, "Elasticsearch", "elasticsearch", Elasticsearch::Probe.new)
36
36
  end
37
37
  end
@@ -21,6 +21,6 @@ module Skylight
21
21
  end
22
22
  end
23
23
 
24
- register("Excon", "excon", Excon::Probe.new)
24
+ register(:excon, "Excon", "excon", Excon::Probe.new)
25
25
  end
26
26
  end
@@ -17,6 +17,6 @@ module Skylight
17
17
  end
18
18
  end
19
19
 
20
- register("Faraday", "faraday", Faraday::Probe.new)
20
+ register(:faraday, "Faraday", "faraday", Faraday::Probe.new)
21
21
  end
22
22
  end
@@ -5,11 +5,13 @@ module Skylight
5
5
  def install
6
6
  version = Gem::Version.new(::Grape::VERSION)
7
7
 
8
- if version > Gem::Version.new("0.12.1")
8
+ if version >= Gem::Version.new("0.13.0")
9
9
  # AS::N is built in to newer versions
10
10
  return
11
11
  end
12
12
 
13
+ Skylight::DEPRECATOR.deprecation_warning("Support for Grape versions before 0.13.0")
14
+
13
15
  if version < Gem::Version.new("0.10.0")
14
16
  # Using $stderr here isn't great, but we don't have a logger accessible
15
17
  $stderr.puts "[SKYLIGHT] [#{Skylight::VERSION}] The Grape probe only works with version 0.10.0+ " \
@@ -81,6 +83,6 @@ module Skylight
81
83
  end
82
84
  end
83
85
 
84
- register("Grape::Endpoint", "grape/endpoint", Grape::Probe.new)
86
+ register(:grape, "Grape::Endpoint", "grape/endpoint", Grape::Probe.new)
85
87
  end
86
88
  end
@@ -41,6 +41,6 @@ module Skylight
41
41
  end # class Probe
42
42
  end # module Probes::HTTPClient
43
43
 
44
- register("HTTPClient", "httpclient", HTTPClient::Probe.new)
44
+ register(:httpclient, "HTTPClient", "httpclient", HTTPClient::Probe.new)
45
45
  end
46
46
  end
@@ -74,6 +74,6 @@ module Skylight
74
74
  end
75
75
  end
76
76
 
77
- register("ActionDispatch::MiddlewareStack::Middleware", "actionpack/action_dispatch", Middleware::Probe.new)
77
+ register(:middleware, "ActionDispatch::MiddlewareStack::Middleware", "actionpack/action_dispatch", Middleware::Probe.new)
78
78
  end
79
79
  end
@@ -156,6 +156,6 @@ module Skylight
156
156
  end
157
157
  end
158
158
 
159
- register("Mongo", "mongo", Mongo::Probe.new)
159
+ register(:mongo, "Mongo", "mongo", Mongo::Probe.new)
160
160
  end
161
161
  end
@@ -8,14 +8,14 @@ module Skylight
8
8
  version = Gem::Version.new(::Mongoid::VERSION)
9
9
 
10
10
  if version < Gem::Version.new("5.0")
11
- require 'skylight/probes/moped'
11
+ Skylight.probe(:moped)
12
12
  else
13
- require 'skylight/probes/mongo'
13
+ Skylight.probe(:mongo)
14
14
  end
15
15
  end
16
16
  end
17
17
  end
18
18
 
19
- register("Mongoid", "mongoid", Mongoid::Probe.new)
19
+ register(:mongoid, "Mongoid", "mongoid", Mongoid::Probe.new)
20
20
  end
21
21
  end
@@ -34,6 +34,6 @@ module Skylight
34
34
  end
35
35
  end
36
36
 
37
- register("Moped", "moped", Moped::Probe.new)
37
+ register(:moped, "Moped", "moped", Moped::Probe.new)
38
38
  end
39
39
  end
@@ -53,6 +53,6 @@ module Skylight
53
53
  end
54
54
  end
55
55
 
56
- register("Net::HTTP", "net/http", NetHTTP::Probe.new)
56
+ register(:net_http, "Net::HTTP", "net/http", NetHTTP::Probe.new)
57
57
  end
58
58
  end
@@ -66,6 +66,6 @@ module Skylight
66
66
  end
67
67
  end
68
68
 
69
- register("Redis", "redis", Redis::Probe.new)
69
+ register(:redis, "Redis", "redis", Redis::Probe.new)
70
70
  end
71
71
  end
@@ -4,6 +4,10 @@ module Skylight
4
4
  module Sequel
5
5
  class Probe
6
6
  def install
7
+ if Gem::Version.new(::Sequel.version) < Gem::Version.new('4.0')
8
+ Skylight::DEPRECATOR.deprecation_warning("Support for Sequel versions before 4.0")
9
+ end
10
+
7
11
  require 'sequel/database/logging'
8
12
 
9
13
  method_name = ::Sequel::Database.method_defined?(:log_connection_yield) ? 'log_connection_yield' : 'log_yield'
@@ -28,6 +32,6 @@ module Skylight
28
32
  end
29
33
  end
30
34
 
31
- register("Sequel", "sequel", Sequel::Probe.new)
35
+ register(:sequel, "Sequel", "sequel", Sequel::Probe.new)
32
36
  end
33
37
  end
@@ -71,6 +71,6 @@ module Skylight
71
71
  end
72
72
  end
73
73
 
74
- register("Sinatra::Base", "sinatra/base", Sinatra::Probe.new)
74
+ register(:sinatra, "Sinatra::Base", "sinatra/base", Sinatra::Probe.new)
75
75
  end
76
76
  end
@@ -4,6 +4,10 @@ module Skylight
4
4
  module Tilt
5
5
  class Probe
6
6
  def install
7
+ if Gem::Version.new(::Tilt::VERSION) < Gem::Version.new('1.4.1')
8
+ Skylight::DEPRECATOR.deprecation_warning("Support for Tilt versions before 1.4.1")
9
+ end
10
+
7
11
  ::Tilt::Template.class_eval do
8
12
  alias render_without_sk render
9
13
 
@@ -22,6 +26,6 @@ module Skylight
22
26
  end
23
27
  end
24
28
 
25
- register("Tilt::Template", "tilt/template", Tilt::Probe.new)
29
+ register(:tilt, "Tilt::Template", "tilt/template", Tilt::Probe.new)
26
30
  end
27
31
  end
@@ -125,9 +125,8 @@ module Skylight
125
125
  end
126
126
 
127
127
  def load_probes
128
- probes = config.skylight.probes || []
129
- probes.each do |p|
130
- require "skylight/probes/#{p}"
128
+ if probes = config.skylight.probes
129
+ Skylight.probe(*probes)
131
130
  end
132
131
  end
133
132
 
@@ -1,4 +1,7 @@
1
1
  require 'skylight'
2
- require 'skylight/probes/sinatra'
3
- require 'skylight/probes/tilt'
4
- require 'skylight/probes/sequel'
2
+
3
+ if Gem::Version(Sinatra::VERSION) < Gem::Version('1.4')
4
+ Skylight::DEPRECATOR.deprecation_warning("Support for Sinatra versions before 1.4")
5
+ end
6
+
7
+ Skylight.probe(:sinatra, :tilt, :sequel)
@@ -1,4 +1,4 @@
1
1
  module Skylight
2
- VERSION = '1.6.1'
2
+ VERSION = '1.7.0'
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.6.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tilde, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-12 00:00:00.000000000 Z
11
+ date: 2018-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -67,6 +67,7 @@ files:
67
67
  - lib/skylight/config.rb
68
68
  - lib/skylight/core.rb
69
69
  - lib/skylight/data/cacert.pem
70
+ - lib/skylight/deprecation.rb
70
71
  - lib/skylight/formatters/http.rb
71
72
  - lib/skylight/gc.rb
72
73
  - lib/skylight/helpers.rb