skylight 1.7.2 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -33
  3. data/ext/extconf.rb +32 -6
  4. data/ext/libskylight.yml +6 -9
  5. data/ext/skylight_native.c +49 -18
  6. data/lib/skylight.rb +35 -1
  7. data/lib/skylight/api.rb +4 -2
  8. data/lib/skylight/cli.rb +1 -1
  9. data/lib/skylight/cli/doctor.rb +6 -4
  10. data/lib/skylight/config.rb +149 -518
  11. data/lib/skylight/data/cacert.pem +236 -812
  12. data/lib/skylight/helpers.rb +5 -1
  13. data/lib/skylight/instrumenter.rb +10 -241
  14. data/lib/skylight/middleware.rb +1 -89
  15. data/lib/skylight/native.rb +8 -6
  16. data/lib/skylight/native_ext_fetcher.rb +251 -0
  17. data/lib/skylight/normalizers/active_job/enqueue_at.rb +2 -20
  18. data/lib/skylight/probes/sinatra_add_middleware.rb +22 -0
  19. data/lib/skylight/railtie.rb +11 -131
  20. data/lib/skylight/sinatra.rb +1 -5
  21. data/lib/skylight/trace.rb +1 -229
  22. data/lib/skylight/util/http.rb +3 -3
  23. data/lib/skylight/vendor/cli/thor/actions/directory.rb +5 -15
  24. data/lib/skylight/version.rb +1 -1
  25. metadata +114 -91
  26. data/lib/skylight/compat.rb +0 -76
  27. data/lib/skylight/core.rb +0 -149
  28. data/lib/skylight/deprecation.rb +0 -55
  29. data/lib/skylight/formatters/http.rb +0 -20
  30. data/lib/skylight/gc.rb +0 -107
  31. data/lib/skylight/normalizers.rb +0 -192
  32. data/lib/skylight/normalizers/action_controller/process_action.rb +0 -50
  33. data/lib/skylight/normalizers/action_controller/send_file.rb +0 -50
  34. data/lib/skylight/normalizers/action_view/render_collection.rb +0 -22
  35. data/lib/skylight/normalizers/action_view/render_partial.rb +0 -21
  36. data/lib/skylight/normalizers/action_view/render_template.rb +0 -21
  37. data/lib/skylight/normalizers/active_model_serializers/render.rb +0 -26
  38. data/lib/skylight/normalizers/active_record/instantiation.rb +0 -17
  39. data/lib/skylight/normalizers/active_record/sql.rb +0 -55
  40. data/lib/skylight/normalizers/active_support/cache.rb +0 -51
  41. data/lib/skylight/normalizers/active_support/cache_clear.rb +0 -16
  42. data/lib/skylight/normalizers/active_support/cache_decrement.rb +0 -16
  43. data/lib/skylight/normalizers/active_support/cache_delete.rb +0 -16
  44. data/lib/skylight/normalizers/active_support/cache_exist.rb +0 -16
  45. data/lib/skylight/normalizers/active_support/cache_fetch_hit.rb +0 -16
  46. data/lib/skylight/normalizers/active_support/cache_generate.rb +0 -16
  47. data/lib/skylight/normalizers/active_support/cache_increment.rb +0 -16
  48. data/lib/skylight/normalizers/active_support/cache_read.rb +0 -16
  49. data/lib/skylight/normalizers/active_support/cache_read_multi.rb +0 -16
  50. data/lib/skylight/normalizers/active_support/cache_write.rb +0 -16
  51. data/lib/skylight/normalizers/coach/handler_finish.rb +0 -36
  52. data/lib/skylight/normalizers/coach/middleware_finish.rb +0 -23
  53. data/lib/skylight/normalizers/couch_potato/query.rb +0 -20
  54. data/lib/skylight/normalizers/default.rb +0 -27
  55. data/lib/skylight/normalizers/elasticsearch/request.rb +0 -20
  56. data/lib/skylight/normalizers/faraday/request.rb +0 -38
  57. data/lib/skylight/normalizers/grape/endpoint.rb +0 -30
  58. data/lib/skylight/normalizers/grape/endpoint_render.rb +0 -26
  59. data/lib/skylight/normalizers/grape/endpoint_run.rb +0 -33
  60. data/lib/skylight/normalizers/grape/endpoint_run_filters.rb +0 -23
  61. data/lib/skylight/normalizers/moped/query.rb +0 -100
  62. data/lib/skylight/probes.rb +0 -129
  63. data/lib/skylight/probes/action_controller.rb +0 -64
  64. data/lib/skylight/probes/action_dispatch.rb +0 -30
  65. data/lib/skylight/probes/action_view.rb +0 -43
  66. data/lib/skylight/probes/active_model_serializers.rb +0 -55
  67. data/lib/skylight/probes/elasticsearch.rb +0 -37
  68. data/lib/skylight/probes/excon.rb +0 -26
  69. data/lib/skylight/probes/excon/middleware.rb +0 -68
  70. data/lib/skylight/probes/faraday.rb +0 -22
  71. data/lib/skylight/probes/grape.rb +0 -88
  72. data/lib/skylight/probes/httpclient.rb +0 -46
  73. data/lib/skylight/probes/middleware.rb +0 -68
  74. data/lib/skylight/probes/mongo.rb +0 -161
  75. data/lib/skylight/probes/mongoid.rb +0 -21
  76. data/lib/skylight/probes/moped.rb +0 -39
  77. data/lib/skylight/probes/net_http.rb +0 -58
  78. data/lib/skylight/probes/redis.rb +0 -71
  79. data/lib/skylight/probes/sequel.rb +0 -37
  80. data/lib/skylight/probes/sinatra.rb +0 -76
  81. data/lib/skylight/probes/tilt.rb +0 -31
  82. data/lib/skylight/subscriber.rb +0 -122
  83. data/lib/skylight/user_config.rb +0 -60
  84. data/lib/skylight/util.rb +0 -17
  85. data/lib/skylight/util/allocation_free.rb +0 -26
  86. data/lib/skylight/util/clock.rb +0 -54
  87. data/lib/skylight/util/deploy.rb +0 -132
  88. data/lib/skylight/util/gzip.rb +0 -21
  89. data/lib/skylight/util/inflector.rb +0 -112
  90. data/lib/skylight/util/logging.rb +0 -127
  91. data/lib/skylight/util/multi_io.rb +0 -21
  92. data/lib/skylight/util/native_ext_fetcher.rb +0 -253
  93. data/lib/skylight/util/platform.rb +0 -75
  94. data/lib/skylight/util/proxy.rb +0 -13
  95. data/lib/skylight/vendor/active_support/notifications.rb +0 -207
  96. data/lib/skylight/vendor/active_support/notifications/fanout.rb +0 -159
  97. data/lib/skylight/vendor/active_support/notifications/instrumenter.rb +0 -72
  98. data/lib/skylight/vendor/active_support/per_thread_registry.rb +0 -52
  99. data/lib/skylight/vendor/thread_safe.rb +0 -126
  100. data/lib/skylight/vendor/thread_safe/non_concurrent_cache_backend.rb +0 -133
  101. data/lib/skylight/vendor/thread_safe/synchronized_cache_backend.rb +0 -76
  102. data/lib/skylight/vm/gc.rb +0 -70
