skylight 4.2.2 → 5.0.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/CONTRIBUTING.md +1 -7
  4. data/ext/extconf.rb +6 -5
  5. data/ext/libskylight.yml +5 -6
  6. data/ext/skylight_native.c +24 -100
  7. data/lib/skylight.rb +204 -14
  8. data/lib/skylight/api.rb +7 -3
  9. data/lib/skylight/cli.rb +4 -3
  10. data/lib/skylight/cli/doctor.rb +13 -14
  11. data/lib/skylight/cli/merger.rb +6 -4
  12. data/lib/skylight/config.rb +604 -127
  13. data/lib/skylight/deprecation.rb +17 -0
  14. data/lib/skylight/errors.rb +17 -2
  15. data/lib/skylight/extensions.rb +107 -0
  16. data/lib/skylight/extensions/source_location.rb +280 -0
  17. data/lib/skylight/formatters/http.rb +19 -0
  18. data/lib/skylight/gc.rb +109 -0
  19. data/lib/skylight/helpers.rb +18 -2
  20. data/lib/skylight/instrumenter.rb +326 -15
  21. data/lib/skylight/middleware.rb +138 -1
  22. data/lib/skylight/native.rb +51 -1
  23. data/lib/skylight/native_ext_fetcher.rb +4 -3
  24. data/lib/skylight/normalizers.rb +151 -0
  25. data/lib/skylight/normalizers/action_controller/process_action.rb +69 -0
  26. data/lib/skylight/normalizers/action_controller/send_file.rb +50 -0
  27. data/lib/skylight/normalizers/action_dispatch/process_middleware.rb +22 -0
  28. data/lib/skylight/normalizers/action_dispatch/route_set.rb +27 -0
  29. data/lib/skylight/normalizers/action_view/render_collection.rb +24 -0
  30. data/lib/skylight/normalizers/action_view/render_layout.rb +25 -0
  31. data/lib/skylight/normalizers/action_view/render_partial.rb +23 -0
  32. data/lib/skylight/normalizers/action_view/render_template.rb +23 -0
  33. data/lib/skylight/normalizers/active_job/perform.rb +86 -0
  34. data/lib/skylight/normalizers/active_model_serializers/render.rb +28 -0
  35. data/lib/skylight/normalizers/active_record/instantiation.rb +16 -0
  36. data/lib/skylight/normalizers/active_record/sql.rb +12 -0
  37. data/lib/skylight/normalizers/active_storage.rb +30 -0
  38. data/lib/skylight/normalizers/active_support/cache.rb +22 -0
  39. data/lib/skylight/normalizers/active_support/cache_clear.rb +16 -0
  40. data/lib/skylight/normalizers/active_support/cache_decrement.rb +16 -0
  41. data/lib/skylight/normalizers/active_support/cache_delete.rb +16 -0
  42. data/lib/skylight/normalizers/active_support/cache_exist.rb +16 -0
  43. data/lib/skylight/normalizers/active_support/cache_fetch_hit.rb +16 -0
  44. data/lib/skylight/normalizers/active_support/cache_generate.rb +16 -0
  45. data/lib/skylight/normalizers/active_support/cache_increment.rb +16 -0
  46. data/lib/skylight/normalizers/active_support/cache_read.rb +16 -0
  47. data/lib/skylight/normalizers/active_support/cache_read_multi.rb +16 -0
  48. data/lib/skylight/normalizers/active_support/cache_write.rb +16 -0
  49. data/lib/skylight/normalizers/coach/handler_finish.rb +46 -0
  50. data/lib/skylight/normalizers/coach/middleware_finish.rb +33 -0
  51. data/lib/skylight/normalizers/couch_potato/query.rb +20 -0
  52. data/lib/skylight/normalizers/data_mapper/sql.rb +12 -0
  53. data/lib/skylight/normalizers/default.rb +32 -0
  54. data/lib/skylight/normalizers/elasticsearch/request.rb +20 -0
  55. data/lib/skylight/normalizers/faraday/request.rb +40 -0
  56. data/lib/skylight/normalizers/grape/endpoint.rb +34 -0
  57. data/lib/skylight/normalizers/grape/endpoint_render.rb +25 -0
  58. data/lib/skylight/normalizers/grape/endpoint_run.rb +41 -0
  59. data/lib/skylight/normalizers/grape/endpoint_run_filters.rb +22 -0
  60. data/lib/skylight/normalizers/grape/format_response.rb +20 -0
  61. data/lib/skylight/normalizers/graphiti/render.rb +22 -0
  62. data/lib/skylight/normalizers/graphiti/resolve.rb +31 -0
  63. data/lib/skylight/normalizers/graphql/base.rb +132 -0
  64. data/lib/skylight/normalizers/render.rb +81 -0
  65. data/lib/skylight/normalizers/sequel/sql.rb +12 -0
  66. data/lib/skylight/normalizers/sql.rb +45 -0
  67. data/lib/skylight/probes.rb +181 -0
  68. data/lib/skylight/probes/action_controller.rb +48 -0
  69. data/lib/skylight/probes/action_dispatch.rb +2 -0
  70. data/lib/skylight/probes/action_dispatch/request_id.rb +29 -0
  71. data/lib/skylight/probes/action_dispatch/routing/route_set.rb +28 -0
  72. data/lib/skylight/probes/action_view.rb +43 -0
  73. data/lib/skylight/probes/active_job.rb +27 -0
  74. data/lib/skylight/probes/active_job_enqueue.rb +35 -0
  75. data/lib/skylight/probes/active_model_serializers.rb +50 -0
  76. data/lib/skylight/probes/delayed_job.rb +148 -0
  77. data/lib/skylight/probes/elasticsearch.rb +38 -0
  78. data/lib/skylight/probes/excon.rb +25 -0
  79. data/lib/skylight/probes/excon/middleware.rb +66 -0
  80. data/lib/skylight/probes/faraday.rb +23 -0
  81. data/lib/skylight/probes/graphql.rb +43 -0
  82. data/lib/skylight/probes/httpclient.rb +44 -0
  83. data/lib/skylight/probes/middleware.rb +126 -0
  84. data/lib/skylight/probes/mongo.rb +163 -0
  85. data/lib/skylight/probes/mongoid.rb +13 -0
  86. data/lib/skylight/probes/net_http.rb +54 -0
  87. data/lib/skylight/probes/redis.rb +60 -0
  88. data/lib/skylight/probes/sequel.rb +33 -0
  89. data/lib/skylight/probes/sinatra.rb +63 -0
  90. data/lib/skylight/probes/sinatra_add_middleware.rb +10 -10
  91. data/lib/skylight/probes/tilt.rb +27 -0
  92. data/lib/skylight/railtie.rb +162 -18
  93. data/lib/skylight/sidekiq.rb +48 -0
  94. data/lib/skylight/subscriber.rb +110 -0
  95. data/lib/skylight/test.rb +146 -0
  96. data/lib/skylight/trace.rb +305 -10
  97. data/lib/skylight/user_config.rb +61 -0
  98. data/lib/skylight/util.rb +12 -0
  99. data/lib/skylight/util/allocation_free.rb +26 -0
  100. data/lib/skylight/util/clock.rb +56 -0
  101. data/lib/skylight/util/component.rb +5 -2
  102. data/lib/skylight/util/deploy.rb +7 -10
  103. data/lib/skylight/util/gzip.rb +20 -0
  104. data/lib/skylight/util/http.rb +5 -11
  105. data/lib/skylight/util/instrumenter_method.rb +26 -0
  106. data/lib/skylight/util/logging.rb +138 -0
  107. data/lib/skylight/util/lru_cache.rb +40 -0
  108. data/lib/skylight/vendor/cli/thor/rake_compat.rb +1 -1
  109. data/lib/skylight/version.rb +5 -1
  110. data/lib/skylight/vm/gc.rb +68 -0
  111. metadata +117 -19
