Then google-cloud-trace gem provides a Rack Middleware class that integrates
with Rack-based application frameworks, such as Rails and Sinatra. When
installed, the middleware collects performance traces of requests and, subject
to sampling constraints, submits them to the Stackdriver Trace service.
Additionally, the google-cloud-trace gem provides a Railtie class that
automatically enables the Rack Middleware in Rails applications when used.
Configuration
The default configuration enables Stackdriver instrumentation features to run on
Google Cloud Platform. You can easily configure the instrumentation library if
you want to run on a non Google Cloud environment or you want to customize the
default behavior.
A child span will be create for each outbound Faraday request, and will be
submitted together with the overall application request trace by the Rack
Middleware.
[[["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,["Version latestkeyboard_arrow_down\n\n- [0.45.0 (latest)](/ruby/docs/reference/google-cloud-trace/latest/INSTRUMENTATION)\n- [0.44.1](/ruby/docs/reference/google-cloud-trace/0.44.1/INSTRUMENTATION)\n- [0.43.0](/ruby/docs/reference/google-cloud-trace/0.43.0/INSTRUMENTATION)\n- [0.42.2](/ruby/docs/reference/google-cloud-trace/0.42.2/INSTRUMENTATION)\n- [0.41.4](/ruby/docs/reference/google-cloud-trace/0.41.4/INSTRUMENTATION) \n\nStackdriver Trace Instrumentation\n=================================\n\nThen google-cloud-trace gem provides a Rack Middleware class that integrates\nwith Rack-based application frameworks, such as Rails and Sinatra. When\ninstalled, the middleware collects performance traces of requests and, subject\nto sampling constraints, submits them to the Stackdriver Trace service.\n\nAdditionally, the google-cloud-trace gem provides a Railtie class that\nautomatically enables the Rack Middleware in Rails applications when used.\n\nConfiguration\n-------------\n\nThe default configuration enables Stackdriver instrumentation features to run on\nGoogle Cloud Platform. You can easily configure the instrumentation library if\nyou want to run on a non Google Cloud environment or you want to customize the\ndefault behavior.\n\nSee the [Configuration\nGuide](https://googleapis.dev/ruby/stackdriver/latest/file.INSTRUMENTATION_CONFIGURATION.html)\nfor full configuration parameters.\n\nRails Integration\n-----------------\n\nTo use the Stackdriver Logging Railtie for Ruby on Rails applications, simply\nadd this line to `config/application.rb`: \n\n```ruby\nrequire \"google/cloud/trace/rails\"\n```\n\nAlternatively, check out the\n[stackdriver](https://googleapis.dev/ruby/stackdriver/latest)\ngem, which enables this Railtie by default.\n\nRack Integration\n----------------\n\nOther Rack base frameworks can also directly leverage the built-in Middleware. \n\n```ruby\nrequire \"google/cloud/trace\"\nuse Google::Cloud::Trace::Middleware\n```\n\nFaraday Middleware\n------------------\n\nOn top of the Rack Middleware, you can also trace outbound Faraday requests by\nusing the Faraday Middleware provided with this gem: \n\n```ruby\nrequire \"google/cloud/trace/faraday_middleware\"\n\nconn = Faraday.new \"https://www.google.com\"\nconn.use Google::Cloud::Trace::FaradayMiddleware\n\nresult = conn.get\n```\n\nA child span will be create for each outbound Faraday request, and will be\nsubmitted together with the overall application request trace by the Rack\nMiddleware."]]