Stackdriver instrumentation libraries are fully integrated with Rails
configuration interface. You can provide all the configuration parameters in
your config/environments/*.rb files:
Rails.application.configuredo|config|# Shared project_id and keyfileconfig.google_cloud.project_id="my-project"config.google_cloud.keyfile="/path/to/key.json"# Library specific configurationsconfig.google_cloud.error_reporting.project_id="error-reporting-project"config.google_cloud.logging.log_name="my-app-logname"config.google_cloud.trace.capture_stack=trueend
Other Rack-based applications can also configure all the Stackdriver
instrumentation libraries through a similar configuration interface in Ruby:
Google::Cloud.configuredo|config|# Shared project_id and keyfileconfig.project_id="my-project"config.keyfile="/path/to/key.json"# Library specific configurationsconfig.error_reporting.project_id="error-reporting-project"config.logging.log_name="my-app-log"config.trace.capture_stack=trueend
Individual libraries can be configured separately:
# Error Reporting specific configurationsGoogle::Cloud::ErrorReporting.configuredo|config|config.project_id="error-reporting-project"config.service_name="my-service"end# Logging specific configurationsGoogle::Cloud::Logging.configuredo|config|config.project_id="error-reporting-project"config.log_name="my-app-log"config.labels={"my-static-label"=>"static-label-value","my-dynamic-label"=>->(rack_env){rack_env["HTTP_X_MY_HEADER"]}}end# Trace specific configurationsGoogle::Cloud::Trace.configuredo|config|config.project_id="error-reporting-project"config.capture_stack=trueend
Configuration Options
Shared
project_id: [String] Shared Google Cloud Platform Project identifier. Self discovered on GCP.
credentials: [String] Path to shared service account JSON keyfile. Self discovered on GCP.
use_logging: [Boolean] Explicitly enable or disable Logging middleware. Default: Rails.env.production?
use_trace: [Boolean] Explicitly enable or disable Trace features. Default: Rails.env.production?
Error Reporting
error_reporting.project_id: [String] Google Cloud Platform Project identifier just for Error Reporting. Self discovered on GCP.
error_reporting.credentials: [String] Path to service account JSON keyfile. Self discovered on GCP.
error_reporting.service_name: [String] Identifier to running service. Self discovered on GCP. Default: "ruby"
error_reporting.service_version: [String] Version identifier to running service. Self discovered on GCP.
error_reporting.ignore_classes: [Array] An Array of Exception classes to ignore. Default: []
Logging
logging.project_id: [String] Google Cloud Platform Project identifier just for Logging. Self discovered on GCP.
logging.credentials: [String] Path to service account JSON keyfile. Self discovered on GCP.
logging.log_name: [String] Name of the application log file. Default: "ruby_app_log"
logging.log_name_map: [Hash] Map specific request routes to other log. Default: { "/_ah/health" => "ruby_health_check_log" }
logging.monitored_resource.type: [String] Resource type name. See full list. Self discovered on GCP.
logging.monitored_resource.labels: [Hash] Resource labels. See full list. Self discovered on GCP.
logging.labels: [Hash] User defined labels. A Hash of label names to string label values or callables/Proc which are functions of the Rack environment.
Trace
trace.project_id: [String] Google Cloud Platform Project identifier just for Trace. Self discovered on GCP.
trace.credentials: [String] Path to service account JSON keyfile. Self discovered on GCP.
trace.capture_stack: [Boolean] Whether to capture stack traces for each span. Default: false
trace.sampler: [Proc] A sampler Proc makes the decision whether to record a trace for each request. Default: Google::Cloud::Trace::TimeSampler
trace.span_id_generator: [Proc] A generator Proc that generates the name String for new TraceRecord. Default: random numbers
trace.notifications: [Array] An array of ActiveSupport notification types to include in traces. Rails-only option. Default: Google::Cloud::Trace::Railtie::DEFAULT_NOTIFICATIONS
trace.max_data_length: [Integer] The maximum length of span properties recorded with ActiveSupport notification events. Rails-only option. Default: Google::Cloud::Trace::Notifications::DEFAULT_MAX_DATA_LENGTH
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [0.23.0 (latest)](/ruby/docs/reference/stackdriver/latest/INSTRUMENTATION-CONFIGURATION)\n- [0.22.0](/ruby/docs/reference/stackdriver/0.22.0/INSTRUMENTATION-CONFIGURATION) \n\nStackdriver Instrumentation Configuration\n=========================================\n\nStackdriver instrumentation libraries are fully integrated with Rails\nconfiguration interface. You can provide all the configuration parameters in\nyour `config/environments/*.rb` files: \n\n```ruby\nRails.application.configure do |config|\n # Shared project_id and keyfile\n config.google_cloud.project_id = \"my-project\"\n config.google_cloud.keyfile = \"/path/to/key.json\"\n\n # Library specific configurations\n config.google_cloud.error_reporting.project_id = \"error-reporting-project\"\n config.google_cloud.logging.log_name = \"my-app-logname\"\n config.google_cloud.trace.capture_stack = true\nend\n```\n\nOther Rack-based applications can also configure all the Stackdriver\ninstrumentation libraries through a similar configuration interface in Ruby: \n\n```ruby\nGoogle::Cloud.configure do |config|\n # Shared project_id and keyfile\n config.project_id = \"my-project\"\n config.keyfile = \"/path/to/key.json\"\n\n # Library specific configurations\n config.error_reporting.project_id = \"error-reporting-project\"\n config.logging.log_name = \"my-app-log\"\n config.trace.capture_stack = true\nend\n```\n\nIndividual libraries can be configured separately: \n\n```ruby\n# Error Reporting specific configurations\nGoogle::Cloud::ErrorReporting.configure do |config|\n config.project_id = \"error-reporting-project\"\n config.service_name = \"my-service\"\nend\n\n# Logging specific configurations\nGoogle::Cloud::Logging.configure do |config|\n config.project_id = \"error-reporting-project\"\n config.log_name = \"my-app-log\"\n config.labels = {\n \"my-static-label\" =\u003e \"static-label-value\",\n \"my-dynamic-label\" =\u003e -\u003e(rack_env) { rack_env[\"HTTP_X_MY_HEADER\"] }\n }\nend\n\n# Trace specific configurations\nGoogle::Cloud::Trace.configure do |config|\n config.project_id = \"error-reporting-project\"\n config.capture_stack = true\nend\n```\n\nConfiguration Options\n---------------------\n\n#### Shared\n\n- `project_id`: \\[`String`\\] Shared Google Cloud Platform Project identifier. Self discovered on GCP.\n- `credentials`: \\[`String`\\] Path to shared service account JSON keyfile. Self discovered on GCP.\n- `use_error_reporting`: \\[`Boolean`\\] Explicitly enable or disable Error Reporting features. Default: `Rails.env.production?`\n- `use_logging`: \\[`Boolean`\\] Explicitly enable or disable Logging middleware. Default: `Rails.env.production?`\n- `use_trace`: \\[`Boolean`\\] Explicitly enable or disable Trace features. Default: `Rails.env.production?`\n\n#### Error Reporting\n\n- `error_reporting.project_id`: \\[`String`\\] Google Cloud Platform Project identifier just for Error Reporting. Self discovered on GCP.\n- `error_reporting.credentials`: \\[`String`\\] Path to service account JSON keyfile. Self discovered on GCP.\n- `error_reporting.service_name`: \\[`String`\\] Identifier to running service. Self discovered on GCP. Default: `\"ruby\"`\n- `error_reporting.service_version`: \\[`String`\\] Version identifier to running service. Self discovered on GCP.\n- `error_reporting.ignore_classes`: \\[`Array`\\] An Array of Exception classes to ignore. Default: `[]`\n\n#### Logging\n\n- `logging.project_id`: \\[`String`\\] Google Cloud Platform Project identifier just for Logging. Self discovered on GCP.\n- `logging.credentials`: \\[`String`\\] Path to service account JSON keyfile. Self discovered on GCP.\n- `logging.log_name`: \\[`String`\\] Name of the application log file. Default: `\"ruby_app_log\"`\n- `logging.log_name_map`: \\[`Hash`\\] Map specific request routes to other log. Default: `{ \"/_ah/health\" =\u003e \"ruby_health_check_log\" }`\n- `logging.monitored_resource.type`: \\[`String`\\] Resource type name. See [full list](https://cloud.google.com/logging/docs/api/v2/resource-list). Self discovered on GCP.\n- `logging.monitored_resource.labels`: \\[`Hash`\\] Resource labels. See [full list](https://cloud.google.com/logging/docs/api/v2/resource-list). Self discovered on GCP.\n- `logging.labels`: \\[`Hash`\\] User defined labels. A `Hash` of label names to string label values or callables/`Proc` which are functions of the Rack environment.\n\n#### Trace\n\n- `trace.project_id`: \\[`String`\\] Google Cloud Platform Project identifier just for Trace. Self discovered on GCP.\n- `trace.credentials`: \\[`String`\\] Path to service account JSON keyfile. Self discovered on GCP.\n- `trace.capture_stack`: \\[`Boolean`\\] Whether to capture stack traces for each span. Default: `false`\n- `trace.sampler`: \\[`Proc`\\] A sampler Proc makes the decision whether to record a trace for each request. Default: `Google::Cloud::Trace::TimeSampler`\n- `trace.span_id_generator`: \\[`Proc`\\] A generator Proc that generates the name String for new TraceRecord. Default: `random numbers`\n- `trace.notifications`: \\[`Array`\\] An array of ActiveSupport notification types to include in traces. Rails-only option. Default: `Google::Cloud::Trace::Railtie::DEFAULT_NOTIFICATIONS`\n- `trace.max_data_length`: \\[`Integer`\\] The maximum length of span properties recorded with ActiveSupport notification events. Rails-only option. Default: `Google::Cloud::Trace::Notifications::DEFAULT_MAX_DATA_LENGTH`"]]