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 =
"1.0.15"
Constants included
from Logger
Logger::PREFIX
Class Attribute Summary collapse
Class Method Summary
collapse
-
.aggregate(name, params = {}) ⇒ Object
-
.configure(silent = false) {|configuration| ... } ⇒ Object
-
.current_timestamp ⇒ Object
-
.destringify_value(value) ⇒ Object
-
.generate_data(name, params) ⇒ Object
-
.heartbeat(name, interval, params) ⇒ Object
-
.ignorable_exception?(e) ⇒ Boolean
-
.queue ⇒ Object
-
.report(name, params = {}, udp = false) ⇒ Object
-
.report_deployment(context = nil, udp = false) ⇒ Object
-
.report_exception(e, env = {}) ⇒ Object
(also: transmit)
-
.report_exception_unless_ignorable(e, env = {}) ⇒ Object
(also: transmit_unless_ignorable)
-
.rescue(&block) ⇒ Object
-
.rescue_and_reraise(&block) ⇒ Object
-
.sum(name, params = {}) ⇒ Object
-
.time(name, params = {}) ⇒ Object
Class Attribute Details
.api ⇒ Object
Returns the value of attribute api.
28
29
30
|
# File 'lib/errplane.rb', line 28
def api
@api
end
|
.configuration ⇒ Object
35
36
37
|
# File 'lib/errplane.rb', line 35
def configuration
@configuration ||= Configuration.new
end
|
Class Method Details
.aggregate(name, params = {}) ⇒ Object
50
51
52
|
# File 'lib/errplane.rb', line 50
def aggregate(name, params = {})
Errplane.api.send generate_data(name, params), "t"
end
|
30
31
32
33
|
# File 'lib/errplane.rb', line 30
def configure(silent = false)
yield(configuration)
self.api = Api.new
end
|
.current_timestamp ⇒ Object
140
141
142
|
# File 'lib/errplane.rb', line 140
def current_timestamp
Time.now.utc.to_i
end
|
.destringify_value(value) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/errplane.rb', line 58
def destringify_value(value)
if value.is_a?(String)
return value.to_f if value =~ /\./
return value.to_i
else
return value
end
end
|
.generate_data(name, params) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/errplane.rb', line 67
def generate_data(name, params)
value = destringify_value(params[:value])
point = {:v => value || 1}
point[:t] = params[:timestamp] unless params[:timestamp].nil?
if context = params[:context]
point[:c] = params[:context].is_a?(String) ? params[:context] : params[:context].to_json
end
if dimensions = params[:dimensions]
point[:d] = Hash[params[:dimensions].map {|k,v| [k.to_s, v.to_s]}]
end
{
:n => name.gsub(/\s+/, "_"),
:p => [point]
}
end
|
.heartbeat(name, interval, params) ⇒ Object
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/errplane.rb', line 90
def heartbeat(name, interval, params)
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, :dimensions => params[:dimensions], :context => params[:context])
end
end
end
|
.ignorable_exception?(e) ⇒ Boolean
144
145
146
147
148
|
# File 'lib/errplane.rb', line 144
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
|
.queue ⇒ Object
39
40
41
|
# File 'lib/errplane.rb', line 39
def queue
@queue ||= MaxQueue.new(configuration.queue_maximum_depth)
end
|
.report(name, params = {}, udp = false) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/errplane.rb', line 43
def report(name, params = {}, udp = false)
unless configuration.ignored_reports.find{ |msg| /#{msg}/ =~ name }
data = generate_data(name, params)
udp ? Errplane.api.send(data) : Errplane.queue.push(data)
end
end
|
.report_deployment(context = nil, udp = false) ⇒ Object
86
87
88
|
# File 'lib/errplane.rb', line 86
def report_deployment(context = nil, udp = false)
report("deployments", {:context => context}, udp)
end
|
.report_exception(e, env = {}) ⇒ Object
Also known as:
transmit
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/errplane.rb', line 120
def report_exception(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({
:n => "exceptions",
:p => [{
:v => 1,
:c => exception_presenter.context.to_json,
:d => exception_presenter.dimensions
}]
})
rescue => e
log :info, "[Errplane] Something went terribly wrong. Exception failed to take off! #{e.class}: #{e.message}"
end
end
|
.report_exception_unless_ignorable(e, env = {}) ⇒ Object
Also known as:
transmit_unless_ignorable
115
116
117
|
# File 'lib/errplane.rb', line 115
def report_exception_unless_ignorable(e, env = {})
report_exception(e, env) unless ignorable_exception?(e)
end
|
.rescue(&block) ⇒ Object
150
151
152
153
154
155
156
157
158
|
# File 'lib/errplane.rb', line 150
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
160
161
162
163
164
165
|
# File 'lib/errplane.rb', line 160
def rescue_and_reraise(&block)
block.call
rescue StandardError => e
transmit_unless_ignorable(e)
raise(e)
end
|
.sum(name, params = {}) ⇒ Object
54
55
56
|
# File 'lib/errplane.rb', line 54
def sum(name, params = {})
Errplane.api.send generate_data(name, params), "c"
end
|
.time(name, params = {}) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/errplane.rb', line 101
def time(name, params = {})
time_elapsed = if block_given?
start_time = Time.now
yield_value = yield
((Time.now - start_time)*1000).ceil
else
params[:value] || 0
end
report(name, :value => time_elapsed)
yield_value
end
|