Class: Tracebin::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/tracebin/middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



8
9
10
11
12
13
# File 'lib/tracebin/middleware.rb', line 8

def initialize(app)
  @app = app
  @config = Tracebin::Agent.config

  Tracebin::Agent.start! unless Tracebin::Agent.started?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/tracebin/middleware.rb', line 6

def config
  @config
end

Instance Method Details

#__call(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tracebin/middleware.rb', line 19

def __call(env)
  path = env['REQUEST_PATH']
  ignored_paths = config.ignored_paths.map { |root| %r{^#{root}} }

  if ignored_paths.any? { |root| !!root.match(path) }
    @app.call env
  else
    timer = Timer.new
    timer.start!

    status, headers, response = @app.call(env)

    timer.transaction_name = fetch_endpoint_name env

    timer.stop!

    PuppetMaster.new(timer).process

    [status, headers, response]
  end
end

#call(env) ⇒ Object



15
16
17
# File 'lib/tracebin/middleware.rb', line 15

def call(env)
  dup.__call(env)
end