skylight 5.0.0.beta4 → 5.1.0.beta2

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +399 -362
  3. data/CLA.md +1 -1
  4. data/CONTRIBUTING.md +1 -1
  5. data/LICENSE.md +7 -17
  6. data/README.md +1 -1
  7. data/ext/extconf.rb +42 -54
  8. data/ext/libskylight.yml +10 -5
  9. data/lib/skylight.rb +20 -30
  10. data/lib/skylight/api.rb +22 -18
  11. data/lib/skylight/cli.rb +47 -46
  12. data/lib/skylight/cli/doctor.rb +50 -50
  13. data/lib/skylight/cli/helpers.rb +19 -19
  14. data/lib/skylight/cli/merger.rb +141 -139
  15. data/lib/skylight/config.rb +267 -310
  16. data/lib/skylight/deprecation.rb +4 -4
  17. data/lib/skylight/errors.rb +3 -4
  18. data/lib/skylight/extensions.rb +17 -29
  19. data/lib/skylight/extensions/source_location.rb +128 -128
  20. data/lib/skylight/formatters/http.rb +1 -3
  21. data/lib/skylight/gc.rb +30 -40
  22. data/lib/skylight/helpers.rb +57 -30
  23. data/lib/skylight/instrumenter.rb +25 -18
  24. data/lib/skylight/middleware.rb +31 -35
  25. data/lib/skylight/native.rb +8 -10
  26. data/lib/skylight/native_ext_fetcher.rb +10 -12
  27. data/lib/skylight/normalizers.rb +43 -38
  28. data/lib/skylight/normalizers/action_controller/process_action.rb +24 -25
  29. data/lib/skylight/normalizers/action_controller/send_file.rb +7 -6
  30. data/lib/skylight/normalizers/action_dispatch/route_set.rb +7 -7
  31. data/lib/skylight/normalizers/active_job/perform.rb +48 -44
  32. data/lib/skylight/normalizers/active_model_serializers/render.rb +7 -3
  33. data/lib/skylight/normalizers/active_storage.rb +11 -13
  34. data/lib/skylight/normalizers/active_support/cache.rb +1 -12
  35. data/lib/skylight/normalizers/coach/handler_finish.rb +1 -3
  36. data/lib/skylight/normalizers/default.rb +1 -9
  37. data/lib/skylight/normalizers/faraday/request.rb +1 -3
  38. data/lib/skylight/normalizers/grape/endpoint.rb +13 -19
  39. data/lib/skylight/normalizers/grape/endpoint_run.rb +16 -18
  40. data/lib/skylight/normalizers/grape/endpoint_run_filters.rb +1 -3
  41. data/lib/skylight/normalizers/graphql/base.rb +23 -28
  42. data/lib/skylight/normalizers/render.rb +19 -21
  43. data/lib/skylight/normalizers/shrine.rb +32 -0
  44. data/lib/skylight/normalizers/sql.rb +4 -4
  45. data/lib/skylight/probes.rb +38 -46
  46. data/lib/skylight/probes/action_controller.rb +32 -28
  47. data/lib/skylight/probes/action_dispatch/request_id.rb +9 -5
  48. data/lib/skylight/probes/action_dispatch/routing/route_set.rb +7 -5
  49. data/lib/skylight/probes/action_view.rb +9 -10
  50. data/lib/skylight/probes/active_job_enqueue.rb +3 -9
  51. data/lib/skylight/probes/active_model_serializers.rb +8 -8
  52. data/lib/skylight/probes/delayed_job.rb +37 -42
  53. data/lib/skylight/probes/elasticsearch.rb +4 -6
  54. data/lib/skylight/probes/excon.rb +1 -1
  55. data/lib/skylight/probes/excon/middleware.rb +22 -23
  56. data/lib/skylight/probes/graphql.rb +2 -7
  57. data/lib/skylight/probes/middleware.rb +14 -5
  58. data/lib/skylight/probes/mongo.rb +83 -91
  59. data/lib/skylight/probes/net_http.rb +1 -1
  60. data/lib/skylight/probes/redis.rb +5 -17
  61. data/lib/skylight/probes/sequel.rb +7 -11
  62. data/lib/skylight/probes/sinatra.rb +8 -5
  63. data/lib/skylight/probes/tilt.rb +2 -4
  64. data/lib/skylight/railtie.rb +121 -135
  65. data/lib/skylight/sidekiq.rb +4 -5
  66. data/lib/skylight/subscriber.rb +31 -33
  67. data/lib/skylight/test.rb +89 -84
  68. data/lib/skylight/trace.rb +121 -115
  69. data/lib/skylight/user_config.rb +14 -17
  70. data/lib/skylight/util/clock.rb +1 -0
  71. data/lib/skylight/util/component.rb +18 -21
  72. data/lib/skylight/util/deploy.rb +11 -13
  73. data/lib/skylight/util/http.rb +104 -105
  74. data/lib/skylight/util/logging.rb +4 -6
  75. data/lib/skylight/util/lru_cache.rb +2 -6
  76. data/lib/skylight/util/platform.rb +2 -6
  77. data/lib/skylight/util/ssl.rb +1 -25
  78. data/lib/skylight/version.rb +1 -1
  79. data/lib/skylight/vm/gc.rb +1 -9
  80. metadata +20 -5
