Module: LightStep::Transport::HTTPJSON::Failbot

Included in:
LightStep::Transport::HTTPJSON
Defined in:
lib/hubstep/failbot.rb

Overview

This reimplementation of LightStep::Transport::HTTPJSON#report reports network errors and other exceptions to Failbot.

Defined Under Namespace

Classes: HTTPError

Instance Method Summary collapse

Instance Method Details

#report(report) ⇒ Object

There’s no way to call through to the normal implementation while getting access to the request/response objects, so we just copy all the code here.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hubstep/failbot.rb', line 17

def report(report) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  p report if @verbose >= 3

  https = Net::HTTP.new(@host, @port)
  https.use_ssl = @encryption == ENCRYPTION_TLS
  req = Net::HTTP::Post.new("/api/v0/reports")
  req["LightStep-Access-Token"] = @access_token
  req["Content-Type"] = "application/json"
  req["Connection"] = "keep-alive"
  req.body = report.to_json

  ::Failbot.push(request_body: req.body)

  res = https.request(req)

  puts res.to_s, res.body if @verbose >= 3

  track_error(res)

  nil
ensure
  ::Failbot.report!($ERROR_INFO) if $ERROR_INFO
  ::Failbot.pop
end

#track_error(res) ⇒ Object



42
43
44
45
46
47
# File 'lib/hubstep/failbot.rb', line 42

def track_error(res)
  return unless res.is_a?(Net::HTTPClientError) || res.is_a?(Net::HTTPServerError)
  exception = HTTPError.new("#{res.code} #{res.message}")
  exception.set_backtrace(caller)
  ::Failbot.report!(exception, response_body: res.body, response_uri: res.uri)
end