Class: Exceptify::DatadogNotifier::DatadogExceptionEvent
- Inherits:
-
Object
- Object
- Exceptify::DatadogNotifier::DatadogExceptionEvent
- Includes:
- BacktraceCleaner
- Defined in:
- lib/exceptify/datadog_notifier.rb
Constant Summary collapse
- MAX_TITLE_LENGTH =
120- MAX_VALUE_LENGTH =
300- MAX_BACKTRACE_SIZE =
3- ALERT_TYPE =
"error"
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#notification ⇒ Object
readonly
Returns the value of attribute notification.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #backtrace ⇒ Object
- #controller ⇒ Object
- #event ⇒ Object
- #formatted_backtrace ⇒ Object
- #formatted_body ⇒ Object
- #formatted_key_value(key, value) ⇒ Object
- #formatted_request ⇒ Object
- #formatted_session ⇒ Object
- #formatted_title ⇒ Object
-
#initialize(exception, options) ⇒ DatadogExceptionEvent
constructor
A new instance of DatadogExceptionEvent.
- #inspect_object(object) ⇒ Object
- #request ⇒ Object
- #tags ⇒ Object
- #title_prefix ⇒ Object
- #truncate(string, max) ⇒ Object
Methods included from BacktraceCleaner
Constructor Details
#initialize(exception, options) ⇒ DatadogExceptionEvent
Returns a new instance of DatadogExceptionEvent.
43 44 45 46 47 |
# File 'lib/exceptify/datadog_notifier.rb', line 43 def initialize(exception, ) @notification = Notification.new(exception, , backtrace_cleaner: self) @exception = notification.exception @options = end |
Instance Attribute Details
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
39 40 41 |
# File 'lib/exceptify/datadog_notifier.rb', line 39 def exception @exception end |
#notification ⇒ Object (readonly)
Returns the value of attribute notification.
39 40 41 |
# File 'lib/exceptify/datadog_notifier.rb', line 39 def notification @notification end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
39 40 41 |
# File 'lib/exceptify/datadog_notifier.rb', line 39 def @options end |
Instance Method Details
#backtrace ⇒ Object
57 58 59 |
# File 'lib/exceptify/datadog_notifier.rb', line 57 def backtrace @backtrace ||= notification.backtrace end |
#controller ⇒ Object
53 54 55 |
# File 'lib/exceptify/datadog_notifier.rb', line 53 def controller @controller ||= notification.controller end |
#event ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/exceptify/datadog_notifier.rb', line 69 def event title = formatted_title body = formatted_body Dogapi::Event.new( body, msg_title: title, alert_type: ALERT_TYPE, tags: , aggregation_key: [title] ) end |
#formatted_backtrace ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/exceptify/datadog_notifier.rb', line 128 def formatted_backtrace size = [backtrace.size, MAX_BACKTRACE_SIZE].min text = [] text << "### **Backtrace**" text << "````" size.times { |i| text << backtrace[i] } text << "````" text << "___" text.join("\n") end |
#formatted_body ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/exceptify/datadog_notifier.rb', line 89 def formatted_body text = [] text << "%%%" text << formatted_request if request text << formatted_session if request text << formatted_backtrace text << "%%%" text.join("\n") end |
#formatted_key_value(key, value) ⇒ Object
101 102 103 |
# File 'lib/exceptify/datadog_notifier.rb', line 101 def formatted_key_value(key, value) "**#{key}:** #{value}" end |
#formatted_request ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/exceptify/datadog_notifier.rb', line 105 def formatted_request text = [] text << "### **Request**" text << formatted_key_value("URL", request.url) text << formatted_key_value("HTTP Method", request.request_method) text << formatted_key_value("IP Address", request.remote_ip) text << formatted_key_value("Parameters", request.filtered_parameters.inspect) text << formatted_key_value("Timestamp", notification.) text << formatted_key_value("Server", notification.hostname) text << formatted_key_value("Rails root", Rails.root) if defined?(Rails) && Rails.respond_to?(:root) text << formatted_key_value("Process", Process.pid) text << "___" text.join("\n") end |
#formatted_session ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/exceptify/datadog_notifier.rb', line 120 def formatted_session text = [] text << "### **Session**" text << formatted_key_value("Data", request.session.to_hash) text << "___" text.join("\n") end |
#formatted_title ⇒ Object
82 83 84 85 86 87 |
# File 'lib/exceptify/datadog_notifier.rb', line 82 def formatted_title title = "#{title_prefix}#{controller_subtitle} (#{exception.class}) #{exception..inspect}" truncate(title, MAX_TITLE_LENGTH) end |
#inspect_object(object) ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/exceptify/datadog_notifier.rb', line 144 def inspect_object(object) case object when Hash, Array truncate(object.inspect, MAX_VALUE_LENGTH) else object.to_s end end |
#request ⇒ Object
49 50 51 |
# File 'lib/exceptify/datadog_notifier.rb', line 49 def request @request ||= notification.request_context.request end |
#tags ⇒ Object
61 62 63 |
# File 'lib/exceptify/datadog_notifier.rb', line 61 def [:tags] || [] end |
#title_prefix ⇒ Object
65 66 67 |
# File 'lib/exceptify/datadog_notifier.rb', line 65 def title_prefix [:title_prefix] || "" end |
#truncate(string, max) ⇒ Object
140 141 142 |
# File 'lib/exceptify/datadog_notifier.rb', line 140 def truncate(string, max) (string.length > max) ? "#{string[0...max]}..." : string end |