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

include AppPerfRpm::Instruments::RackModule



56
57
58
# File 'lib/app_perf_rpm/instruments/rack.rb', line 56

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



52
53
54
# File 'lib/app_perf_rpm/instruments/rack.rb', line 52

def app
  @app
end

Instance Method Details

#call(env) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/app_perf_rpm/instruments/rack.rb', line 60

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

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

    if AppPerfRpm::Tracer.tracing?
      span = AppPerfRpm.tracer.start_span(@app.class.name, :child_of => extracted_ctx, tags: {
        "component" => "Rack",
        "span.kind" => "client"
      })
      AppPerfRpm::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
  AppPerfRpm::Tracer.sample_off!
end

#ignore_path?(path) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/app_perf_rpm/instruments/rack.rb', line 98

def ignore_path?(path)
  path.to_s =~ AppPerfRpm.config.ignore_paths
end