Setting Up Stackdriver Debugger for Ruby

App Engine Flexible

  1. Add the Stackdriver gem to your Gemfile:

    gem "stackdriver"
    
  2. Enable the agent.

Rails

Bundler automatically loads the library into your app when it starts. No configuration is required.

Rack

Use the Rack Middleware provided by the library:

require "google/cloud/debugger"

use Google::Cloud::Debugger::Middleware

Other

For pure Ruby apps, start the agent explicitly at the entry point:

require "google/cloud/debugger"

Google::Cloud::Debugger.new.start

The debugger is now ready for use with your app.

Kubernetes Engine

  1. Make sure your cluster is created with one of the following access scopes:

    • https://www.googleapis.com/auth/cloud-platform
    • https://www.googleapis.com/auth/cloud_debugger

    Example:

    gcloud container clusters create EXAMPLE-CLUSTER-NAME \
        --scopes https://www.googleapis.com/auth/cloud-platform
    
  2. Follow the instructions for Compute Engine.

Compute Engine

  1. Make sure your Compute Engine instances are created with the access scope option Allow full access to all Cloud APIs, or have one of the following access scopes:

    • https://www.googleapis.com/auth/cloud-platform
    • https://www.googleapis.com/auth/cloud_debugger
  2. Add the Stackdriver gem to your Gemfile:

    gem "stackdriver"
    
  3. Use Bundler to install the gem:

    bundle install
    
  4. Enable the agent.

Rails

Bundler automatically loads the library into your app when it starts.

You can optionally provide a service and version through the Ruby on Rails configuration inteface:

# Add this to config/environments/*.rb
Rails.application.configure do |config|
  config.google_cloud.debugger.service_name = "SERVICE-NAME"
  config.google_cloud.debugger.service_version = "SERVICE-VERSION"
end

Where:

  • SERVICE-NAME is a name for your app, such as MyApp, Backend, or Frontend.
  • SERVICE-VERSION is a version, such as v1.0, build_147, or v20170714.

We recommend setting these from environment variables so you do not need to change the source code with each deployment.

Rack

Use the Rack Middleware provided by the library:

require "google/cloud/debugger"

Google::Cloud::Debugger.configure do |config|
  config.service_name = "SERVICE-NAME"
  config.service_version = "SERVICE-VERSION"
end

use Google::Cloud::Debugger::Middleware

Where:

  • SERVICE-NAME is a name for your app, such as MyApp, Backend, or Frontend.
  • SERVICE-VERSION is a version, such as v1.0, build_147, or v20170714.

We recommend setting these from environment variables so you do not need to change the source code with each deployment.

Other

For pure Ruby apps, start the agent explicitly at the entry point:

require "google/cloud/debugger"

Google::Cloud::Debugger.new(service_name: "SERVICE-NAME",
                            service_version: "SERVICE-VERSION").start

Where:

  • SERVICE-NAME is a name for your app, such as MyApp, Backend, or Frontend.
  • SERVICE-VERSION is a version, such as v1.0, build_147, or v20170714.

We recommend setting these from environment variables so you do not need to change the source code with each deployment.

The debugger is now ready for use with your app.

Local and Elsewhere

  1. Add the Stackdriver gem to your Gemfile.

    gem "stackdriver"
    
  2. Use Bundler to install the gem:

    bundle install
    
  3. Download service account credentials.

    To use the Ruby debugger agent on machines not hosted by Google Cloud Platform, the agent must use a GCP service account credentials to authenticate with the Stackdriver Debugger Service.

    Use the GCP Console Service Accounts page to create a credentials file for an existing or new service account. The service account must have at least the Cloud Debugger Agent role.

  4. Configure and enable the agent with the downloaded credentials.

Rails

Provide the parameters through the Ruby on Rails configuration interface:

# Add this to config/environments/*.rb
Rails.application.configure do |config|
  config.google_cloud.project_id = "YOUR-PROJECT-ID"
  config.google_cloud.keyfile    = "/path/to/service-account.json"
  config.google_cloud.debugger.service_name = "SERVICE-NAME"
  config.google_cloud.debugger.service_version = "SERVICE-VERSION"
end

Where:

  • SERVICE-NAME is a name for your app, such as MyApp, Backend, or Frontend.
  • SERVICE-VERSION is a version, such as v1.0, build_147, or v20170714.

We recommend setting these from environment variables so you do not need to change the source code with each deployment.

Rack

Use the Rack Middleware provided by the library:

require "stackdriver"
require "google/cloud/debugger"

Google::Cloud.configure do |config|
  config.project_id = "YOUR-PROJECT-ID"
  config.keyfile    = "/path/to/service-account.json"
  config.service_name = "SERVICE-NAME"
  config.service_version = "SERVICE-VERSION"
end

use Google::Cloud::Debugger::Middleware

Where:

  • SERVICE-NAME is a name for your app, such as MyApp, Backend, or Frontend.
  • SERVICE-VERSION is a version, such as v1.0, build_147, or v20170714.

We recommend setting these from environment variables so you do not need to change the source code with each deployment.

Other

For pure Ruby apps, start the agent explicitly at the entry point:

require "google/cloud/debugger"

Google::Cloud::Debugger.new(project: "YOUR-PROJECT-ID",
                            keyfile: "/path/to/service-account.json",
                            service_name: "SERVICE-NAME",
                            service_version: "SERVICE-VERSION").start

Where:

  • SERVICE-NAME is a name for your app, such as MyApp, Backend, or Frontend.
  • SERVICE-VERSION is a version, such as v1.0, build_147, or v20170714.

We recommend setting these from environment variables so you do not need to change the source code with each deployment.

The debugger is now ready for use with your app.

The Debug page in the GCP Console can display local source files, without upload, for local development. See Selecting Source Code Manually.

Send feedback about...

Stackdriver Debugger Documentation