Class: Synchrolog::Middleware
- Inherits:
-
Object
- Object
- Synchrolog::Middleware
- Defined in:
- lib/synchrolog/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
6 7 8 |
# File 'lib/synchrolog/middleware.rb', line 6 def initialize app @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 |
# File 'lib/synchrolog/middleware.rb', line 10 def call env request = ActionDispatch::Request.new(env) if request.original_fullpath == "/synchrolog-time" [ 200, {'Content-Type' => 'application/json'}, [{ time: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%3NZ") }.to_json] ] else if request.['synchrolog_anonymous_id'].nil? request.['synchrolog_anonymous_id'] = SecureRandom.hex end anonymous_id = request.['synchrolog_anonymous_id'] user_id = request.['synchrolog_user_id'] SYNCHROLOG.logger.tagged("synchrolog_anonymous_id:#{anonymous_id}", "synchrolog_user_id:#{user_id}") do begin response = @app.call(env) rescue Exception => exception SYNCHROLOG.exception_logger.capture(response, exception, env, anonymous_id, user_id) raise end exception = env['rack.exception'] || env['action_dispatch.exception'] SYNCHROLOG.exception_logger.capture(response, exception, env, anonymous_id, user_id) if exception response end end end |