Class: Synchrolog::ExceptionLogger::HTTPS
- Inherits:
-
Object
- Object
- Synchrolog::ExceptionLogger::HTTPS
- Defined in:
- lib/synchrolog/exception_logger/https.rb
Instance Method Summary collapse
- #body(response, exception, env, anonymous_id, user_id) ⇒ Object
- #capture(response, exception, env, anonymous_id, user_id) ⇒ Object
-
#initialize(api_key, **args) ⇒ HTTPS
constructor
A new instance of HTTPS.
Constructor Details
#initialize(api_key, **args) ⇒ HTTPS
Returns a new instance of HTTPS.
7 8 9 10 |
# File 'lib/synchrolog/exception_logger/https.rb', line 7 def initialize(api_key, **args) @api_key = api_key @host = args[:host] end |
Instance Method Details
#body(response, exception, env, anonymous_id, user_id) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/synchrolog/exception_logger/https.rb', line 22 def body(response, exception, env, anonymous_id, user_id) status, headers, body = *response error = exception.backtrace[0].split(':') return { event_type: 'error', timestamp: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%3NZ"), anonymous_id: anonymous_id, user_id: user_id, source: 'backend', api_key: @api_key, error: { status: status.to_s, description: exception.to_s, backtrace: exception.backtrace.join("\n"), ip_address: env['REMOTE_ADDR'], user_agent: env['HTTP_USER_AGENT'], file_name: file_name = error[0], file: File.read(error[0]), line_number: error[1].to_i } } end |
#capture(response, exception, env, anonymous_id, user_id) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/synchrolog/exception_logger/https.rb', line 12 def capture(response, exception, env, anonymous_id, user_id) return unless anonymous_id json_headers = {'Authorization' => "Basic #{@api_key}", 'Content-Type' =>'application/json'} uri = URI.parse("#{@host}/v1/track-backend-error") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.post(uri.path, body(response, exception, env, anonymous_id, user_id).to_json, json_headers) end |