Reference documentation and code samples for the google-cloud-debugger class Google::Cloud::Debugger::Middleware.
Rack Middleware implementation that supports Stackdriver Debugger Agent in Rack-based Ruby frameworks. It instantiates a new debugger agent if one isn't given already. It helps optimize Debugger Agent Tracer performance by suspending and resuming the tracer between each request.
To use this middleware, simply install it in your Rack configuration. The middleware will take care of registering itself with the Stackdriver Debugger and activating the debugger agent. The location of the middleware in the middleware stack matters: breakpoints will be detected in middleware appearing after but not before this middleware.
For best results, you should also call Middleware.start_agents during application initialization. See its documentation for details.
Inherits
- Object
Methods
.start_agents
def self.start_agents()
This should be called once the application determines that it is safe to start background threads and open gRPC connections. It informs the middleware system that it can start debugger agents.
Generally, this matters if the application forks worker processes;
this method should be called only after workers are forked, since
threads and network connections interact badly with fork. For
example, when running Puma in
clustered mode, this
method should be called in an on_worker_boot
block.
If the application does no forking, this method can be called any time early in the application initialization process.
If Middleware.start_agents is never called, the debugger agent will be started when the first request is received. This should be safe, but it will probably mean breakpoints will not be recognized during that first request. For best results, an application should call this method at the appropriate time.
#call
def call(env) -> Rack::Response
Rack middleware entry point. In most Rack based frameworks, a request is served by one thread. It enables/resume the debugger breakpoints tracing and stops/pauses the tracing afterwards to help improve debugger performance.
- env (Hash) — Rack environment hash
- (Rack::Response) — The response from downstream Rack app
#initialize
def initialize(app, debugger: nil, **kwargs) -> Google::Cloud::Debugger::Middleware
Create a new Debugger Middleware.
- app (Rack Application) — Rack application
- debugger (Google::Cloud::Debugger::Project) (defaults to: nil) — A debugger to be used by this middleware. If not given, will construct a new one using the other parameters.
- kwargs (Hash) — Hash of configuration settings. Used for backward API compatibility. See the Configuration Guide for the prefered way to set configuration parameters.
- (Google::Cloud::Debugger::Middleware) — A new Google::Cloud::Debugger::Middleware instance