Reference documentation and code samples for the Cloud Trace API class Google::Cloud::Trace::Railtie.
Rails integration for Stackdriver Trace
This Railtie is a drop-in Stackdriver Trace instrumentation plugin
for Ruby on Rails applications. If present, it automatically
instruments your Rails app to record performance traces and cause them
to appear on your Stackdriver console.
Installation
To install this plugin, the gem google-cloud-trace must be in your
Gemfile. You also must add the following line to your application.rb
file:
ruby
require "google/cloud/trace/rails"
If you include the stackdriver gem in your Gemfile, the above is done
for you automatically, and you do not need to edit your
application.rb.
To add a custom measurement to a request trace, use the classes
provided in this library. Below is an example to get you started.
ruby
class MyController < ApplicationController
def index
Google::Cloud::Trace.in_span "Sleeping on the job!" do
sleep rand
end
render plain: "Hello World!"
end
end
Inherits
Rails::Railtie
Constants
DEFAULT_NOTIFICATIONS
value: [
"sql.active_record",
"render_template.action_view",
"send_file.action_controller",
"send_data.action_controller",
"deliver.action_mailer"
].freeze The default list of ActiveSupport notification types to include in
traces.
[[["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-09-04 UTC."],[],[],null,["# Cloud Trace API - Class Google::Cloud::Trace::Railtie (v0.45.0)\n\nVersion latestkeyboard_arrow_down\n\n- [0.45.0 (latest)](/ruby/docs/reference/google-cloud-trace/latest/Google-Cloud-Trace-Railtie)\n- [0.44.1](/ruby/docs/reference/google-cloud-trace/0.44.1/Google-Cloud-Trace-Railtie)\n- [0.43.0](/ruby/docs/reference/google-cloud-trace/0.43.0/Google-Cloud-Trace-Railtie)\n- [0.42.2](/ruby/docs/reference/google-cloud-trace/0.42.2/Google-Cloud-Trace-Railtie)\n- [0.41.4](/ruby/docs/reference/google-cloud-trace/0.41.4/Google-Cloud-Trace-Railtie) \nReference documentation and code samples for the Cloud Trace API class Google::Cloud::Trace::Railtie.\n\nRails integration for Stackdriver Trace\n---------------------------------------\n\nThis Railtie is a drop-in Stackdriver Trace instrumentation plugin\nfor Ruby on Rails applications. If present, it automatically\ninstruments your Rails app to record performance traces and cause them\nto appear on your Stackdriver console.\n\n### Installation\n\nTo install this plugin, the gem `google-cloud-trace` must be in your\nGemfile. You also must add the following line to your `application.rb`\nfile:\n\n`ruby\nrequire \"google/cloud/trace/rails\"\n`\n\nIf you include the `stackdriver` gem in your Gemfile, the above is done\nfor you automatically, and you do not need to edit your\n`application.rb`.\n\n### Configuration\n\nSee the [Instrumentation Guide](./INSTRUMENTATION \"Instrumentation Guide\") and\n[Configuration\nGuide](https://googleapis.dev/ruby/stackdriver/latest/file.INSTRUMENTATION_CONFIGURATION.html)\non how to configure the Railtie and Middleware.\n\n### Measuring custom functionality\n\nTo add a custom measurement to a request trace, use the classes\nprovided in this library. Below is an example to get you started.\n\n`ruby\nclass MyController \u003c ApplicationController\ndef index\nGoogle::Cloud::Trace.in_span \"Sleeping on the job!\" do\nsleep rand\nend\nrender plain: \"Hello World!\"\nend\nend\n` \n\nInherits\n--------\n\n- Rails::Railtie\n\nConstants\n---------\n\n### DEFAULT_NOTIFICATIONS\n\n**value:** \\[\n\"sql.active_record\",\n\"render_template.action_view\",\n\"send_file.action_controller\",\n\"send_data.action_controller\",\n\"deliver.action_mailer\"\n\\].freeze \nThe default list of ActiveSupport notification types to include in\ntraces."]]