Class: ElasticAPM::Middleware Private

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/elastic_apm/middleware.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary

Constants included from Logging

Logging::LEVELS, Logging::PREFIX

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(app) ⇒ Middleware

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Middleware.



9
10
11
# File 'lib/elastic_apm/middleware.rb', line 9

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/MethodLength



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/elastic_apm/middleware.rb', line 14

def call(env)
  begin
    if running? && !path_ignored?(env)
      transaction = start_transaction(env)
    end

    resp = @app.call env
  rescue InternalError
    raise # Don't report ElasticAPM errors
  rescue ::Exception => e
    ElasticAPM.report(e, handled: false)
    raise
  ensure
    if resp && transaction
      status, headers, _body = resp
      transaction.add_response(status, headers: headers)
    end

    ElasticAPM.end_transaction http_result(status)
  end

  resp
end