@@ -1,55 +0,0 @@
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
@@ -1,20 +0,0 @@
1
- module Skylight
2
- module Formatters
3
- module HTTP
4
-
5
- # Build instrumentation options for HTTP queries
6
- #
7
- # @param [String] method HTTP method, e.g. get, post
8
- # @param [String] scheme HTTP scheme, e.g. http, https
9
- # @param [String] host Request host, e.g. example.com
10
- # @param [String, Integer] port Request port
11
- # @param [String] path Request path
12
- # @param [String] query Request query string
13
- # @return [Hash] a hash containing `:category`, `:title`, and `:annotations`
14
- def self.build_opts(method, scheme, host, port, path, query)
15
- { category: "api.http.#{method.downcase}",
16
- title: "#{method.upcase} #{host}" }
17
- end
18
- end
19
- end
20
- end
@@ -1,107 +0,0 @@
1
- require 'thread'
2
-
3
- module Skylight
4
- # @api private
5
- class GC
6
- METHODS = [ :enable, :total_time ]
7
- TH_KEY = :SK_GC_CURR_WINDOW
8
- MAX_COUNT = 1000
9
- MAX_TIME = 30_000_000
10
-
11
- include Util::Logging
12
-
13
- attr_reader :config
14
-
15
- def initialize(config, profiler)
16
- @listeners = []
17
- @config = config
18
- @lock = Mutex.new
19
- @time = 0
20
-
21
- if METHODS.all? { |m| profiler.respond_to?(m) }
22
- @profiler = profiler
23
- @time = @profiler.total_time
24
- else
25
- debug "disabling GC profiling"
26
- end
27
- end
28
-
29
- def enable
30
- @profiler.enable if @profiler
31
- end
32
-
33
- def track
34
- unless @profiler
35
- win = Window.new(nil)
36
- else
37
- win = Window.new(self)
38
-
39
- @lock.synchronize do
40
- __update
41
- @listeners << win
42
-
43
- # Cleanup any listeners that might have leaked
44
- until @listeners[0].time < MAX_TIME
45
- @listeners.shift
46
- end
47
-
48
- if @listeners.length > MAX_COUNT
49
- @listeners.shift
50
- end
51
- end
52
- end
53
-
54
- win
55
- end
56
-
57
- def release(win)
58
- @lock.synchronize do
59
- @listeners.delete(win)
60
- end
61
- end
62
-
63
- def update
64
- @lock.synchronize do
65
- __update
66
- end
67
-
68
- nil
69
- end
70
-
71
- private
72
-
73
- def __update
74
- time = @profiler.total_time
75
- diff = time - @time
76
- @time = time
77
-
78
- if diff > 0
79
- @listeners.each do |l|
80
- l.add(diff)
81
- end
82
- end
83
- end
84
-
85
- class Window
86
- attr_reader :time
87
-
88
- def initialize(global)
89
- @global = global
90
- @time = 0
91
- end
92
-
93
- def update
94
- @global.update if @global
95
- end
96
-
97
- def add(time)
98
- @time += time
99
- end
100
-
101
- def release
102
- @global.release(self) if @global
103
- end
104
- end
105
-
106
- end
107
- end
@@ -1,192 +0,0 @@
1
- require 'skylight/normalizers/default'
2
-
3
- module Skylight
4
- # @api private
5
- # Convert AS::N events to Skylight events
6
- module Normalizers
7
-
8
- DEFAULT = Default.new
9
-
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
25
- end
26
-
27
- def self.build(config)
28
- normalizers = {}
29
-
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
-
37
- unless klass.method_defined?(:normalize)
38
- # TODO: Warn
39
- next
40
- end
41
-
42
- normalizers[key] = klass.new(config)
43
- end
44
-
45
- Container.new(normalizers)
46
- end
47
-
48
- class Normalizer
49
- def self.register(name, opts={})
50
- Normalizers.register(name, self, opts)
51
- end
52
-
53
- attr_reader :config
54
-
55
- def initialize(config)
56
- @config = config
57
- setup if respond_to?(:setup)
58
- end
59
-
60
- def normalize(trace, name, payload)
61
- :skip
62
- end
63
-
64
- def normalize_after(trace, span, name, payload)
65
- end
66
- end
67
-
68
- # FIXME: Move this elsewhere
69
- # Base Normalizer for Rails rendering
70
- class RenderNormalizer < Normalizer
71
- include Util::AllocationFree
72
-
73
- def setup
74
- @paths = config['normalizers.render.view_paths'] || []
75
- end
76
-
77
- # Generic normalizer for renders
78
- # @param category [String]
79
- # @param payload [Hash]
80
- # @option payload [String] :identifier
81
- # @return [Array]
82
- def normalize_render(category, payload)
83
- if path = payload[:identifier]
84
- title = relative_path(path)
85
- path = nil if path == title
86
- end
87
-
88
- [ category, title, nil ]
89
- end
90
-
91
- def relative_path(path)
92
- return path if relative_path?(path)
93
-
94
- root = array_find(@paths) { |p| path.start_with?(p) }
95
- type = :project
96
-
97
- unless root
98
- root = array_find(Gem.path) { |p| path.start_with?(p) }
99
- type = :gem
100
- end
101
-
102
- if root
103
- start = root.size
104
- start += 1 if path.getbyte(start) == SEPARATOR_BYTE
105
- if type == :gem
106
- "$GEM_PATH/#{path[start, path.size]}"
107
- else
108
- path[start, path.size]
109
- end
110
- else
111
- "Absolute Path"
112
- end
113
- end
114
-
115
- private
116
- def relative_path?(path)
117
- !absolute_path?(path)
118
- end
119
-
120
- SEPARATOR_BYTE = File::SEPARATOR.ord
121
-
122
- if File.const_defined?(:NULL) ? File::NULL == "NUL" : RbConfig::CONFIG['host_os'] =~ /mingw|mswin32/
123
- # This is a DOSish environment
124
- ALT_SEPARATOR_BYTE = File::ALT_SEPARATOR && File::ALT_SEPARATOR.ord
125
- COLON_BYTE = ":".ord
126
- def absolute_path?(path)
127
- if alpha?(path.getbyte(0)) && path.getbyte(1) == COLON_BYTE
128
- byte2 = path.getbyte(2)
129
- byte2 == SEPARATOR_BYTE || byte2 == ALT_SEPARATOR_BYTE
130
- end
131
- end
132
-
133
- def alpha?(byte)
134
- byte >= 65 and byte <= 90 || byte >= 97 and byte <= 122
135
- end
136
- else
137
- def absolute_path?(path)
138
- path.getbyte(0) == SEPARATOR_BYTE
139
- end
140
- end
141
- end
142
-
143
- class Container
144
- def initialize(normalizers)
145
- @normalizers = normalizers
146
- end
147
-
148
- def keys
149
- @normalizers.keys
150
- end
151
-
152
- def normalize(trace, name, payload)
153
- normalizer_for(name).normalize(trace, name, payload)
154
- end
155
-
156
- def normalize_after(trace, span, name, payload)
157
- normalizer_for(name).normalize_after(trace, span, name, payload)
158
- end
159
-
160
- def normalizer_for(name)
161
- @normalizers[name] || DEFAULT
162
- end
163
- end
164
-
165
- %w( action_controller/process_action
166
- action_controller/send_file
167
- action_view/render_collection
168
- action_view/render_partial
169
- action_view/render_template
170
- active_model_serializers/render
171
- active_record/instantiation
172
- active_record/sql
173
- active_support/cache
174
- elasticsearch/request
175
- grape/endpoint
176
- moped/query
177
- faraday/request
178
- couch_potato/query).each do |file|
179
- require "skylight/normalizers/#{file}"
180
- end
181
-
182
- # Coach instrumentation is only available in Ruby 2+
183
- if RUBY_VERSION.split.first.to_i > 1
184
- %w(coach/handler_finish coach/middleware_finish).each do |file|
185
- require "skylight/normalizers/#{file}"
186
- end
187
- end
188
-
189
- # The following are not required by default as they are of dubious usefulness:
190
- # - active_job/enqueue_at
191
- end
192
- end
@@ -1,50 +0,0 @@
1
- module Skylight
2
- module Normalizers
3
- module ActionController
4
- # Normalizer for processing a Rails controller action
5
- class ProcessAction < Normalizer
6
- register "process_action.action_controller"
7
-
8
- CAT = "app.controller.request".freeze
9
-
10
- # Payload Keys: controller, action, params, format, method, path
11
- # Additional keys available in `normalize_after`: status, view_runtime
12
- # Along with ones added by probe: variant
13
-
14
- # @param trace [Skylight::Messages::Trace::Builder]
15
- # @param name [String] ignored, only present to match API
16
- # @param payload [Hash]
17
- # @option payload [String] :controller Controller name
18
- # @option payload [String] :action Action name
19
- # @return [Array]
20
- def normalize(trace, name, payload)
21
- trace.endpoint = controller_action(payload)
22
- [ CAT, trace.endpoint, nil ]
23
- end
24
-
25
- def normalize_after(trace, span, name, payload)
26
- return unless config.enable_segments?
27
-
28
- # Show 'error' if there's an unhandled exception or if the status is 4xx or 5xx
29
- if payload[:exception] || payload[:status].to_s =~ /^[45]/
30
- segment = "error"
31
- # We won't have a rendered_format if it's a `head` outside of a `respond_to` block.
32
- elsif payload[:rendered_format]
33
- # We only show the variant if we actually have a format
34
- segment = [payload[:rendered_format], payload[:variant]].compact.flatten.join('+')
35
- end
36
-
37
- if segment
38
- trace.endpoint += "<sk-segment>#{segment}</sk-segment>"
39
- end
40
- end
41
-
42
- private
43
-
44
- def controller_action(payload)
45
- "#{payload[:controller]}##{payload[:action]}"
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,50 +0,0 @@
1
- module Skylight
2
- module Normalizers
3
- module ActionController
4
-
5
- # Temporary hacks
6
- begin
7
- require "action_dispatch/http/mime_type"
8
- require "action_dispatch/http/mime_types"
9
- require "rack/utils"
10
-
11
- class SendFile < Normalizer
12
- register "send_file.action_controller"
13
-
14
- CAT = "app.controller.send_file".freeze
15
- TITLE = "send file".freeze
16
-
17
- def normalize(trace, name, payload)
18
- path = payload[:path]
19
-
20
- title = TITLE
21
-
22
- # depending on normalization, we probably want this to eventually
23
- # include the full path, but we need to make sure we have a good
24
- # deduping strategy first.
25
- desc = nil
26
-
27
- [ CAT, title, desc ]
28
- end
29
-
30
- private
31
-
32
- OCTET_STREAM = "application/octet-stream".freeze
33
- ATTACHMENT = "attachment".freeze
34
-
35
- def initialize(*)
36
- super
37
-
38
- @mimes = Mime::SET.reduce({}) do |hash, mime|
39
- hash[mime.symbol] = mime.to_s.dup.freeze
40
- hash
41
- end
42
- end
43
- end
44
-
45
- rescue LoadError
46
- end
47
-
48
- end
49
- end
50
- end