google-cloud-debugger - Class Google::Cloud::Debugger::Middleware (v0.42.2)
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
defself.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
defcall(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.
Parameter
env (Hash) — Rack environment hash
Returns
(Rack::Response) — The response from downstream Rack app
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# google-cloud-debugger - Class Google::Cloud::Debugger::Middleware (v0.42.2)\n\nReference documentation and code samples for the google-cloud-debugger class Google::Cloud::Debugger::Middleware.\n\nRack Middleware implementation that supports Stackdriver Debugger Agent\nin Rack-based Ruby frameworks. It instantiates a new debugger agent if\none isn't given already. It helps optimize Debugger Agent Tracer\nperformance by suspending and resuming the tracer between each request.\n\n\nTo use this middleware, simply install it in your Rack configuration.\nThe middleware will take care of registering itself with the\nStackdriver Debugger and activating the debugger agent. The location\nof the middleware in the middleware stack matters: breakpoints will be\ndetected in middleware appearing after but not before this middleware.\n\n\u003cbr /\u003e\n\nFor best results, you should also call [Middleware.start_agents](/ruby/docs/reference/google-cloud-debugger/latest/Google-Cloud-Debugger-Middleware#Google__Cloud__Debugger__Middleware_start_agents_class_ \"Google::Cloud::Debugger::Middleware.start_agents (method)\")\nduring application initialization. See its documentation for details. \n\nInherits\n--------\n\n- Object\n\nMethods\n-------\n\n### .start_agents\n\n def self.start_agents()\n\nThis should be called once the application determines that it is safe\nto start background threads and open gRPC connections. It informs\nthe middleware system that it can start debugger agents.\n\n\nGenerally, this matters if the application forks worker processes;\nthis method should be called only after workers are forked, since\nthreads and network connections interact badly with fork. For\nexample, when running Puma in\n[clustered mode](https://github.com/puma/puma#clustered-mode), this\nmethod should be called in an `on_worker_boot` block.\n\nIf the application does no forking, this method can be called any\ntime early in the application initialization process.\n\n\u003cbr /\u003e\n\nIf [Middleware.start_agents](/ruby/docs/reference/google-cloud-debugger/latest/Google-Cloud-Debugger-Middleware#Google__Cloud__Debugger__Middleware_start_agents_class_ \"Google::Cloud::Debugger::Middleware.start_agents (method)\") is never called, the debugger agent will\nbe started when the first request is received. This should be safe,\nbut it will probably mean breakpoints will not be recognized during\nthat first request. For best results, an application should call this\nmethod at the appropriate time.\n\n### #call\n\n def call(env) -\u003e Rack::Response\n\nRack middleware entry point. In most Rack based frameworks, a request\nis served by one thread. It enables/resume the debugger breakpoints\ntracing and stops/pauses the tracing afterwards to help improve\ndebugger performance. \n**Parameter**\n\n- **env** (Hash) --- Rack environment hash \n**Returns**\n\n- (Rack::Response) --- The response from downstream Rack app\n\n### #initialize\n\n def initialize(app, debugger: nil, **kwargs) -\u003e Google::Cloud::Debugger::Middleware\n\nCreate a new Debugger Middleware. \n**Parameters**\n\n- **app** (Rack Application) --- Rack application\n- **debugger** ([Google::Cloud::Debugger::Project](./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.\n- **kwargs** (Hash) --- Hash of configuration settings. Used for backward API compatibility. See the [Configuration\nGuide](https://googleapis.dev/ruby/stackdriver/latest/file.INSTRUMENTATION_CONFIGURATION.html) for the prefered way to set configuration parameters. \n**Returns**\n\n- ([Google::Cloud::Debugger::Middleware](./Google-Cloud-Debugger-Middleware)) --- A new Google::Cloud::Debugger::Middleware instance"]]