Class: Google::Cloud::Debugger::Middleware
- Inherits:
-
Object
- Object
- Google::Cloud::Debugger::Middleware
- Defined in:
- lib/google/cloud/debugger/middleware.rb
Overview
Rack Middleware implementation that supports Stackdriver Debugger Agent in Rack-based Ruby frameworks. It instantiates a new debugger agent if one isn't given already. It helps optimize Debugger Agent Tracer performance by suspend and resume tracer between each request.
Instance Method Summary collapse
-
#call(env) ⇒ Rack::Response
Rack middleware entry point.
-
#initialize(app, debugger: nil, **kwargs) ⇒ Google::Cloud::Debugger::Middleware
constructor
Create a new Debugger Middleware.
Constructor Details
#initialize(app, debugger: nil, **kwargs) ⇒ Google::Cloud::Debugger::Middleware
Create a new Debugger Middleware.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/google/cloud/debugger/middleware.rb', line 43 def initialize app, debugger: nil, **kwargs @app = app load_config kwargs if debugger @debugger = debugger else @debugger = Debugger.new(project_id: configuration.project_id, credentials: configuration.credentials, service_name: configuration.service_name, service_version: configuration.service_version) @debugger.agent.quota_manager = Google::Cloud::Debugger::RequestQuotaManager.new end # Immediately start the debugger agent @debugger.start end |
Instance Method Details
#call(env) ⇒ Rack::Response
Rack middleware entry point. In most Rack based frameworks, a request is served by one thread. It enables/resume the debugger breakpoints tracing and stops/pauses the tracing afterwards to help improve debugger performance.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/google/cloud/debugger/middleware.rb', line 75 def call env # Enable/resume breakpoints tracing @debugger.agent.tracer.start # Use Stackdriver Logger for debugger if available if env["rack.logger"].is_a? Google::Cloud::Logging::Logger @debugger.agent.logger = env["rack.logger"] end @app.call env ensure # Stop breakpoints tracing beyond this point @debugger.agent.tracer.disable_traces_for_thread # Reset quotas after each request finishes. @debugger.agent.quota_manager.reset if @debugger.agent.quota_manager end |