Class: TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware
- Inherits:
-
Object
- Object
- TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware
- Defined in:
- lib/tcell_agent/rails/middleware/context_middleware.rb
Constant Summary collapse
- THREADS =
rubocop:disable Style/MutableConstant
{}
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ContextMiddleware
constructor
A new instance of ContextMiddleware.
Constructor Details
#initialize(app) ⇒ ContextMiddleware
Returns a new instance of ContextMiddleware.
14 15 16 |
# File 'lib/tcell_agent/rails/middleware/context_middleware.rb', line 14 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tcell_agent/rails/middleware/context_middleware.rb', line 18 def call(env) if TCellAgent.configuration.should_intercept_requests? env[TCellAgent::Instrumentation::TCELL_ID] = TCellAgent::Instrumentation::TCellData.new TCellAgent::Instrumentation.safe_block('Setting transaction_id') do env[TCellAgent::Instrumentation::TCELL_ID].transaction_id = SecureRandom.uuid request = Rack::Request.new(env) env[TCellAgent::Instrumentation::TCELL_ID].uri = request.url env[TCellAgent::Instrumentation::TCELL_ID].fullpath = request.fullpath env[TCellAgent::Instrumentation::TCELL_ID].path = request.path env[TCellAgent::Instrumentation::TCELL_ID].user_agent = request.user_agent env[TCellAgent::Instrumentation::TCELL_ID].referrer = request.referrer env[TCellAgent::Instrumentation::TCELL_ID].remote_address = request.ip env[TCellAgent::Instrumentation::TCELL_ID].reverse_proxy_header_value = TCellAgent::Utils::Rails.reverse_proxy_header(request) if request.request_method env[TCellAgent::Instrumentation::TCELL_ID].request_method = request.request_method end end env['filter_body_set'] = Set.new ContextMiddleware::THREADS[Thread.current.object_id] = env end response = @app.call(env) if TCellAgent.configuration.should_intercept_requests? ContextMiddleware::THREADS.delete(Thread.current.object_id) end response end |