@@ -17,7 +17,8 @@ module Skylight
17
17
 
18
18
  include FileUtils
19
19
 
20
- class FetchError < StandardError; end
20
+ class FetchError < StandardError
21
+ end
21
22
 
22
23
  # Creates a new fetcher and fetches
23
24
  # @param opts [Hash]
@@ -56,7 +57,7 @@ module Skylight
56
57
  # @return [String] the inflated archive
57
58
  def fetch
58
59
  log "fetching native ext; curr-platform=#{@platform}; " \
59
- "requested-arch=#{@arch}; version=#{@version}"
60
+ "requested-arch=#{@arch}; version=#{@version}"
60
61
 
61
62
  tar_gz = "#{@target}/#{basename}"
62
63
 
@@ -109,11 +110,12 @@ module Skylight
109
110
  next
110
111
  end
111
112
  end
112
- rescue => e
113
+ rescue StandardError => e
113
114
  remaining_attempts -= 1
114
115
 
115
116
  error "failed to fetch native extension; uri=#{uri}; msg=#{e.message}; " \
116
- "remaining-attempts=#{remaining_attempts}", e
117
+ "remaining-attempts=#{remaining_attempts}",
118
+ e
117
119
 
118
120
  if remaining_attempts > 0
119
121
  sleep 2
@@ -149,9 +151,7 @@ module Skylight
149
151
  opts = {}
150
152
  opts[:use_ssl] = use_ssl
151
153
 
152
- if use_ssl
153
- opts[:ca_file] = Util::SSL.ca_cert_file_or_default
154
- end
154
+ opts[:ca_file] = Util::SSL.ca_cert_file_or_default if use_ssl
155
155
 
156
156
  Net::HTTP.start(host, port, p_host, p_port, p_user, p_pass, use_ssl: use_ssl) do |http|
157
157
  http.request_get path do |resp|
@@ -164,13 +164,13 @@ module Skylight
164
164
  out.write chunk
165
165
  end
166
166
 
167
- return [:success, digest.hexdigest]
167
+ return :success, digest.hexdigest
168
168
  when Net::HTTPRedirection
169
169
  unless (location = resp["location"])
170
170
  raise "received redirect but no location"
171
171
  end
172
172
 
173
- return [:redirect, location]
173
+ return :redirect, location
174
174
  else
175
175
  raise "received HTTP status code #{resp.code}"
176
176
  end
@@ -221,9 +221,7 @@ module Skylight
221
221
  def maybe_raise(err)
222
222
  error err
223
223
 
224
- if @required
225
- raise err
226
- end
224
+ raise err if @required
227
225
  end
228
226
 
229
227
  # Log an `info` to the `logger`
@@ -79,18 +79,18 @@ module Skylight
79
79
 
80
80
  private
81
81
 
82
- def process_meta(trace, _name, payload, meta, cache_key: nil)
83
- trace.instrumenter.extensions.process_normalizer_meta(
84
- payload,
85
- meta,
86
- cache_key: cache_key,
87
- **process_meta_options(payload)
88
- )
89
- end
82
+ def process_meta(trace, _name, payload, meta, cache_key: nil)
83
+ trace.instrumenter.extensions.process_normalizer_meta(
84
+ payload,
85
+ meta,
86
+ cache_key: cache_key,
87
+ **process_meta_options(payload)
88
+ )
89
+ end
90
90
 
91
- def process_meta_options(_payload)
92
- {}
93
- end
91
+ def process_meta_options(_payload)
92
+ {}
93
+ end
94
94
  end
95
95
 
96
96
  require "skylight/normalizers/default"
@@ -105,6 +105,10 @@ module Skylight
105
105
  @normalizers.keys
106
106
  end
107
107
 
108
+ def each_key(&block)
109
+ @normalizers.each_key(&block)
110
+ end
111
+
108
112
  def normalize(trace, name, payload)
