Module: Google::Cloud::Debugger

Defined in:
lib/google/cloud/debugger.rb,
lib/google/cloud/debugger/agent.rb,
lib/google/cloud/debugger/rails.rb,
lib/google/cloud/debugger/tracer.rb,
lib/google/cloud/debugger/project.rb,
lib/google/cloud/debugger/service.rb,
lib/google/cloud/debugger/version.rb,
lib/google/cloud/debugger/debuggee.rb,
lib/google/cloud/debugger/breakpoint.rb,
lib/google/cloud/debugger/middleware.rb,
lib/google/cloud/debugger/async_actor.rb,
lib/google/cloud/debugger/credentials.rb,
lib/google/cloud/debugger/transmitter.rb,
lib/google/cloud/debugger/breakpoint_manager.rb,
lib/google/cloud/debugger/breakpoint/variable.rb,
lib/google/cloud/debugger/v2/debugger2_client.rb,
lib/google/cloud/debugger/breakpoint/evaluator.rb,
lib/google/cloud/debugger/v2/controller2_client.rb,
lib/google/cloud/debugger/breakpoint/stack_frame.rb,
lib/google/cloud/debugger/breakpoint/source_location.rb,
lib/google/cloud/debugger/debuggee/app_uniquifier_generator.rb

Overview

Stackdriver Debugger

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

For general information about Stackdriver Debugger, read Stackdriver Debugger Documentation.

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

  • Easy-to-use debugger instrumentation that reports state data, such as value of program variables and the call stack, to Stackdriver Debugger when the code at a breakpoint location is executed in your Ruby application. See the instrumenting your app section for how to debug your application, in both development and production.
  • An idiomatic Ruby API for registerying debuggee application, and querying or manipulating breakpoints in registered Ruby debuggee application. See Debugger API section for an introduction to Stackdriver Debugger API.

Instrumenting Your App

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

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

When this library is configured in your running application, and the source code and breakpoints are setup through the Google Cloud Console, You'll be able to interact with your application in real time through the Stackdriver Debugger UI. This library also integrates with Google App Engine Flexible to make debuggee application configuration more seemless.

Note that when no breakpoints are created, the debugger agent consumes very little resource and has no interference with the running application. Once breakpoints are created and depends on where the breakpoints are located, the debugger agent may add a little latency onto each request. The application performance will be back to normal after all breakpoints are finished being evaluated. Be aware the more breakpoints are created, or the harder to reach the breakpoints, 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 the following line to your config/application.rb file:

require "google/cloud/debugger/rails"

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

# Explicitly enable or disable Stackdriver Debugger Agent
config.google_cloud.use_debugger = true
# Shared Google Cloud Platform project identifier
config.google_cloud.project_id = "gcloud-project"
# Google Cloud Platform project identifier for Stackdriver Debugger only
config.google_cloud.debugger.project_id = "debugger-project"
# Shared Google Cloud authentication json file
config.google_cloud.keyfile = "/path/to/keyfile.json"
# Google Cloud authentication json file for Stackdriver Debugger only
config.google_cloud.debugger.keyfile = "/path/to/debugger/keyfile.json"
# Stackdriver Debugger Agent module name identifier
config.google_cloud.debugger.module_name = "my-ruby-app"
# Stackdriver Debugger Agent module version identifier
config.google_cloud.debugger.module_version = "v1"

See the 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 the following lines to your main application Ruby file:

require "google/cloud/debugger"
use Google::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"
use Google::Cloud::Debugger::Middleware project: "debugger-project-id",
                                        keyfile: "/path/to/keyfile.json",
                                        module_name: "my-ruby-app",
                                        module_version: "v1"

Using instrumentation with other Rack-based frameworks

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

require "google/cloud/debugger"
use Google::Cloud::Debugger::Middleware

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

The Stackdriver diagnostics suite

The debugger library is part of the Stackdriver diagnostics suite, which also includes error reporting, log analysis, and tracing analysis. If you include the stackdriver gem in your Gemfile, this debugger library will be included automatically. In addition, if you include the stackdriver gem in an application 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 Stackdriver Debugger API. This API provides calls to register debuggee application, as well as creating or modifying breakpoints.

For further information on the Debugger API, see Project

Registering debuggee application

require "google/cloud/debugger/v2"

Controller2Client = Google::Cloud::Debugger::V2::Controller2Client
Debuggee = Google::Devtools::Clouddebugger::V2::Debuggee

controller2_client = Controller2Client.new
debuggee = Debuggee.new
response = controller2_client.register_debuggee(debuggee)
debuggee_id = response.debuggee.id

See Stackdriver Debugger Debuggee doc on fields necessary for registerying a debuggee.

Upon successful registration, the response debuggee object will contain a debuggee_id that's later needed to interact with the other Stackdriver Debugger API.

See V2::Controller2Client for details.

List Active Breakpoints

require "google/cloud/debugger/v2"

Controller2Client = Google::Cloud::Debugger::V2::Controller2Client
controller2_client = Controller2Client.new

debuggee_id = ''
response = controller2_client.list_active_breakpoints(debuggee_id)
breakpoints = response.breakpoints

See V2::Controller2Client for details.

Update Active Breakpoint

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

require "google/cloud/debugger/v2"

