Class: Startback::Audit::Middleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



5
6
7
# File 'lib/startback/audit/middleware.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/startback/audit/middleware.rb', line 9

def call(env)
  context = ::Startback::Context::Middleware.context(env)

  # attach to the existing trace if any
  trace_id = env['HTTP_X_TRACE_ID']
  span_id = env['HTTP_X_SPAN_ID']
  context.tracer = context.tracer.attach_to(trace_id, span_id) if trace_id && span_id

  # trace it!
  context.trace_span({
    :type => :request_handler,
    :method => env['REQUEST_METHOD'],
    :path => env['PATH_INFO'],
    :qs => env['QUERY_STRING']
  }) do
    @app.call(env)
  end
end