class BaselineRedRpm::Instruments::Rack

Attributes

app[R]

Public Class Methods

new(app) click to toggle source

include BaselineRedRpm::Instruments::RackModule

# File lib/baseline_red_rpm/instruments/rack.rb, line 56
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/baseline_red_rpm/instruments/rack.rb, line 60
def call(env)
  req = ::Rack::Request.new(env)

  unless ignore_path?(req.path)
    extracted_ctx = BaselineRedRpm.tracer.extract(OpenTracing::FORMAT_RACK, env)
    BaselineRedRpm::Tracer.sample!(extracted_ctx, !!req.params["app-perf-sample"])

    if BaselineRedRpm::Tracer.tracing?
      span = BaselineRedRpm.tracer.start_span(@app.class.name, :child_of => extracted_ctx, tags: {
        "component" => "Rack",
        "span.kind" => "client"
      })
      BaselineRedRpm::Utils.log_source_and_backtrace(span, :rack)
    end
  end

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

  if span
    span.set_tag "peer.address", req.host
    span.set_tag "peer.port", req.port
    span.set_tag "http.method", req.request_method
    span.set_tag "http.url", req.path
    span.set_tag "http.status_code", status
  end

  [status, headers, response]
rescue Exception => e
  if span
    span.set_tag('error', true)
    span.log_error(e)
  end
  raise
ensure
  span.finish if span
  BaselineRedRpm::Tracer.sample_off!
end
ignore_path?(path) click to toggle source
# File lib/baseline_red_rpm/instruments/rack.rb, line 98
def ignore_path?(path)
  path.to_s =~ BaselineRedRpm.config.ignore_paths
end