109
113
  normalizer_for(name).normalize_with_meta(trace, name, payload)
110
114
  end
@@ -121,32 +125,33 @@ module Skylight
121
125
  end
122
126
  end
123
127
 
124
- %w[ action_controller/process_action
125
- action_controller/send_file
126
- action_dispatch/process_middleware
127
- action_dispatch/route_set
128
- action_view/render_collection
129
- action_view/render_partial
130
- action_view/render_template
131
- action_view/render_layout
132
- active_job/perform
133
- active_model_serializers/render
134
- active_record/instantiation
135
- active_record/sql
136
- active_storage
137
- active_support/cache
138
- coach/handler_finish
139
- coach/middleware_finish
140
- couch_potato/query
141
- data_mapper/sql
142
- elasticsearch/request
143
- faraday/request
144
- grape/endpoint
145
- graphiti/resolve
146
- graphiti/render
147
- graphql/base
148
- sequel/sql].each do |file|
149
- require "skylight/normalizers/#{file}"
150
- end
128
+ %w[
129
+ action_controller/process_action
130
+ action_controller/send_file
131
+ action_dispatch/process_middleware
132
+ action_dispatch/route_set
133
+ action_view/render_collection
134
+ action_view/render_partial
135
+ action_view/render_template
136
+ action_view/render_layout
137
+ active_job/perform
138
+ active_model_serializers/render
139
+ active_record/instantiation
140
+ active_record/sql
141
+ active_storage
142
+ active_support/cache
143
+ coach/handler_finish
144
+ coach/middleware_finish
145
+ couch_potato/query
146
+ data_mapper/sql
147
+ elasticsearch/request
148
+ faraday/request
149
+ grape/endpoint
150
+ graphiti/resolve
151
+ graphiti/render
152
+ graphql/base
153
+ sequel/sql
154
+ shrine
155
+ ].each { |file| require "skylight/normalizers/#{file}" }
151
156
  end
152
157
  end
@@ -32,37 +32,36 @@ module Skylight
32
32
 
33
33
  private
34
34
 
35
- def controller_action(payload)
36
- "#{payload[:controller]}##{payload[:action]}"
37
- end
35
+ def controller_action(payload)
36
+ "#{payload[:controller]}##{payload[:action]}"
37
+ end
38
38
 
39
- def process_meta_options(payload)
40
- # provide hints to override default source_location behavior
41
- super.merge(source_location_hint: [:instance_method, payload[:controller], payload[:action]])
42
- end
39
+ def process_meta_options(payload)
40
+ # provide hints to override default source_location behavior
41
+ super.merge(source_location_hint: [:instance_method, payload[:controller], payload[:action]])
42
+ end
43
43
 
44
- def segment_from_payload(payload)
45
- # Show 'error' if there's an unhandled exception or if the status is 4xx or 5xx
46
- return "error" if payload[:exception] || payload[:exception_object]
44
+ def segment_from_payload(payload)
45
+ # Show 'error' if there's an unhandled exception or if the status is 4xx or 5xx
46
+ return "error" if payload[:exception] || payload[:exception_object]
47
47
 
48
- segment_from_status(payload[:status]) ||
49
- if payload[:sk_rendered_format]
50
- # We only show the variant if we actually have a format
51
- # We won't have a sk_rendered_format if it's a `head` outside of a `respond_to` block.
52
- [payload[:sk_rendered_format], payload[:sk_variant]].compact.flatten.join("+")
53
- end
48
+ segment_from_status(payload[:status]) || if payload[:sk_rendered_format]
49
+ # We only show the variant if we actually have a format
50
+ # We won't have a sk_rendered_format if it's a `head` outside of a `respond_to` block.
51
+ [payload[:sk_rendered_format], payload[:sk_variant]].compact.flatten.join("+")
54
52
  end
53
+ end
55
54
 
56
- def segment_from_status(status)
57
- case status
58
- when 304
59
- "not modified"
60
- when (300..399)
61
- "redirect"
62
- when (400..599)
63
- "error"
64
- end
55
+ def segment_from_status(status)
56
+ case status
57
+ when 304
58
+ "not modified"
59
+ when (300..399)
60
+ "redirect"
61
+ when (400..599)
62
+ "error"
65
63
  end
64
+ end
66
65
  end
67
66
  end
68
67
  end
@@ -32,17 +32,18 @@ module Skylight
32
32
 
33
33
  private
34
34
 
35
- OCTET_STREAM = "application/octet-stream".freeze
36
- ATTACHMENT = "attachment".freeze
35
+ OCTET_STREAM = "application/octet-stream".freeze
36
+ ATTACHMENT = "attachment".freeze
37
37
 
