Class: HubStep::Rack::Middleware

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

Overview

Rack middleware for wrapping a request in a span.

Constant Summary collapse

SPAN =
"#{name}.span"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, tracer, enable_if) ⇒ Middleware

Create a Middleware

tracer - a HubStep::Tracer instance enable_if - Proc that is passed the env for each request. If the Proc

returns true, the tracer will be enabled for the duration
of the request. If the Proc returns false, the tracer will
be disabled for the duration of the request.


27
28
29
30
31
# File 'lib/hubstep/rack/middleware.rb', line 27

def initialize(app, tracer, enable_if)
  @app = app
  @tracer = tracer
  @enable_if = enable_if
end

Class Method Details

.get_span(env) ⇒ Object

Get the span that represents this request

env - a Rack env Hash

Returns a Span.



16
17
18
# File 'lib/hubstep/rack/middleware.rb', line 16

def self.get_span(env)
  env[SPAN] || Tracer::InertSpan.instance
end

Instance Method Details

#call(env) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/hubstep/rack/middleware.rb', line 33

def call(env)
  @tracer.with_enabled(@enable_if.call(env)) do
    trace(env) do
      @app.call(env)
    end
  end
end