Class: Skylight::Core::Middleware Private
- Inherits:
-
Object
- Object
- Skylight::Core::Middleware
- Includes:
- Util::Logging
- Defined in:
- lib/skylight/core/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.
Defined Under Namespace
Classes: BodyProxy
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
private
For Util::Logging.
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object private
-
#initialize(app, opts = {}) ⇒ Middleware
constructor
private
A new instance of Middleware.
Methods included from Util::Logging
#config_for_logging, #debug, #error, #fmt, #info, #log, #log_env_prefix, #raise_on_error?, #t, #trace, #trace?, #warn
Constructor Details
#initialize(app, opts = {}) ⇒ Middleware
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.
Returns a new instance of Middleware.
63 64 65 66 |
# File 'lib/skylight/core/middleware.rb', line 63 def initialize(app, opts = {}) @app = app @config = opts[:config] end |
Instance Attribute Details
#config ⇒ Object (readonly)
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.
For Util::Logging
61 62 63 |
# File 'lib/skylight/core/middleware.rb', line 61 def config @config end |
Class Method Details
.with_after_close(resp, &block) ⇒ 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.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/skylight/core/middleware.rb', line 47 def self.with_after_close(resp, &block) # Responses should be arrays but in some situations they aren't # e.g. https://github.com/ruby-grape/grape/issues/1041 # The safest approach seems to be to rely on implicit destructuring # since that is currently what Rack::Lint does. # See also https://github.com/rack/rack/issues/1239 status, headers, body = resp [status, headers, BodyProxy.new(body, &block)] end |
Instance Method Details
#call(env) ⇒ 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.
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 93 94 95 96 97 |
# File 'lib/skylight/core/middleware.rb', line 68 def call(env) set_request_id(env) if instrumentable.tracing? error "Already instrumenting. Make sure the Skylight Rack Middleware hasn't been added more than once." end if env["REQUEST_METHOD"] == "HEAD" t { "middleware skipping HEAD" } @app.call(env) else begin t { "middleware beginning trace" } trace = instrumentable.trace(endpoint_name(env), "app.rack.request", nil, meta: (env)) t { "middleware began trace=#{trace ? trace.uuid : nil}" } resp = @app.call(env) if trace Middleware.with_after_close(resp) { trace.submit } else resp end rescue Exception => e t { "middleware exception: #{e}\n#{e.backtrace.join("\n")}" } trace.submit if trace raise end end end |