Class: Google::Cloud::Debugger::Railtie
- Inherits:
-
Rails::Railtie
- Object
- Rails::Railtie
- Google::Cloud::Debugger::Railtie
- Defined in:
- lib/google/cloud/debugger/rails.rb
Overview
Railtie
Google::Cloud::Debugger::Railtie automatically adds the Google::Cloud::Debugger::Middleware to Rack in a Rails environment.
The Middleware is only added when certain conditions are met. See Railtie.use_debugger? for detail.
When loaded, the Google::Cloud::Debugger::Middleware will be inserted after the Rack::ETag Middleware, which is top of the Rack stack, closest to the application code.
The Railtie should also initialize a debugger to be used by the middleware. The debugger can be configured using the following Rails configuration:
Class Method Summary collapse
-
.use_debugger?(config) ⇒ Boolean
Determine whether to use Stackdriver Debugger or not.
Class Method Details
.use_debugger?(config) ⇒ Boolean
Determine whether to use Stackdriver Debugger or not.
Returns true if valid GCP project_id is provided and underneath API is able to authenticate. Also either Rails needs to be in "production" environment or config.stackdriver.use_debugger is explicitly true.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/google/cloud/debugger/rails.rb', line 92 def self.use_debugger? config debugger_config = parse_rails_config config # Return false if config.stackdriver.use_debugger is explicitly false use_debugger = debugger_config[:use_debugger] return false if !use_debugger.nil? && !use_debugger # Try authenticate authorize client API. Return false if unable to # authorize. begin Google::Cloud::Debugger::Credentials.credentials_with_scope( debugger_config[:keyfile]) rescue => e Rails.log "Google::Cloud::Debugger is not activated due to " \ "authorization error: #{e.}" return false end project_id = debugger_config[:project_id] || Google::Cloud::Debugger::Project.default_project if project_id.to_s.empty? Rails.log "Google::Cloud::Debugger is not activated due to empty " \ "project_id" return false end # Otherwise default to true if Rails is running in production or # config.stackdriver.use_debugger is true Rails.env.production? || use_debugger end |