Breakpoint = Google::Devtools::Clouddebugger::V2::Breakpoint
Controller2Client = Google::Cloud::Debugger::V2::Controller2Client

controller2_client = Controller2Client.new
debuggee_id = ''
breakpoint = Breakpoint.new
response =
  controller2_client.update_active_breakpoint(debuggee_id, breakpoint)

See Stackdriver Debugger Breakpoint doc for all available fields for breakpoint.

See V2::Controller2Client for details.

Set Breakpoint

require "google/cloud/debugger/v2"

Breakpoint = Google::Devtools::Clouddebugger::V2::Breakpoint
Debugger2Client = Google::Cloud::Debugger::V2::Debugger2Client

debugger2_client = Debugger2Client.new
debuggee_id = ''
breakpoint = Breakpoint.new
client_version = ''
response = debugger2_client.set_breakpoint(
             debuggee_id, breakpoint, client_version)

See Stackdriver Debugger Breakpoint doc for fields needed to specify breakpoint location.

See V2::Debugger2Client for details.

Get Breakpoint

require "google/cloud/debugger/v2"

Debugger2Client = Google::Cloud::Debugger::V2::Debugger2Client

debugger2_client = Debugger2Client.new
debuggee_id = ''
breakpoint_id = ''
client_version = ''
response = debugger2_client.get_breakpoint(
             debuggee_id, breakpoint_id, client_version)

See V2::Debugger2Client for details.

Delete Breakpoint

require "google/cloud/debugger/v2"

Debugger2Client = Google::Cloud::Debugger::V2::Debugger2Client

debugger2_client = Debugger2Client.new
debuggee_id = ''
breakpoint_id = ''
client_version = ''
debugger2_client.delete_breakpoint(
  debuggee_id, breakpoint_id, client_version)

See V2::Debugger2Client for details.

List Breakpoints

require "google/cloud/debugger/v2"

Debugger2Client = Google::Cloud::Debugger::V2::Debugger2Client

Debugger2Client = Google::Cloud::Debugger::V2::Debugger2Client

debugger2_client = Debugger2Client.new
debuggee_id = ''
client_version = ''
response = debugger2_client.list_breakpoints(debuggee_id, client_version)

See V2::Debugger2Client for details.

List Debuggees

require "google/cloud/debugger/v2"

Debugger2Client = Google::Cloud::Debugger::V2::Debugger2Client

debugger2_client = Debugger2Client.new
project = ''
client_version = ''
response = debugger2_client.list_debuggees(project, client_version)

See V2::Debugger2Client for details.

Defined Under Namespace

Modules: V2 Classes: Agent, Breakpoint, BreakpointManager, Debuggee, Middleware, Project, Railtie, Tracer, Transmitter

Constant Summary collapse

VERSION =
"0.25.0"

Class Method Summary collapse

Class Method Details

.configure {|Google::Cloud.configure[:debugger]| ... } ⇒ Stackdriver::Core::Configuration

Configure the Stackdriver Debugger agent.

See the Configuration Guide for full configuration parameters.

Yields:

Returns:

  • (Stackdriver::Core::Configuration)

    The configuration object the Google::Cloud::ErrorReporting module uses.



400
401
402
403
404
# File 'lib/google/cloud/debugger.rb', line 400

def self.configure
  yield Google::Cloud.configure[:debugger] if block_given?

  Google::Cloud.configure[:debugger]
end

.new(project: nil, keyfile: nil, module_name: nil, module_version: nil, scope: nil, timeout: nil, client_config: nil) ⇒ Google::Cloud::Debugger::Project

Creates a new debugger object for instrumenting Stackdriver Debugger for an application. Each call creates a new debugger agent with independent connection service.

For more information on connecting to Google Cloud see the Authentication Guide.

Examples:

require "google/cloud/debugger"

debugger = Google::Cloud::Debugger.new
debugger.start

Parameters:

  • project (String)

    Project identifier for the Stackdriver Debugger service.

  • keyfile (String, Hash)

    Keyfile downloaded from Google Cloud: either the JSON data or the path to a readable file.

  • module_name (String)

    Name for the debuggee application. Optional.

  • module_version (String)

    Version identifier for the debuggee application. Optional.

  • scope (String, Array<String>)

    The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs. The default scope is https://www.googleapis.com/auth/cloud-platform

  • timeout (Integer)

    Default timeout to use in requests. Optional.

Returns:



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
# File 'lib/google/cloud/debugger.rb', line 364

def self.new project: nil, keyfile: nil, module_name: nil,
             module_version: nil, scope: nil, timeout: nil,
             client_config: nil
  project ||= Debugger::Project.default_project
  project = project.to_s # Always cast to a string
  module_name ||= Debugger::Project.default_module_name
  module_name = module_name.to_s
  module_version ||= Debugger::Project.default_module_version
  module_version = module_version.to_s

  fail ArgumentError, "project is missing" if project.empty?
  fail ArgumentError, "module_name is missing" if module_name.empty?
  fail ArgumentError, "module_version is missing" if module_version.nil?

  credentials = Credentials.credentials_with_scope keyfile, scope

  Google::Cloud::Debugger::Project.new(
    Google::Cloud::Debugger::Service.new(
      project, credentials, timeout: timeout,
                            client_config: client_config),
    module_name: module_name,
    module_version: module_version
  )
end