Class: DatadogNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog_notifier.rb,
lib/datadog_notifier/version.rb

Overview

DatadogNotifier for custom error notification to datadog

Constant Summary collapse

VERSION =
'1.0.4'

Class Method Summary collapse

Class Method Details

.fetch_backtrace(exception) ⇒ Object



27
28
29
30
31
# File 'lib/datadog_notifier.rb', line 27

def self.fetch_backtrace(exception)
  return { custom_exception: true } if exception.blank?
  return exception.backtrace if exception.class.ancestors.include?(StandardError)
  exception
end

.find_root_span(child_span) ⇒ Object



21
22
23
24
25
# File 'lib/datadog_notifier.rb', line 21

def self.find_root_span(child_span)
  current_span = child_span
  current_span = current_span.send(:parent) while current_span.send(:parent)
  current_span
end

.notify(exception, payload = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/datadog_notifier.rb', line 9

def self.notify(exception, payload = {})
  root_span = find_root_span(Datadog::Tracing.active_span)
  if exception.is_a?(String)
    exception = DatadogNotifierException.new exception
    backtrace = fetch_backtrace(payload)
    exception.set_backtrace(backtrace.inspect)
  end
  root_span.set_error(exception)
  root_span.set_tag('custom_dd_notifier', true)
  root_span.set_tag('payload', payload.to_json) if payload.present?
end