skylight 1.7.2 → 2.0.0.beta1
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 +4 -4
- data/CHANGELOG.md +4 -33
- data/ext/extconf.rb +32 -6
- data/ext/libskylight.yml +6 -9
- data/ext/skylight_native.c +49 -18
- data/lib/skylight.rb +35 -1
- data/lib/skylight/api.rb +4 -2
- data/lib/skylight/cli.rb +1 -1
- data/lib/skylight/cli/doctor.rb +6 -4
- data/lib/skylight/config.rb +149 -518
- data/lib/skylight/data/cacert.pem +236 -812
- data/lib/skylight/helpers.rb +5 -1
- data/lib/skylight/instrumenter.rb +10 -241
- data/lib/skylight/middleware.rb +1 -89
- data/lib/skylight/native.rb +8 -6
- data/lib/skylight/native_ext_fetcher.rb +251 -0
- data/lib/skylight/normalizers/active_job/enqueue_at.rb +2 -20
- data/lib/skylight/probes/sinatra_add_middleware.rb +22 -0
- data/lib/skylight/railtie.rb +11 -131
- data/lib/skylight/sinatra.rb +1 -5
- data/lib/skylight/trace.rb +1 -229
- data/lib/skylight/util/http.rb +3 -3
- data/lib/skylight/vendor/cli/thor/actions/directory.rb +5 -15
- data/lib/skylight/version.rb +1 -1
- metadata +114 -91
- data/lib/skylight/compat.rb +0 -76
- data/lib/skylight/core.rb +0 -149
- data/lib/skylight/deprecation.rb +0 -55
- data/lib/skylight/formatters/http.rb +0 -20
- data/lib/skylight/gc.rb +0 -107
- data/lib/skylight/normalizers.rb +0 -192
- data/lib/skylight/normalizers/action_controller/process_action.rb +0 -50
- data/lib/skylight/normalizers/action_controller/send_file.rb +0 -50
- data/lib/skylight/normalizers/action_view/render_collection.rb +0 -22
- data/lib/skylight/normalizers/action_view/render_partial.rb +0 -21
- data/lib/skylight/normalizers/action_view/render_template.rb +0 -21
- data/lib/skylight/normalizers/active_model_serializers/render.rb +0 -26
- data/lib/skylight/normalizers/active_record/instantiation.rb +0 -17
- data/lib/skylight/normalizers/active_record/sql.rb +0 -55
- data/lib/skylight/normalizers/active_support/cache.rb +0 -51
- data/lib/skylight/normalizers/active_support/cache_clear.rb +0 -16
- data/lib/skylight/normalizers/active_support/cache_decrement.rb +0 -16
- data/lib/skylight/normalizers/active_support/cache_delete.rb +0 -16
- data/lib/skylight/normalizers/active_support/cache_exist.rb +0 -16
- data/lib/skylight/normalizers/active_support/cache_fetch_hit.rb +0 -16
- data/lib/skylight/normalizers/active_support/cache_generate.rb +0 -16
- data/lib/skylight/normalizers/active_support/cache_increment.rb +0 -16
- data/lib/skylight/normalizers/active_support/cache_read.rb +0 -16
- data/lib/skylight/normalizers/active_support/cache_read_multi.rb +0 -16
- data/lib/skylight/normalizers/active_support/cache_write.rb +0 -16
- data/lib/skylight/normalizers/coach/handler_finish.rb +0 -36
- data/lib/skylight/normalizers/coach/middleware_finish.rb +0 -23
- data/lib/skylight/normalizers/couch_potato/query.rb +0 -20
- data/lib/skylight/normalizers/default.rb +0 -27
- data/lib/skylight/normalizers/elasticsearch/request.rb +0 -20
- data/lib/skylight/normalizers/faraday/request.rb +0 -38
- data/lib/skylight/normalizers/grape/endpoint.rb +0 -30
- data/lib/skylight/normalizers/grape/endpoint_render.rb +0 -26
- data/lib/skylight/normalizers/grape/endpoint_run.rb +0 -33
- data/lib/skylight/normalizers/grape/endpoint_run_filters.rb +0 -23
- data/lib/skylight/normalizers/moped/query.rb +0 -100
- data/lib/skylight/probes.rb +0 -129
- data/lib/skylight/probes/action_controller.rb +0 -64
- data/lib/skylight/probes/action_dispatch.rb +0 -30
- data/lib/skylight/probes/action_view.rb +0 -43
- data/lib/skylight/probes/active_model_serializers.rb +0 -55
- data/lib/skylight/probes/elasticsearch.rb +0 -37
- data/lib/skylight/probes/excon.rb +0 -26
- data/lib/skylight/probes/excon/middleware.rb +0 -68
- data/lib/skylight/probes/faraday.rb +0 -22
- data/lib/skylight/probes/grape.rb +0 -88
- data/lib/skylight/probes/httpclient.rb +0 -46
- data/lib/skylight/probes/middleware.rb +0 -68
- data/lib/skylight/probes/mongo.rb +0 -161
- data/lib/skylight/probes/mongoid.rb +0 -21
- data/lib/skylight/probes/moped.rb +0 -39
- data/lib/skylight/probes/net_http.rb +0 -58
- data/lib/skylight/probes/redis.rb +0 -71
- data/lib/skylight/probes/sequel.rb +0 -37
- data/lib/skylight/probes/sinatra.rb +0 -76
- data/lib/skylight/probes/tilt.rb +0 -31
- data/lib/skylight/subscriber.rb +0 -122
- data/lib/skylight/user_config.rb +0 -60
- data/lib/skylight/util.rb +0 -17
- data/lib/skylight/util/allocation_free.rb +0 -26
- data/lib/skylight/util/clock.rb +0 -54
- data/lib/skylight/util/deploy.rb +0 -132
- data/lib/skylight/util/gzip.rb +0 -21
- data/lib/skylight/util/inflector.rb +0 -112
- data/lib/skylight/util/logging.rb +0 -127
- data/lib/skylight/util/multi_io.rb +0 -21
- data/lib/skylight/util/native_ext_fetcher.rb +0 -253
- data/lib/skylight/util/platform.rb +0 -75
- data/lib/skylight/util/proxy.rb +0 -13
- data/lib/skylight/vendor/active_support/notifications.rb +0 -207
- data/lib/skylight/vendor/active_support/notifications/fanout.rb +0 -159
- data/lib/skylight/vendor/active_support/notifications/instrumenter.rb +0 -72
- data/lib/skylight/vendor/active_support/per_thread_registry.rb +0 -52
- data/lib/skylight/vendor/thread_safe.rb +0 -126
- data/lib/skylight/vendor/thread_safe/non_concurrent_cache_backend.rb +0 -133
- data/lib/skylight/vendor/thread_safe/synchronized_cache_backend.rb +0 -76
- data/lib/skylight/vm/gc.rb +0 -70
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
module Skylight
|
|
2
|
-
module Probes
|
|
3
|
-
module ActionController
|
|
4
|
-
class Probe
|
|
5
|
-
def install
|
|
6
|
-
::ActionController::Instrumentation.class_eval do
|
|
7
|
-
private
|
|
8
|
-
alias append_info_to_payload_without_sk append_info_to_payload
|
|
9
|
-
def append_info_to_payload(payload)
|
|
10
|
-
append_info_to_payload_without_sk(payload)
|
|
11
|
-
rendered_mime = begin
|
|
12
|
-
if respond_to?(:rendered_format)
|
|
13
|
-
rendered_format
|
|
14
|
-
elsif content_type.is_a?(Mime::Type)
|
|
15
|
-
content_type
|
|
16
|
-
elsif content_type.respond_to?(:to_s)
|
|
17
|
-
type_str = content_type.to_s.split(';').first
|
|
18
|
-
Mime::Type.lookup(type_str) unless type_str.blank?
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
payload[:rendered_format] = rendered_mime.try(:ref)
|
|
22
|
-
payload[:variant] = request.respond_to?(:variant) ? request.variant : nil
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
if Gem::Version.new(Rails.version) < Gem::Version.new('4.2.1')
|
|
27
|
-
# Backport https://github.com/rails/rails/pull/17978
|
|
28
|
-
::ActionController::Instrumentation.class_eval do
|
|
29
|
-
def process_action(*args)
|
|
30
|
-
raw_payload = {
|
|
31
|
-
:controller => self.class.name,
|
|
32
|
-
:action => self.action_name,
|
|
33
|
-
:params => request.filtered_parameters,
|
|
34
|
-
:method => request.request_method,
|
|
35
|
-
:path => (request.fullpath rescue "unknown")
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if Gem::Version.new(Rails.version) < Gem::Version.new('3.1')
|
|
39
|
-
raw_payload[:formats] = request.formats.map(&:to_sym)
|
|
40
|
-
else
|
|
41
|
-
raw_payload[:format] = request.format.try(:ref)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
ActiveSupport::Notifications.instrument("start_processing.action_controller", raw_payload.dup)
|
|
45
|
-
|
|
46
|
-
ActiveSupport::Notifications.instrument("process_action.action_controller", raw_payload) do |payload|
|
|
47
|
-
begin
|
|
48
|
-
result = super
|
|
49
|
-
payload[:status] = response.status
|
|
50
|
-
result
|
|
51
|
-
ensure
|
|
52
|
-
append_info_to_payload(payload)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
register(:action_controller, "ActionController::Instrumentation", "action_controller/metal/instrumentation", ActionController::Probe.new)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
module Skylight
|
|
2
|
-
module Probes
|
|
3
|
-
module ActionDispatch
|
|
4
|
-
module Routing
|
|
5
|
-
module RouteSet
|
|
6
|
-
class Probe
|
|
7
|
-
|
|
8
|
-
def install
|
|
9
|
-
::ActionDispatch::Routing::RouteSet.class_eval do
|
|
10
|
-
alias call_without_sk call
|
|
11
|
-
def call(env)
|
|
12
|
-
trace = Skylight::Instrumenter.try(:instance).try(:current_trace)
|
|
13
|
-
return call_without_sk(env) unless trace
|
|
14
|
-
|
|
15
|
-
trace.endpoint = self.class.name
|
|
16
|
-
Skylight.instrument(title: self.class.name, category: 'rack.app') do
|
|
17
|
-
call_without_sk(env)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
register(:rails_router, 'ActionDispatch::Routing::RouteSet', 'action_dispatch/routing/route_set', ActionDispatch::Routing::RouteSet::Probe.new)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
module Skylight
|
|
2
|
-
module Probes
|
|
3
|
-
module ActionView
|
|
4
|
-
class Probe
|
|
5
|
-
def install
|
|
6
|
-
# Rails 3.0 didn't have ActionView::TemplateRenderer, but it also
|
|
7
|
-
# didn't have the bug that this probe is trying to fix. In Rails
|
|
8
|
-
# 3.1, a templating engine refactor moved the layout rendering out
|
|
9
|
-
# of the existing instrumentation, making any other events that
|
|
10
|
-
# happen inside of the layout appear to happen directly inside the
|
|
11
|
-
# parent (usually the controller).
|
|
12
|
-
return if [ActionPack::VERSION::MAJOR, ActionPack::VERSION::MINOR] == [3, 0]
|
|
13
|
-
|
|
14
|
-
::ActionView::TemplateRenderer.class_eval do
|
|
15
|
-
alias render_with_layout_without_sk render_with_layout
|
|
16
|
-
|
|
17
|
-
def render_with_layout(path, locals, *args, &block) #:nodoc:
|
|
18
|
-
layout = nil
|
|
19
|
-
|
|
20
|
-
if path
|
|
21
|
-
if ::ActionView.respond_to?(:gem_version) && ::ActionView.gem_version >= Gem::Version.new('5.x')
|
|
22
|
-
layout = find_layout(path, locals.keys, [formats.first])
|
|
23
|
-
else
|
|
24
|
-
layout = find_layout(path, locals.keys)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
if layout
|
|
29
|
-
instrument(:template, :identifier => layout.identifier) do
|
|
30
|
-
render_with_layout_without_sk(path, locals, *args, &block)
|
|
31
|
-
end
|
|
32
|
-
else
|
|
33
|
-
render_with_layout_without_sk(path, locals, *args, &block)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
register(:action_view, "ActionView::TemplateRenderer", "action_view", ActionView::Probe.new)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
module Skylight
|
|
2
|
-
module Probes
|
|
3
|
-
module ActiveModelSerializers
|
|
4
|
-
class Probe
|
|
5
|
-
def install
|
|
6
|
-
version = nil
|
|
7
|
-
|
|
8
|
-
# File moved location between version
|
|
9
|
-
%w(serializer serializers).each do |dir|
|
|
10
|
-
begin
|
|
11
|
-
require "active_model/#{dir}/version"
|
|
12
|
-
rescue LoadError
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
if defined?(::ActiveModel::Serializer::VERSION)
|
|
17
|
-
version = Gem::Version.new(::ActiveModel::Serializer::VERSION)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
if !version || version < Gem::Version.new("0.5.0")
|
|
21
|
-
# Using $stderr here isn't great, but we don't have a logger accessible
|
|
22
|
-
$stderr.puts "[SKYLIGHT] [#{Skylight::VERSION}] Instrumention is only available for " \
|
|
23
|
-
"ActiveModelSerializers version 0.5.0 and greater."
|
|
24
|
-
return
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# We don't actually support the RCs correctly, requires
|
|
28
|
-
# a release after 0.10.0.rc3
|
|
29
|
-
if version >= Gem::Version.new("0.10.0.rc1")
|
|
30
|
-
# AS::N is built in to newer versions
|
|
31
|
-
return
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# End users could override as_json without calling super, but it's likely safer
|
|
35
|
-
# than overriding serializable_array/hash/object.
|
|
36
|
-
|
|
37
|
-
[::ActiveModel::Serializer, ::ActiveModel::ArraySerializer].each do |klass|
|
|
38
|
-
klass.class_eval do
|
|
39
|
-
alias as_json_without_sk as_json
|
|
40
|
-
def as_json(*args)
|
|
41
|
-
payload = { serializer: self.class }
|
|
42
|
-
ActiveSupport::Notifications.instrument('render.active_model_serializers', payload) do
|
|
43
|
-
as_json_without_sk(*args)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
register(:active_model_serializers, "ActiveModel::Serializer", "active_model/serializer", ActiveModelSerializers::Probe.new)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
module Skylight
|
|
2
|
-
module Probes
|
|
3
|
-
module Elasticsearch
|
|
4
|
-
class Probe
|
|
5
|
-
def install
|
|
6
|
-
::Elasticsearch::Transport::Transport::Base.class_eval do
|
|
7
|
-
alias perform_request_without_sk perform_request
|
|
8
|
-
def perform_request(method, path, *args, &block)
|
|
9
|
-
ActiveSupport::Notifications.instrument "request.elasticsearch",
|
|
10
|
-
name: 'Request',
|
|
11
|
-
method: method,
|
|
12
|
-
path: path do
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
# Prevent HTTP-related probes from firing
|
|
16
|
-
Skylight::Normalizers::Faraday::Request.disable do
|
|
17
|
-
disable_skylight_probe(:NetHTTP) do
|
|
18
|
-
disable_skylight_probe(:HTTPClient) do
|
|
19
|
-
perform_request_without_sk(method, path, *args, &block)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def disable_skylight_probe(class_name, &block)
|
|
27
|
-
klass = Skylight::Probes.const_get(class_name).const_get(:Probe) rescue nil
|
|
28
|
-
klass ? klass.disable(&block) : block.call
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
register(:elasticsearch, "Elasticsearch", "elasticsearch", Elasticsearch::Probe.new)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
module Skylight
|
|
2
|
-
module Probes
|
|
3
|
-
module Excon
|
|
4
|
-
# Probe for instrumenting Excon requests. Installs {Excon::Middleware} to achieve this.
|
|
5
|
-
class Probe
|
|
6
|
-
def install
|
|
7
|
-
if defined?(::Excon::Middleware)
|
|
8
|
-
# Don't require until installation since it depends on Excon being loaded
|
|
9
|
-
require 'skylight/probes/excon/middleware'
|
|
10
|
-
|
|
11
|
-
idx = ::Excon.defaults[:middlewares].index(::Excon::Middleware::Instrumentor)
|
|
12
|
-
|
|
13
|
-
# TODO: Handle possibility of idx being nil
|
|
14
|
-
::Excon.defaults[:middlewares].insert(idx, Skylight::Probes::Excon::Middleware)
|
|
15
|
-
else
|
|
16
|
-
# Using $stderr here isn't great, but we don't have a logger accessible
|
|
17
|
-
$stderr.puts "[SKYLIGHT] [#{Skylight::VERSION}] The installed version of Excon doesn't " \
|
|
18
|
-
"support Middlewares. The Excon probe will be disabled."
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
register(:excon, "Excon", "excon", Excon::Probe.new)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
require 'skylight/formatters/http'
|
|
2
|
-
|
|
3
|
-
module Skylight
|
|
4
|
-
module Probes
|
|
5
|
-
module Excon
|
|
6
|
-
|
|
7
|
-
# Middleware for Excon that instruments requests
|
|
8
|
-
class Middleware < ::Excon::Middleware::Base
|
|
9
|
-
|
|
10
|
-
# This probably won't work since config isn't defined
|
|
11
|
-
include Util::Logging
|
|
12
|
-
|
|
13
|
-
def initialize(*)
|
|
14
|
-
@requests = {}
|
|
15
|
-
super
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# TODO:
|
|
19
|
-
# - Consider whether a LIFO queue would be sufficient
|
|
20
|
-
# - Check that errors can't be called without a request
|
|
21
|
-
|
|
22
|
-
def request_call(datum)
|
|
23
|
-
begin_instrumentation(datum)
|
|
24
|
-
super
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def response_call(datum)
|
|
28
|
-
super
|
|
29
|
-
ensure
|
|
30
|
-
end_instrumentation(datum)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def error_call(datum)
|
|
34
|
-
super
|
|
35
|
-
ensure
|
|
36
|
-
end_instrumentation(datum)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
private
|
|
40
|
-
|
|
41
|
-
def begin_instrumentation(datum)
|
|
42
|
-
method = datum[:method].to_s
|
|
43
|
-
scheme = datum[:scheme]
|
|
44
|
-
host = datum[:host]
|
|
45
|
-
# TODO: Maybe don't show other default ports like 443
|
|
46
|
-
port = datum[:port] != 80 ? datum[:port] : nil
|
|
47
|
-
path = datum[:path]
|
|
48
|
-
query = datum[:query]
|
|
49
|
-
|
|
50
|
-
opts = Formatters::HTTP.build_opts(method, scheme, host, port, path, query)
|
|
51
|
-
|
|
52
|
-
@requests[datum.object_id] = Skylight.instrument(opts)
|
|
53
|
-
rescue Exception => e
|
|
54
|
-
error "failed to begin instrumentation for Excon; msg=%s", e.message
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def end_instrumentation(datum)
|
|
58
|
-
if request = @requests.delete(datum.object_id)
|
|
59
|
-
Skylight.done(request)
|
|
60
|
-
end
|
|
61
|
-
rescue Exception => e
|
|
62
|
-
error "failed to end instrumentation for Excon; msg=%s", e.message
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module Skylight
|
|
2
|
-
module Probes
|
|
3
|
-
module Faraday
|
|
4
|
-
class Probe
|
|
5
|
-
def install
|
|
6
|
-
::Faraday::Connection.class_eval do
|
|
7
|
-
alias initialize_without_sk initialize
|
|
8
|
-
|
|
9
|
-
def initialize(*args, &block)
|
|
10
|
-
initialize_without_sk(*args, &block)
|
|
11
|
-
|
|
12
|
-
@builder.insert 0, ::Faraday::Request::Instrumentation
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
register(:faraday, "Faraday", "faraday", Faraday::Probe.new)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
module Skylight
|
|
2
|
-
module Probes
|
|
3
|
-
module Grape
|
|
4
|
-
class Probe
|
|
5
|
-
def install
|
|
6
|
-
version = Gem::Version.new(::Grape::VERSION)
|
|
7
|
-
|
|
8
|
-
if version >= Gem::Version.new("0.13.0")
|
|
9
|
-
# AS::N is built in to newer versions
|
|
10
|
-
return
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
Skylight::DEPRECATOR.deprecation_warning("Support for Grape versions before 0.13.0")
|
|
14
|
-
|
|
15
|
-
if version < Gem::Version.new("0.10.0")
|
|
16
|
-
# Using $stderr here isn't great, but we don't have a logger accessible
|
|
17
|
-
$stderr.puts "[SKYLIGHT] [#{Skylight::VERSION}] The Grape probe only works with version 0.10.0+ " \
|
|
18
|
-
"and will be disabled."
|
|
19
|
-
|
|
20
|
-
return
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Grape relies on this but does doesn't correctly require it.
|
|
24
|
-
# However, when using ActiveSupport 4 it is implicitly loaded,
|
|
25
|
-
# in AS 3, it will fail.
|
|
26
|
-
# https://github.com/ruby-grape/grape/issues/1087
|
|
27
|
-
require 'active_support/core_ext/hash/except'
|
|
28
|
-
|
|
29
|
-
::Grape::Endpoint.class_eval do
|
|
30
|
-
alias initialize_without_sk initialize
|
|
31
|
-
def initialize(*args, &block)
|
|
32
|
-
initialize_without_sk(*args, &block)
|
|
33
|
-
|
|
34
|
-
# This solution of wrapping the block is effective, but potentially fragile.
|
|
35
|
-
# A cleaner solution would be to call the original initialize with the already
|
|
36
|
-
# modified block. However, Grape does some odd stuff with the block binding
|
|
37
|
-
# that makes this difficult to reason about.
|
|
38
|
-
if original_block = @block
|
|
39
|
-
@block = lambda do |endpoint_instance|
|
|
40
|
-
ActiveSupport::Notifications.instrument('endpoint_render.grape', endpoint: endpoint_instance) do
|
|
41
|
-
original_block.call(endpoint_instance)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
alias run_without_sk run
|
|
48
|
-
def run(*args)
|
|
49
|
-
ActiveSupport::Notifications.instrument('endpoint_run.grape', endpoint: self) do
|
|
50
|
-
run_without_sk(*args)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
alias run_filters_without_sk run_filters
|
|
55
|
-
def run_filters(filters)
|
|
56
|
-
# Unfortunately, the type isn't provided to the method so we have
|
|
57
|
-
# to try to guess it by looking at the contents. This is only reliable
|
|
58
|
-
# if the filters aren't empty.
|
|
59
|
-
if filters && !filters.empty?
|
|
60
|
-
type = case filters
|
|
61
|
-
when befores then :before
|
|
62
|
-
when before_validations then :before_validation
|
|
63
|
-
when after_validations then :after_validation
|
|
64
|
-
when afters then :after
|
|
65
|
-
else :other
|
|
66
|
-
end
|
|
67
|
-
else
|
|
68
|
-
type = :unknown
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
payload = {
|
|
72
|
-
endpoint: self,
|
|
73
|
-
filters: filters,
|
|
74
|
-
type: type
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
ActiveSupport::Notifications.instrument('endpoint_run_filters.grape', payload) do
|
|
78
|
-
run_filters_without_sk(filters)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
register(:grape, "Grape::Endpoint", "grape/endpoint", Grape::Probe.new)
|
|
87
|
-
end
|
|
88
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
require 'skylight/formatters/http'
|
|
2
|
-
|
|
3
|
-
module Skylight
|
|
4
|
-
module Probes
|
|
5
|
-
module HTTPClient
|
|
6
|
-
class Probe
|
|
7
|
-
DISABLED_KEY = :__skylight_httpclient_disabled
|
|
8
|
-
|
|
9
|
-
def self.disable
|
|
10
|
-
Thread.current[DISABLED_KEY] = true
|
|
11
|
-
yield
|
|
12
|
-
ensure
|
|
13
|
-
Thread.current[DISABLED_KEY] = false
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def self.disabled?
|
|
17
|
-
!!Thread.current[DISABLED_KEY]
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def install
|
|
21
|
-
::HTTPClient.class_eval do
|
|
22
|
-
# HTTPClient has request methods on the class object itself,
|
|
23
|
-
# but the internally instantiate a client and perform the method
|
|
24
|
-
# on that, so this instance method override will cover both
|
|
25
|
-
# `HTTPClient.get(...)` and `HTTPClient.new.get(...)`
|
|
26
|
-
|
|
27
|
-
alias do_request_without_sk do_request
|
|
28
|
-
def do_request(method, uri, query, body, header, &block)
|
|
29
|
-
if Skylight::Probes::HTTPClient::Probe.disabled?
|
|
30
|
-
return do_request_without_sk(method, uri, query, body, header, &block)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
opts = Formatters::HTTP.build_opts(method, uri.scheme, uri.host, uri.port, uri.path, uri.query)
|
|
34
|
-
|
|
35
|
-
Skylight.instrument(opts) do
|
|
36
|
-
do_request_without_sk(method, uri, query, body, header, &block)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end # class Probe
|
|
42
|
-
end # module Probes::HTTPClient
|
|
43
|
-
|
|
44
|
-
register(:httpclient, "HTTPClient", "httpclient", HTTPClient::Probe.new)
|
|
45
|
-
end
|
|
46
|
-
end
|