Stackdriver Trace Instrumentation

Then google-cloud-trace gem provides a Rack Middleware class that integrateswith Rack-based application frameworks, such as Rails and Sinatra. Wheninstalled, the middleware collects performance traces of requests and, subjectto sampling constraints, submits them to the Stackdriver Trace service.

Additionally, the google-cloud-trace gem provides a Railtie class thatautomatically enables the Rack Middleware in Rails applications when used.

Configuration

The default configuration enables Stackdriver instrumentation features to run onGoogle Cloud Platform. You can easily configure the instrumentation library ifyou want to run on a non Google Cloud environment or you want to customize thedefault behavior.

See theConfigurationGuidefor full configuration parameters.

Rails Integration

To use the Stackdriver Logging Railtie for Ruby on Rails applications, simplyadd this line toconfig/application.rb:

require"google/cloud/trace/rails"

Alternatively, check out thestackdrivergem, which enables this Railtie by default.

Rack Integration

Other Rack base frameworks can also directly leverage the built-in Middleware.

require"google/cloud/trace"useGoogle::Cloud::Trace::Middleware

Faraday Middleware

On top of the Rack Middleware, you can also trace outbound Faraday requests byusing the Faraday Middleware provided with this gem:

require"google/cloud/trace/faraday_middleware"conn=Faraday.new"https://www.google.com"conn.useGoogle::Cloud::Trace::FaradayMiddlewareresult=conn.get

A child span will be create for each outbound Faraday request, and will besubmitted together with the overall application request trace by the RackMiddleware.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.