38
- def initialize(*)
39
- super
38
+ def initialize(*)
39
+ super
40
40
 
41
- @mimes = Mime::SET.each_with_object({}) do |mime, hash|
41
+ @mimes =
42
+ Mime::SET.each_with_object({}) do |mime, hash|
42
43
  hash[mime.symbol] = mime.to_s.dup.freeze
43
44
  hash
44
45
  end
45
- end
46
+ end
46
47
  end
47
48
  end
48
49
  end
@@ -13,14 +13,14 @@ module Skylight
13
13
 
14
14
  private
15
15
 
16
- def router_class_name
17
- "ActionDispatch::Routing::RouteSet"
18
- end
16
+ def router_class_name
17
+ "ActionDispatch::Routing::RouteSet"
18
+ end
19
19
 
20
- def process_meta_options(_payload)
21
- # provide hints to override default source_location behavior
22
- super.merge(source_location_hint: [:own_instance_method, router_class_name, "call"])
23
- end
20
+ def process_meta_options(_payload)
21
+ # provide hints to override default source_location behavior
22
+ super.merge(source_location_hint: [:own_instance_method, router_class_name, "call"])
23
+ end
24
24
  end
25
25
  end
26
26
  end
@@ -8,12 +8,16 @@ module Skylight
8
8
  DELAYED_JOB_WRAPPER = "ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper".freeze
9
9
 
10
10
  def self.normalize_title(job_instance)
11
- job_instance.class.name.to_s.tap do |str|
12
- if str.match(DELIVERY_JOB)
13
- mailer_class, mailer_method, * = job_instance.arguments
14
- return ["#{mailer_class}##{mailer_method}", str]
11
+ job_instance
12
+ .class
13
+ .name
14
+ .to_s
15
+ .tap do |str|
16
+ if str.match(DELIVERY_JOB)
17
+ mailer_class, mailer_method, * = job_instance.arguments
18
+ return "#{mailer_class}##{mailer_method}", str
19
+ end
15
20
  end
16
- end
17
21
  end
18
22
 
19
23
  CAT = "app.job.perform".freeze
@@ -36,50 +40,50 @@ module Skylight
36
40
 
37
41
  private
38
42
 
39
- def process_meta_options(payload)
40
- # provide hints to override default source_location behavior
41
- super.merge(source_location_hint: [:instance_method, payload[:job].class.to_s, "perform"])
42
- end
43
-
44
- def normalize_adapter_name(adapter)
45
- adapter_string = adapter.is_a?(Class) ? adapter.to_s : adapter.class.to_s
46
- adapter_string[/ActiveJob::QueueAdapters::(\w+)Adapter/, 1].underscore
47
- rescue
48
- "active_job"
49
- end
43
+ def process_meta_options(payload)
44
+ # provide hints to override default source_location behavior
45
+ super.merge(source_location_hint: [:instance_method, payload[:job].class.to_s, "perform"])
46
+ end
50
47
 
51
- def maybe_set_endpoint(trace, payload)
52
- if assign_endpoint?(trace, payload)
53
- trace.endpoint = normalize_title(payload[:job])
54
- end
55
- end
48
+ def normalize_adapter_name(adapter)
49
+ adapter_string = adapter.is_a?(Class) ? adapter.to_s : adapter.class.to_s
50
+ adapter_string[/ActiveJob::QueueAdapters::(\w+)Adapter/, 1].underscore
51
+ rescue StandardError
52
+ "active_job"
53
+ end
56
54
 
57
- def assign_endpoint?(trace, payload)
58
- # Always assign the endpoint if it has not yet been assigned by the ActiveJob probe.
59
- return true unless trace.endpoint
60
- return true if defined?(Skylight::Probes::ActiveJob::TITLE) &&
61
- trace.endpoint == Skylight::Probes::ActiveJob::TITLE
62
- return true if defined?(SKylight::Probes::DelayedJob::Probe::UNKNOWN) &&
63
- trace.endpoint == Skylight::Probes::DelayedJob::Probe::UNKNOWN
55
+ def maybe_set_endpoint(trace, payload)
56
+ trace.endpoint = normalize_title(payload[:job]) if assign_endpoint?(trace, payload)
57
+ end
64
58
 
