lib/app.rb
# Reports the given exception to Haystack.
#
# exception - An Exception instance.
#
# Returns nothing.
Reports the given exception to Haystack.
exception - An Exception instance.

Returns nothing.
Reports the given exception to Haystack . exception - An Exception instance . Returns nothing .
def report_exception(service_class, service_data, exception)
    backtrace = Array(exception.backtrace)[0..500]
    data = {
      'app'       => 'github-services',
      'type'      => 'exception',
      'class'     => exception.class.to_s,
      'server'    => settings.hostname,
      'message'   => exception.message[0..254],
      'backtrace' => backtrace.join("\n"),
      'rollup'    => Digest::MD5.hexdigest(exception.class.to_s + backtrace[0]),
      'service'   => service_class.to_s
    }
    if exception.kind_of?(Service::Error)
      if exception.original_exception
        data['original_class'] = exception.original_exception.to_s
        data['backtrace'] = exception.original_exception.backtrace.join("\n")
        data['message'] = exception.original_exception.message[0..254]
      end
    elsif !exception.kind_of?(Service::TimeoutError)
      data['original_class'] = data['class']
      data['class'] = 'Service::Error'
    end
    if service_class == Service::Web
      data['service_data'] = service_data.inspect
    end
    if settings.hostname =~ /^sh1\.(rs|stg)\.github\.com$/
      Net::HTTP.new('haystack', 80).
        post('/async', "json=#{Rack::Utils.escape(data.to_json)}")
    else
      $stderr.puts data[ 'message' ]
      $stderr.puts data[ 'backtrace' ]
    end
  rescue => boom
    $stderr.puts "reporting exception failed:"
    $stderr.puts "#{boom.class}: #{boom}"
    $stderr.puts "#{boom.backtrace.join("\n")}"
  end
def report_exception ( service_class , service_data , exception ) backtrace = Array ( exception . backtrace ) [ 0 .. 500 ] data = { 'app' => 'github-services' , 'type' => 'exception' , 'class' => exception . class . to_s , 'server' => settings . hostname , 'message' => exception . message [ 0 .. 254 ] , 'backtrace' => backtrace . join ( "\n" ) , 'rollup' => Digest :: MD5 . hexdigest ( exception . class . to_s + backtrace [ 0 ] ) , 'service' => service_class . to_s } if exception . kind_of? ( Service :: Error ) if exception . original_exception data [ 'original_class' ] = exception . original_exception . to_s data [ 'backtrace' ] = exception . original_exception . backtrace . join ( "\n" ) data [ 'message' ] = exception . original_exception . message [ 0 .. 254 ] end elsif ! exception . kind_of? ( Service :: TimeoutError ) data [ 'original_class' ] = data [ 'class' ] data [ 'class' ] = 'Service::Error' end if service_class == Service :: Web data [ 'service_data' ] = service_data . inspect end if settings . hostname =~ / ^sh1 \. (rs|stg) \. github \. com$ / Net :: HTTP . new ( 'haystack' , 80 ) . post ( '/async' , "json=#{Rack::Utils.escape(data.to_json)}" ) else $stderr . puts data [ 'message' ] $stderr . puts data [ 'backtrace' ] end rescue => boom $stderr . puts "reporting exception failed:" $stderr . puts "#{boom.class}: #{boom}" $stderr . puts "#{boom.backtrace.join("\n")}" end
Reports the given exception to Haystack.
Reports the given exception to Haystack .
# run only in github's production environment # swallow errors
service_class
<not_specific>
service_data
<not_specific>
exception
<not_specific>