Setting Up Stackdriver Debugger for Ruby

This page describes how to configure your environment and your Ruby application to use Stackdriver Debugger. For some environments, you must explicitly specify the access scope to let the Stackdriver Debugger agent send data. We recommend setting the broadest possible access scope and then using Cloud Identity and Access Management to restrict access. In keeping with this best practice, set the access scope to be all Cloud APIs with the option cloud-platform.

App Engine flexible environment

  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.

Google Kubernetes Engine

  1. Create your cluster, with one of the following access scopes:
    • https://www.googleapis.com/auth/cloud-platform
    • https://www.googleapis.com/auth/cloud_debugger

    To create a cluster using gcloud, do the following:

    1. (Optional) Update gcloud to the latest version:
      gcloud components update
    2. Set your default project ID:
      gcloud config set project [PROJECT_ID]
    3. If you're working with zonal clusters, set your default compute zone:
      gcloud config set compute/zone [COMPUTE_ZONE]
    4. If you're working with regional clusters, set your default compute region:
      gcloud config set compute/region [COMPUTE_REGION]
    5. Issue the create command:
      gcloud container clusters create example-cluster-name --scopes https://www.googleapis.com/auth/cloud-platform

    For more detailed information on creating a cluster, see Creating a cluster.

  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 interface:

# 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.

Debugger is enabled by default when Rails is running in production mode. To enable Debugger in development mode, add the following:

# Add this to config/environments/development.rb
Rails.application.configure do |config|
  config.google_cloud.use_debugger = true
end

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 Stackdriver Debugger agent for Ruby 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 Stackdriver 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.

Debugger is enabled by default when Rails is running in production mode. To enable Debugger in development mode, add the following:

# Add this to config/environments/development.rb
Rails.application.configure do |config|
  config.google_cloud.use_debugger = true
end

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.

Was this page helpful? Let us know how we did:

Send feedback about...

Stackdriver Debugger Documentation