Sha256: 8fe82afba2ef80f9dafa692c9691cfd7cbde5d7e6beb978fe0401f42cf90f1bf
Contents?: true
Size: 1.3 KB
Versions: 3
Compression:
Stored size: 1.3 KB
Contents
require 'securerandom' require 'json' module Synchrolog class Middleware def initialize app @app = app end 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.cookie_jar['synchrolog_anonymous_id'].nil? request.cookie_jar['synchrolog_anonymous_id'] = SecureRandom.hex end anonymous_id = request.cookie_jar['synchrolog_anonymous_id'] user_id = request.cookie_jar['synchrolog_user_id'] SYNCHROLOG.logger.tagged("synchrolog_anonymous_id:#{anonymous_id}", "synchrolog_user_id:#{user_id}") do begin response = @app.call(env) rescue Error raise # Don't capture Synchrolog errors 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 end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
synchrolog-ruby-0.1.6 | lib/synchrolog/middleware.rb |
synchrolog-ruby-0.1.5 | lib/synchrolog/middleware.rb |
synchrolog-ruby-0.1.4 | lib/synchrolog/middleware.rb |