65
- # If a job is called using #perform_now inside a controller action
66
- # or within another job's #perform method, we do not want this to
67
- # overwrite the existing endpoint name (unless it is the default from ActiveJob).
68
- #
69
- # If the current endpoint name matches this payload, return true to allow the
70
- # segment to be assigned by normalize_after.
71
- trace.endpoint == DELIVERY_JOB ||
72
- trace.endpoint == normalize_title(payload[:job]) ||
73
- # This adapter wrapper needs to be handled specifically due to interactions with the
74
- # standalone Delayed::Job probe, as there is no consistent way to get the wrapped
75
- # job name among all Delayed::Job backends.
76
- trace.endpoint == DELAYED_JOB_WRAPPER
59
+ def assign_endpoint?(trace, payload)
60
+ # Always assign the endpoint if it has not yet been assigned by the ActiveJob probe.
61
+ return true unless trace.endpoint
62
+ if defined?(Skylight::Probes::ActiveJob::TITLE) && trace.endpoint == Skylight::Probes::ActiveJob::TITLE
63
+ return true
77
64
  end
78
-
79
- def normalize_title(job_instance)
80
- title, * = self.class.normalize_title(job_instance)
81
- title
65
+ if defined?(SKylight::Probes::DelayedJob::Probe::UNKNOWN) &&
66
+ trace.endpoint == Skylight::Probes::DelayedJob::Probe::UNKNOWN
67
+ return true
82
68
  end
69
+
70
+ # If a job is called using #perform_now inside a controller action
71
+ # or within another job's #perform method, we do not want this to
72
+ # overwrite the existing endpoint name (unless it is the default from ActiveJob).
73
+ #
74
+ # If the current endpoint name matches this payload, return true to allow the
75
+ # segment to be assigned by normalize_after.
76
+ trace.endpoint == DELIVERY_JOB || trace.endpoint == normalize_title(payload[:job]) ||
77
+ # This adapter wrapper needs to be handled specifically due to interactions with the
78
+ # standalone Delayed::Job probe, as there is no consistent way to get the wrapped
79
+ # job name among all Delayed::Job backends.
80
+ trace.endpoint == DELAYED_JOB_WRAPPER
81
+ end
82
+
83
+ def normalize_title(job_instance)
84
+ title, * = self.class.normalize_title(job_instance)
85
+ title
86
+ end
83
87
  end
84
88
  end
85
89
  end
@@ -14,9 +14,13 @@ module Skylight
14
14
  title = title.sub(/^ActiveModel::(Serializer::)?/, "")
15
15
 
16
16
  if (adapter_instance = payload[:adapter])
17
- adapter_name = adapter_instance.class.name.to_s.
18
- sub(/^ActiveModel::Serializer::Adapter::/, "").
19
- sub(/^ActiveModelSerializers::Adapter::/, "")
17
+ adapter_name =
18
+ adapter_instance
19
+ .class
20
+ .name
21
+ .to_s
22
+ .sub(/^ActiveModel::Serializer::Adapter::/, "")
23
+ .sub(/^ActiveModelSerializers::Adapter::/, "")
20
24
  desc = "Adapter: #{adapter_name}"
21
25
  end
22
26
 
@@ -2,26 +2,24 @@ module Skylight
2
2
  module Normalizers
3
3
  class ActiveStorage < Normalizer
4
4
  TITLES = {
5
- "preview.active_storage" => "Preview",
6
- "transform.active_storage" => "Transform",
7
- "service_download.active_storage" => "Download",
8
- "service_upload.active_storage" => "Upload",
5
+ "preview.active_storage" => "Preview",
6
+ "transform.active_storage" => "Transform",
7
+ "service_download.active_storage" => "Download",
8
+ "service_upload.active_storage" => "Upload",
9
9
  "service_streaming_download.active_storage" => "Streaming Download",
10
- "service_download_chunk.active_storage" => "Download Chunk",
11
- "service_delete.active_storage" => "Delete",
12
- "service_delete_prefixed.active_storage" => "Delete Prefixed",
13
- "service_exist.active_storage" => "Exist",
14
- "service_url.active_storage" => "Url"
10
+ "service_download_chunk.active_storage" => "Download Chunk",
11
+ "service_delete.active_storage" => "Delete",
12
+ "service_delete_prefixed.active_storage" => "Delete Prefixed",
13
+ "service_exist.active_storage" => "Exist",
14
+ "service_url.active_storage" => "Url"
15
15
  }.freeze
16
16
 
17
- TITLES.each_key do |key|
18
- register key
19
- end
17
+ TITLES.each_key { |key| register key }
20
18
 
21
19
  def normalize(_trace, name, _payload)
22
20
  title = ["ActiveStorage", TITLES[name]].join(" ")
23
21
 
24
- cat = "app.#{name.split('.').reverse.join('.')}"
22
+ cat = "app.#{name.split(".").reverse.join(".")}"
25
23
 
26
24
  [cat, title, nil]
27
25
  end