Module: Errplane

Extended by:
Logger
Defined in:
lib/errplane.rb,
lib/errplane/api.rb,
lib/errplane/rack.rb,
lib/errplane/rails.rb,
lib/errplane/logger.rb,
lib/errplane/worker.rb,
lib/errplane/railtie.rb,
lib/errplane/sidekiq.rb,
lib/errplane/version.rb,
lib/errplane/backtrace.rb,
lib/errplane/max_queue.rb,
lib/errplane/configuration.rb,
lib/errplane/rails/benchmarking.rb,
lib/errplane/exception_presenter.rb,
lib/errplane/rails/instrumentation.rb,
lib/errplane/rails/air_traffic_controller.rb,
lib/errplane/rails/middleware/hijack_render_exception.rb,
lib/errplane/rails/middleware/hijack_rescue_action_everywhere.rb

Defined Under Namespace

Modules: Logger, Rails Classes: Api, Backtrace, Configuration, ExceptionPresenter, MaxQueue, Rack, Railtie, Sidekiq, Worker

Constant Summary collapse

VERSION =
"0.6.8"

Constants included from Logger

Logger::PREFIX

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.apiObject

Returns the value of attribute api.



28
29
30
# File 'lib/errplane.rb', line 28

def api
  @api
end

.configurationObject



35
36
37
# File 'lib/errplane.rb', line 35

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure(silent = false) {|configuration| ... } ⇒ Object

Yields:



30
31
32
33
# File 'lib/errplane.rb', line 30

def configure(silent = false)
  yield(configuration)
  self.api = Api.new
end

.current_timestampObject



104
105
106
# File 'lib/errplane.rb', line 104

def current_timestamp
  Time.now.utc.to_i
end

.heartbeat(name, interval) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/errplane.rb', line 62

def heartbeat(name, interval)
  log :debug, "Starting heartbeat '#{name}' on a #{interval} second interval."
  Thread.new do
    while true do
      log :debug, "Sleeping '#{name}' for #{interval} seconds."
      sleep(interval)
      report(name, :timestamp => "now")
    end
  end
end

.ignorable_exception?(e) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
117
118
# File 'lib/errplane.rb', line 114

def ignorable_exception?(e)
  configuration.ignore_current_environment? ||
  !!configuration.ignored_exception_messages.find{ |msg| /.*#{msg}.*/ =~ e.message  } ||
  configuration.ignored_exceptions.include?(e.class.to_s)
end

.process_line(line) ⇒ Object



108
109
110
111
112
# File 'lib/errplane.rb', line 108

def process_line(line)
  data = "#{line[:name]} #{line[:value] || 1} #{line[:timestamp] || "now"}"
  data = "#{data} #{Base64.strict_encode64(line[:context].to_json)}" if line[:context]
  data
end

.queueObject



39
40
41
# File 'lib/errplane.rb', line 39

def queue
  @queue ||= MaxQueue.new(configuration.queue_maximum_depth)
end

.report(name, params = {}, async = true) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/errplane.rb', line 43

def report(name, params = {}, async = true)
  unless configuration.ignored_reports.find{ |msg| /#{msg}/ =~ name  }
    data = {
      :name => name.gsub(/\s+/, "_"),
      :timestamp => "now"
    }.merge(params)

    if async
      Errplane.queue.push(data)
    else
      Errplane.api.post(Errplane.process_line(data))
    end
  end
end

.report_deployment(context = nil, async = false) ⇒ Object



58
59
60
# File 'lib/errplane.rb', line 58

def report_deployment(context = nil, async = false)
  report("deployments", {:context => context}, async)
end

.rescue(&block) ⇒ Object



120
121
122
123
124
125
126
127
128
# File 'lib/errplane.rb', line 120

def rescue(&block)
  block.call
rescue StandardError => e
  if configuration.ignore_current_environment?
    raise(e)
  else
    transmit_unless_ignorable(e)
  end
end

.rescue_and_reraise(&block) ⇒ Object



130
131
132
133
134
135
# File 'lib/errplane.rb', line 130

def rescue_and_reraise(&block)
  block.call
rescue StandardError => e
  transmit_unless_ignorable(e)
  raise(e)
end

.time(name, params = {}) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/errplane.rb', line 73

def time(name, params = {})
  value = if block_given?
    start_time = Time.now
    yield
    ((Time.now - start_time)*1000).ceil
  else
    params[:value] || 0
  end

  report(name, :value => value)
end

.transmit(e, env = {}) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/errplane.rb', line 89

def transmit(e, env = {})
  begin
    env = errplane_request_data if env.empty? && defined? errplane_request_data
    exception_presenter = ExceptionPresenter.new(e, env)
    log :info, "Exception: #{exception_presenter.to_json[0..512]}..."

    Errplane.queue.push({
      :name => exception_presenter.time_series_name,
      :context => exception_presenter
    })
  rescue => e
    log :info, "[Errplane] Something went terribly wrong. Exception failed to take off! #{e.class}: #{e.message}"
  end
end

.transmit_unless_ignorable(e, env = {}) ⇒ Object



85
86
87
# File 'lib/errplane.rb', line 85

def transmit_unless_ignorable(e, env = {})
  transmit(e, env) unless ignorable_exception?(e)
end