@@ -0,0 +1,50 @@
1
+ module Skylight
2
+ module Normalizers
3
+ module ActionController
4
+ enabled = true
5
+
6
+ # Temporary hacks
7
+ begin
8
+ require "action_dispatch/http/mime_type"
9
+ require "action_dispatch/http/mime_types"
10
+ require "rack/utils"
11
+ rescue LoadError
12
+ enabled = false
13
+ end
14
+
15
+ if enabled
16
+ class SendFile < Normalizer
17
+ register "send_file.action_controller"
18
+
19
+ CAT = "app.controller.send_file".freeze
20
+ TITLE = "send file".freeze
21
+
22
+ def normalize(_trace, _name, _payload)
23
+ title = TITLE
24
+
25
+ # depending on normalization, we probably want this to eventually
26
+ # include the full path, but we need to make sure we have a good
27
+ # deduping strategy first.
28
+ desc = nil
29
+
30
+ [CAT, title, desc]
31
+ end
32
+
33
+ private
34
+
35
+ OCTET_STREAM = "application/octet-stream".freeze
36
+ ATTACHMENT = "attachment".freeze
37
+
38
+ def initialize(*)
39
+ super
40
+
41
+ @mimes = Mime::SET.each_with_object({}) do |mime, hash|
42
+ hash[mime.symbol] = mime.to_s.dup.freeze
43
+ hash
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Skylight
4
+ module Normalizers
5
+ module ActionDispatch
6
+ class ProcessMiddleware < Normalizer
7
+ register "process_middleware.action_dispatch"
8
+
9
+ CAT = "rack.middleware"
10
+ ANONYMOUS_MIDDLEWARE = "Anonymous Middleware"
11
+ ANONYMOUS = /\A#<(Class|Module|Proc):/.freeze
12
+
13
+ def normalize(trace, _name, payload)
14
+ name = payload[:middleware].to_s
15
+ name = ANONYMOUS_MIDDLEWARE if name[ANONYMOUS]
16
+ trace.endpoint = name
17
+ [CAT, name, nil]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ module Skylight
2
+ module Normalizers
3
+ module ActionDispatch
4
+ class RouteSet < Normalizer
5
+ register "route_set.action_dispatch"
6
+
7
+ CAT = "rack.app".freeze
8
+
9
+ def normalize(trace, _name, _payload)
10
+ trace.endpoint = router_class_name
11
+ [CAT, trace.endpoint, nil]
12
+ end
13
+
14
+ private
15
+
16
+ def router_class_name
17
+ "ActionDispatch::Routing::RouteSet"
18
+ end
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
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ require "skylight/normalizers/render"
2
+
3
+ module Skylight
4
+ module Normalizers
5
+ module ActionView
6
+ # Normalizer for Rails collection rendering
7
+ class RenderCollection < RenderNormalizer
8
+ register "render_collection.action_view"
9
+
10
+ CAT = "view.render.collection".freeze
11
+
12
+ # @param trace [Skylight::Messages::Trace::Builder] ignored, only present to match API
13
+ # @param name [String] ignored, only present to match API
14
+ # @param payload (see RenderNormalizer#normalize_render)
15
+ # @option payload (see RenderNormalizer#normalize_render)
16
+ # @option payload [Integer] :count
17
+ # @return (see RenderNormalizer#normalize_render)
18
+ def normalize(_trace, _name, payload)
19
+ normalize_render(CAT, payload)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "skylight/normalizers/render"
4
+
5
+ module Skylight
6
+ module Normalizers
7
+ module ActionView
8
+ # Normalizer for Rails layout rendering
9
+ class RenderLayout < RenderNormalizer
10
+ register "render_layout.action_view"
11
+
12
+ CAT = "view.render.layout"
13
+
14
+ # @param trace [Skylight::Messages::Trace::Builder] ignored, only present to match API
15
+ # @param name [String] ignored, only present to match API
16
+ # @param payload (see RenderNormalizer#normalize_render)
17
+ # @option payload (see RenderNormalizer#normalize_render)
18
+ # @return (see RenderNormalizer#normalize_render)
19
+ def normalize(_trace, _name, payload)
20
+ normalize_render(CAT, payload)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ require "skylight/normalizers/render"
2
+
3
+ module Skylight
4
+ module Normalizers
5
+ module ActionView
6
+ # Normalizer for Rails partial rendering
7
+ class RenderPartial < RenderNormalizer
8
+ register "render_partial.action_view"
9
+
10
+ CAT = "view.render.template".freeze
11
+
12
+ # @param trace [Skylight::Messages::Trace::Builder] ignored, only present to match API
13
+ # @param name [String] ignored, only present to match API
14
+ # @param payload (see RenderNormalizer#normalize_render)
15
+ # @option payload (see RenderNormalizer#normalize_render)
16
+ # @return (see RenderNormalizer#normalize_render)
17
+ def normalize(_trace, _name, payload)
18
+ normalize_render(CAT, payload)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require "skylight/normalizers/render"
2
+
3
+ module Skylight
4
+ module Normalizers
5
+ module ActionView
6
+ # Normalizer for Rails template rendering
7
+ class RenderTemplate < RenderNormalizer
8
+ register "render_template.action_view"
9
+
10
+ CAT = "view.render.template".freeze
11
+
12
+ # @param trace [Skylight::Messages::Trace::Builder] ignored, only present to match API
13
+ # @param name [String] ignored, only present to match API
14
+ # @param payload (see RenderNormalizer#normalize_render)
15
+ # @option payload (see RenderNormalizer#normalize_render)
16
+ # @return (see RenderNormalizer#normalize_render)
17
+ def normalize(_trace, _name, payload)
18
+ normalize_render(CAT, payload)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,86 @@
1
+ module Skylight
2
+ module Normalizers
3
+ module ActiveJob
4
+ class Perform < Normalizer
5
+ register "perform.active_job"
6
+
7
+ DELIVERY_JOB = /\AActionMailer::(Mail)?DeliveryJob\Z/.freeze
8
+ DELAYED_JOB_WRAPPER = "ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper".freeze
9
+
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]
15
+ end
16
+ end
17
+ end
18
+
19
+ CAT = "app.job.perform".freeze
20
+
21
+ def normalize(trace, _name, payload)
22
+ title = payload[:job].class.to_s
23
+ adapter_name = normalize_adapter_name(payload[:adapter])
24
+ desc = "{ adapter: '#{adapter_name}', queue: '#{payload[:job].queue_name}' }"
25
+
26
+ maybe_set_endpoint(trace, payload)
27
+
28
+ [CAT, title, desc]
29
+ end
30
+
31
+ def normalize_after(trace, _span, _name, payload)
32
+ return unless config.enable_segments? && assign_endpoint?(trace, payload)
33
+
34
+ trace.segment = payload[:job].queue_name
35
+ end
36
+
37
+ private
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[: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
50
+
51
+ def maybe_set_endpoint(trace, payload)
52
+ if assign_endpoint?(trace, payload)
53
+ trace.endpoint = normalize_title(payload[:job])
54
+ end
55
+ end
56
+
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
64
+
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
77
+ end
78
+
79
+ def normalize_title(job_instance)
80
+ title, * = self.class.normalize_title(job_instance)
81
+ title
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,28 @@
1
+ module Skylight
2
+ module Normalizers
3
+ module ActiveModelSerializers
4
+ class Render < Normalizer
5
+ register "render.active_model_serializers"
6
+
7
+ CAT = "view.render.active_model_serializers".freeze
8
+ ANONYMOUS = "<Anonymous Serializer>".freeze
9
+
10
+ def normalize(_trace, _name, payload)
11
+ serializer_class = payload[:serializer]
12
+
13
+ title = serializer_class.name || ANONYMOUS
14
+ title = title.sub(/^ActiveModel::(Serializer::)?/, "")
15
+
16
+ if (adapter_instance = payload[:adapter])
17
+ adapter_name = adapter_instance.class.name.to_s.
18
+ sub(/^ActiveModel::Serializer::Adapter::/, "").
19
+ sub(/^ActiveModelSerializers::Adapter::/, "")
20
+ desc = "Adapter: #{adapter_name}"
21
+ end
22
+
23
+ [CAT, title, desc]
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ module Skylight
2
+ module Normalizers
3
+ module ActiveRecord
4
+ class Instantiation < Normalizer
5
+ register "instantiation.active_record"
6
+
7
+ CAT = "db.active_record.instantiation".freeze
8
+
9
+ def normalize(_trace, _name, payload)
10
+ # Payload also includes `:record_count` but this will be variable
11
+ [CAT, "#{payload[:class_name]} Instantiation", nil]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ require "skylight/normalizers/sql"
2
+
3
+ module Skylight
4
+ module Normalizers
5
+ module ActiveRecord
6
+ # Normalizer for SQL requests
7
+ class SQL < Skylight::Normalizers::SQL
8
+ register "sql.active_record"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,30 @@
1
+ module Skylight
2
+ module Normalizers
3
+ class ActiveStorage < Normalizer
4
+ TITLES = {
5
+ "preview.active_storage" => "Preview",
6
+ "transform.active_storage" => "Transform",
7
+ "service_download.active_storage" => "Download",
8
+ "service_upload.active_storage" => "Upload",
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"
15
+ }.freeze
16
+
17
+ TITLES.each_key do |key|
18
+ register key
19
+ end
20
+
21
+ def normalize(_trace, name, _payload)
22
+ title = ["ActiveStorage", TITLES[name]].join(" ")
23
+
24
+ cat = "app.#{name.split('.').reverse.join('.')}"
25
+
26
+ [cat, title, nil]
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ module Skylight
2
+ module Normalizers
3
+ module ActiveSupport
4
+ class Cache < Normalizer
5
+ %w[
6
+ clear
7
+ decrement
8
+ delete
9
+ exist
10
+ fetch_hit
11
+ generate
12
+ increment
13
+ read
14
+ read_multi
15
+ write
16
+ ].each do |type|
17
+ require "skylight/normalizers/active_support/cache_#{type}"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module Skylight
2
+ module Normalizers
3
+ module ActiveSupport
4
+ class CacheClear < Cache
5
+ register "cache_clear.active_support"
6
+
7
+ CAT = "app.cache.clear".freeze
8
+ TITLE = "cache clear".freeze
9
+
10
+ def normalize(_trace, _name, _payload)
11
+ [CAT, TITLE, nil]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Skylight
2
+ module Normalizers
3
+ module ActiveSupport
4
+ class CacheDecrement < Cache
5
+ register "cache_decrement.active_support"
6
+
7
+ CAT = "app.cache.decrement".freeze
8
+ TITLE = "cache decrement".freeze
9
+
10
+ def normalize(_trace, _name, _payload)
11
+ [CAT, TITLE, nil]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Skylight
2
+ module Normalizers
3
+ module ActiveSupport
4
+ class CacheDelete < Cache
5
+ register "cache_delete.active_support"
6
+
7
+ CAT = "app.cache.delete".freeze
8
+ TITLE = "cache delete".freeze
9
+
10
+ def normalize(_trace, _name, _payload)
11
+ [CAT, TITLE, nil]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end