Stackdriver Debugger

Stackdriver Debugger is a feature of the Google Cloud Platform that lets youinspect the state of an application at any code location without using loggingstatements and without stopping or slowing down your applications. Your usersare not impacted during debugging. Using the production debugger you can capturethe local variables and call stack and link it back to a specific line locationin your source code. You can use this to analyze the production state of yourapplication and understand the behavior of your code in production.

For general information about Stackdriver Debugger, readStackdriver DebuggerDocumentation.

The Stackdriver Debugger Ruby library,google-cloud-debugger, provides:

  • Easy-to-use debugger instrumentation that reports state data, such as value ofprogram variables and the call stack, to Stackdriver Debugger when the code ata breakpoint location is executed in your Ruby application. See theinstrumenting your app section for how to debugyour application, in both development and production.
  • An idiomatic Ruby API for registerying debuggee application, and querying ormanipulating breakpoints in registered Ruby debuggee application. SeeDebugger API section for an introduction toStackdriver Debugger API.

Instrumenting Your App

This instrumentation library provides the following features to help you debugyour applications in production:

  • Automatic application registration. It facilitates multiple running instancesof same version of application when hosted in production.
  • A background debugger agent that runs side-by-side with your application thatautomatically collects state data when code is executed at breakpointlocations.
  • A Rack middleware and Railtie that automatically manages the debugger agentfor Ruby on Rails and other Rack-based Ruby applications.

When this library is configured in your running application, and the source codeand breakpoints are setup through the Google Cloud Console, You'll be able tointeract with yourapplication in real time through theStackdriver DebuggerUI.This library also integrates with Google App Engine Flexible to make debuggeeapplication configuration more seemless.

Note that when no breakpoints are created, the debugger agent consumes verylittle resource and has no interference with the running application. Oncebreakpoints are created and depends on where the breakpoints are located, thedebugger agent may add a little latency onto each request. The applicationperformance will be back to normal after all breakpoints are finished beingevaluated. Be aware the more breakpoints are created, or the harder to reach thebreakpoints, the more resource the debugger agent would need to consume.

Using instrumentation with Ruby on Rails

To install application instrumentation in your Ruby on Rails app, add this gem,google-cloud-debugger, to your Gemfile and update your bundle. Then add thefollowing line to yourconfig/application.rb file:

require"google/cloud/debugger/rails"

This will load a Railtie that automatically integrates with the Rails frameworkby injecting a Rack middleware. The Railtie also takes in the following Railsconfiguration as parameter of the debugger agent initialization:

# Explicitly enable or disable Stackdriver Debugger Agentconfig.google_cloud.use_debugger=true# Shared Google Cloud Platform project identifierconfig.google_cloud.project_id="gcloud-project"# Google Cloud Platform project identifier for Stackdriver Debugger onlyconfig.google_cloud.debugger.project_id="debugger-project"# Shared Google Cloud authentication json fileconfig.google_cloud.keyfile="/path/to/keyfile.json"# Google Cloud authentication json file for Stackdriver Debugger onlyconfig.google_cloud.debugger.keyfile="/path/to/debugger/keyfile.json"# Stackdriver Debugger Agent service name identifierconfig.google_cloud.debugger.service_name="my-ruby-app"# Stackdriver Debugger Agent service version identifierconfig.google_cloud.debugger.service_version="v1"

See theGoogle::Cloud::Debugger::Railtie class for more information.

Using instrumentation with Sinatra

To install application instrumentation in your Sinatra app, add this gem,google-cloud-debugger, to your Gemfile and update your bundle. Then add thefollowing lines to your main application Ruby file:

require"google/cloud/debugger"useGoogle::Cloud::Debugger::Middleware

This will install the debugger middleware in your application.

Configuration parameters may also be passed in as arguments to Middleware.

require"google/cloud/debugger"useGoogle::Cloud::Debugger::Middlewareproject:"debugger-project-id",keyfile:"/path/to/keyfile.json",service_name:"my-ruby-app",service_version:"v1"

Using instrumentation with other Rack-based frameworks

