Module: Safely
- Extended by:
- Methods
- Defined in:
- lib/safely/core.rb,
lib/safely/version.rb,
lib/safely/services.rb
Defined Under Namespace
Modules: Methods
Constant Summary collapse
- VERSION =
"0.4.1"
- DEFAULT_EXCEPTION_METHOD =
proc do |e, info| begin Airbrake.notify(e, info) if defined?(Airbrake) if defined?(Appsignal) if Appsignal::VERSION.to_i >= 3 Appsignal.send_error(e) do |transaction| transaction.(info) end else Appsignal.send_error(e, info) end end if defined?(Bugsnag) Bugsnag.notify(e) do |report| report.add_tab(:info, info) if info.any? end end if defined?(Datadog::Tracing) Datadog::Tracing.active_span&.(info) Datadog::Tracing.active_span&.set_error(e) end ExceptionNotifier.notify_exception(e, data: info) if defined?(ExceptionNotifier) # TODO add info Google::Cloud::ErrorReporting.report(e) if defined?(Google::Cloud::ErrorReporting) Honeybadger.notify(e, context: info) if defined?(Honeybadger) NewRelic::Agent.notice_error(e, custom_params: info) if defined?(NewRelic::Agent) Raven.capture_exception(e, extra: info) if defined?(Raven) Raygun.track_exception(e, custom_data: info) if defined?(Raygun) Rollbar.error(e, info) if defined?(Rollbar) if defined?(ScoutApm::Error) # no way to add context for a single call # ScoutApm::Context.add(info) ScoutApm::Error.capture(e) end Sentry.capture_exception(e, extra: info) if defined?(Sentry) rescue => e $stderr.puts "[safely] Error reporting exception: #{e.class.name}: #{e.}" end end
Class Attribute Summary collapse
- .env ⇒ Object
-
.raise_envs ⇒ Object
Returns the value of attribute raise_envs.
-
.report_exception_method ⇒ Object
Returns the value of attribute report_exception_method.
-
.tag ⇒ Object
Returns the value of attribute tag.
-
.throttle_counter ⇒ Object
Returns the value of attribute throttle_counter.
Class Method Summary collapse
Methods included from Methods
Class Attribute Details
.env ⇒ Object
29 30 31 |
# File 'lib/safely/core.rb', line 29 def env @env ||= ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development" end |
.raise_envs ⇒ Object
Returns the value of attribute raise_envs.
10 11 12 |
# File 'lib/safely/core.rb', line 10 def raise_envs @raise_envs end |
.report_exception_method ⇒ Object
Returns the value of attribute report_exception_method.
10 11 12 |
# File 'lib/safely/core.rb', line 10 def report_exception_method @report_exception_method end |
.tag ⇒ Object
Returns the value of attribute tag.
10 11 12 |
# File 'lib/safely/core.rb', line 10 def tag @tag end |
.throttle_counter ⇒ Object
Returns the value of attribute throttle_counter.
10 11 12 |
# File 'lib/safely/core.rb', line 10 def throttle_counter @throttle_counter end |
Class Method Details
.report_exception(e, tag: nil, context: {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/safely/core.rb', line 13 def report_exception(e, tag: nil, context: {}) tag = Safely.tag if tag.nil? if tag && e. e = e.dup # leave original exception unmodified = e. e.define_singleton_method(:message) do "[#{tag == true ? "safely" : tag}] #{}" end end if report_exception_method.arity == 1 report_exception_method.call(e) else report_exception_method.call(e, context) end end |
.throttled?(e, options) ⇒ Boolean
33 34 35 36 37 38 |
# File 'lib/safely/core.rb', line 33 def throttled?(e, ) return false unless key = "#{[:key] || Digest::MD5.hexdigest([e.class.name, e., e.backtrace.join("\n")].join("/"))}/#{(Time.now.to_i / [:period]) * [:period]}" throttle_counter.clear if throttle_counter.size > 1000 # prevent from growing indefinitely (throttle_counter[key] += 1) > [:limit] end |