Class: Skylight::Core::Probes::Middleware::Probe Private
- Inherits:
-
Object
- Object
- Skylight::Core::Probes::Middleware::Probe
- Defined in:
- lib/skylight/core/probes/middleware.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- DISABLED_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:__skylight_middleware_disabled
Class Method Summary collapse
- .add_instrumentation(middleware, default_name: "Anonymous Middleware", category: "rack.middleware") ⇒ Object private
- .disable! ⇒ Object private
- .disabled? ⇒ Boolean private
- .enable! ⇒ Object private
Instance Method Summary collapse
- #install ⇒ Object private
Class Method Details
.add_instrumentation(middleware, default_name: "Anonymous Middleware", category: "rack.middleware") ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/skylight/core/probes/middleware.rb', line 19 def self.add_instrumentation(middleware, default_name: "Anonymous Middleware", category: "rack.middleware") middleware.instance_eval " alias call_without_sk call\n def call(*args, &block)\n return call_without_sk(*args, &block) if Skylight::Core::Probes::Middleware::Probe.disabled?\n\n traces = Skylight::Core::Fanout.registered.map do |r|\n r.instrumenter ? r.instrumenter.current_trace : nil\n end.compact\n\n return call_without_sk(*args, &block) if traces.empty?\n\n begin\n name = self.class.name || \"\#{default_name}\"\n\n traces.each{|t| t.endpoint = name }\n\n spans = Skylight::Core::Fanout.instrument(title: name, category: \"\#{category}\")\n resp = call_without_sk(*args, &block)\n\n Skylight::Core::Middleware.with_after_close(resp) do\n Skylight::Core::Fanout.done(spans)\n end\n rescue Exception => e\n # FIXME: Log this?\n Skylight::Core::Fanout.done(spans, exception_object: e)\n raise\n end\n end\n RUBY\nend\n", __FILE__, __LINE__ + 1 |
.disable! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
7 8 9 |
# File 'lib/skylight/core/probes/middleware.rb', line 7 def self.disable! @disabled = true end |
.disabled? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 |
# File 'lib/skylight/core/probes/middleware.rb', line 15 def self.disabled? !!@disabled end |
.enable! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
11 12 13 |
# File 'lib/skylight/core/probes/middleware.rb', line 11 def self.enable! @disabled = false end |
Instance Method Details
#install ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/skylight/core/probes/middleware.rb', line 51 def install ::ActionDispatch::MiddlewareStack.class_eval do alias build_without_sk build if ::ActionPack.gem_version >= Gem::Version.new('5.x') # Rails 5 def build(app = Proc.new) Skylight::Core::Probes::Middleware::Probe.add_instrumentation(app, default_name: "Rack App", category: "rack.app") build_without_sk(app) end else # Rails 3 and 4 def build(app, &block) app ||= block raise "MiddlewareStack#build requires an app" unless app Skylight::Core::Probes::Middleware::Probe.add_instrumentation(app, default_name: "Rack App", category: "rack.app") build_without_sk(app) end end end ::ActionDispatch::MiddlewareStack::Middleware.class_eval do alias build_without_sk build def build(*args) sk_instrument_middleware(build_without_sk(*args)) end def sk_instrument_middleware(middleware) return middleware if middleware.is_a?(Skylight::Core::Middleware) # Not sure how this would actually happen return middleware if middleware.respond_to?(:call_without_sk) # On Rails 3, ActionDispatch::Session::CookieStore is frozen, for one return middleware if middleware.frozen? Skylight::Core::Probes::Middleware::Probe.add_instrumentation(middleware) middleware end end end |