To install application instrumentation in an app using another Rack-based webframework, add this gem,google-cloud-debugger, to your Gemfile and updateyour bundle. Then add install the debugger middleware in your middleware stack.In most cases, this means adding these lines to yourconfig.ru Rackconfiguration file:

require"google/cloud/debugger"useGoogle::Cloud::Debugger::Middleware

Some web frameworks have an alternate mechanism for modifying the middlewarestack. Consult your web framework's documentation for more information.

The Stackdriver diagnostics suite

The debugger library is part of the Stackdriver diagnostics suite, which alsoincludes error reporting, log analysis, and tracing analysis. If you include thestackdriver gem in your Gemfile, this debugger library will be includedautomatically. In addition, if you include thestackdriver gem in anapplication using Ruby On Rails, the Railties will be installed automatically.See the documentation for the "stackdriver" gem for more details.

Stackdriver Debugger API

This library also includes an easy to use Ruby client for the StackdriverDebugger API. This API provides calls to register debuggee application, as wellas creating or modifying breakpoints.

For further information on the Debugger API, seeGoogle::Cloud::Debugger::Project

Registering debuggee application

require"google/cloud/debugger/v2"controller_client=Google::Cloud::Debugger::V2::Controller::Client.newdebuggee=Google::Cloud::Debugger::V2::Debuggee.newresponse=controller_client.register_debuggeedebuggee:debuggeedebuggee_id=response.debuggee.id

SeeStackdriver Debugger Debuggeedocon fields necessary for registerying a debuggee.

Upon successful registration, the response debuggee object will contain adebuggee_id that's later needed to interact with the other Stackdriver DebuggerAPI.

List Active Breakpoints

require"google/cloud/debugger/v2"controller_client=Google::Cloud::Debugger::V2::Controller::Client.newdebuggee_id=''response=controller_client.list_active_breakpointsdebuggee_id:debuggee_idbreakpoints=response.breakpoints

Update Active Breakpoint

Users can send custom snapshots for active breakpoints using this API.

require"google/cloud/debugger/v2"controller_client=Google::Cloud::Debugger::V2::Controller::Client.newdebuggee_id=''breakpoint=Google::Cloud::Debugger::V2::Breakpoint.newresponse=controller_client.update_active_breakpoint(debuggee_id:debuggee_id,breakpoint:breakpoint)

SeeStackdriver Debugger Breakpointdocfor all available fields for breakpoint.

Set Breakpoint

require"google/cloud/debugger/v2"debugger_client=Google::Cloud::Debugger::V2::Debugger::Client.newdebuggee_id=''breakpoint=Google::Cloud::Debugger::V2::Breakpoint.newclient_version=''response=debugger_client.set_breakpoint(debuggee_id:debuggee_id,breakpoint:breakpoint,client_version:client_version)

SeeStackdriver Debugger Breakpointdocfor fields needed to specify breakpoint location.

Get Breakpoint

require"google/cloud/debugger/v2"debugger_client=Google::Cloud::Debugger::V2::Debugger::Client.newdebuggee_id=''breakpoint_id=''client_version=''response=debugger_client.get_breakpoint(debuggee_id:debuggee_id,breakpoint_id:breakpoint_id,client_version:client_version)

Delete Breakpoint

require"google/cloud/debugger/v2"debugger_client=Google::Cloud::Debugger::V2::Debugger::Client.newdebuggee_id=''breakpoint_id=''client_version=''debugger_client.delete_breakpoint(debuggee_id:debuggee_id,breakpoint_id:breakpoint_id,client_version:client_version)

List Breakpoints

require"google/cloud/debugger/v2"debugger_client=Google::Cloud::Debugger::V2::Debugger::Client.newdebuggee_id=''client_version=''response=debugger_client.list_breakpoints(debuggee_id:debuggee_id,client_version:client_version)

List Debuggees

require"google/cloud/debugger/v2"debugger_client=Google::Cloud::Debugger::V2::Debugger::Client.newproject=''client_version=''response=debugger_client.list_debuggees(project:project,client_version:client_version)

Additional information

Stackdriver Debugger can be configured to use gRPC's logging. To learn more, seetheLogging guide.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.