Class: AppPerfRpm::Instruments::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/app_perf_rpm/instruments/rack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Rack

Returns a new instance of Rack.



6
7
8
# File 'lib/app_perf_rpm/instruments/rack.rb', line 6

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



4
5
6
# File 'lib/app_perf_rpm/instruments/rack.rb', line 4

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/app_perf_rpm/instruments/rack.rb', line 10

def call(env)
  req = ::Rack::Request.new(env)

  incoming_trace = env["HTTP_X_APP_PERF_TRACE"]
  incoming_trace_id = env["HTTP_X_APP_PERF_TRACE_ID"]

  opts = {}
  if incoming_trace.to_s.eql?("1")
    opts.merge!("trace_id" => incoming_trace_id)
  end

  if ignore_path?(req.path)
    @status, @headers, @response = @app.call(env)
  else
    AppPerfRpm::Tracer.start_trace("rack", opts) do |span|
      span.type = "web"
      span.domain = req.host
      span.url = req.path
      span.options["class"] = self.class.name

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

  [@status, @headers, @response]
end

#ignore_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/app_perf_rpm/instruments/rack.rb', line 37

def ignore_path?(path)
  path.to_s =~ /\/assets/
end