Class: Google::Cloud::Debugger::Middleware

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(app, debugger: nil, module_name: nil, module_version: nil, project: nil, keyfile: nil) ⇒ Google::Cloud::Debugger::Middleware

Create a new Debugger Middleware.

Parameters:

  • app (Rack Application)

    Rack application

  • debugger (Google::Cloud::Debugger::Project)

    A debugger to be used by this middleware. If not given, will construct a new one using the other parameters.

  • project (String)

    Project identifier for the Stackdriver Debugger service. Optional if a debugger is given.

  • keyfile (String, Hash)

    Keyfile downloaded from Google Cloud: either the JSON data or the path to a readable file. Optional if a debugger is given.

  • module_name (String)

    Name for the debuggee application. Optional if a debugger is given.

  • module_version (String)

    Version identifier for the debuggee application. Optiona if a debugger is given.



45
46
47
48
49
50
51
52
53
# File 'lib/google/cloud/debugger/middleware.rb', line 45

def initialize app, debugger: nil, module_name:nil, module_version: nil,
               project: nil, keyfile: nil
  @app = app
  @debugger = debugger || Debugger.new(project: project,
                                       keyfile: keyfile,
                                       module_name: module_name,
                                       module_version: module_version)
  @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.

Parameters:

  • env (Hash)

    Rack environment hash

Returns:

  • (Rack::Response)

    The response from downstream Rack app



65
66
67
68
69
70
71
72
73
# File 'lib/google/cloud/debugger/middleware.rb', line 65

def call env
  # Enable/resume breakpoints tracing
  @debugger.agent.tracer.start

  @app.call env
ensure
  # Stop breakpoints tracing beyond this point
  @debugger.agent.tracer.disable_traces_for_thread
end