Class: Raven::Event
- Inherits:
-
Object
- Object
- Raven::Event
- Defined in:
- lib/raven/event.rb
Constant Summary collapse
- LOG_LEVELS =
{ "debug" => 10, "info" => 20, "warn" => 30, "warning" => 30, "error" => 40, "fatal" => 50, }.freeze
- BACKTRACE_RE =
/^(.+?):(\d+)(?::in `(.+?)')?$/
- PLATFORM =
"ruby".freeze
Instance Attribute Summary collapse
-
#checksum ⇒ Object
Returns the value of attribute checksum.
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#context ⇒ Object
Returns the value of attribute context.
-
#culprit ⇒ Object
Returns the value of attribute culprit.
-
#extra ⇒ Object
Returns the value of attribute extra.
-
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#level ⇒ Object
Returns the value of attribute level.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#message ⇒ Object
Returns the value of attribute message.
-
#modules ⇒ Object
Returns the value of attribute modules.
-
#project ⇒ Object
Returns the value of attribute project.
-
#release ⇒ Object
Returns the value of attribute release.
-
#server_name ⇒ Object
Returns the value of attribute server_name.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#time_spent ⇒ Object
Returns the value of attribute time_spent.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Class Method Summary collapse
- .from_exception(exc, options = {}, &block) ⇒ Object (also: captureException, capture_exception)
- .from_message(message, options = {}) ⇒ Object (also: captureMessage, capture_message)
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #get_culprit(frames) ⇒ Object
- #get_file_context(filename, lineno, context) ⇒ Object
-
#initialize(init = {}) {|_self| ... } ⇒ Event
constructor
A new instance of Event.
- #interface(name, value = nil, &block) ⇒ Object
- #list_gem_specs ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(init = {}) {|_self| ... } ⇒ Event
Returns a new instance of Event.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/raven/event.rb', line 31 def initialize(init = {}) @configuration = Raven.configuration @interfaces = {} @context = Raven.context @id = generate_event_id @project = nil @message = nil @timestamp = Time.now.utc @time_spent = nil @level = :error @logger = '' @culprit = nil @server_name = @configuration.server_name @release = @configuration.release @modules = list_gem_specs if @configuration.send_modules @user = {} @extra = {} @tags = {} @checksum = nil @fingerprint = nil yield self if block_given? if !self[:http] && @context.rack_env interface :http do |int| int.from_rack(@context.rack_env) end end init.each_pair { |key, val| instance_variable_set('@' + key.to_s, val) } @user = @context.user.merge(@user) @extra = @context.extra.merge(@extra) @tags = @configuration..merge(@context.).merge(@tags) # Some type coercion @timestamp = @timestamp.strftime('%Y-%m-%dT%H:%M:%S') if @timestamp.is_a?(Time) @time_spent = (@time_spent*1000).to_i if @time_spent.is_a?(Float) @level = LOG_LEVELS[@level.to_s.downcase] if @level.is_a?(String) || @level.is_a?(Symbol) end |
Instance Attribute Details
#checksum ⇒ Object
Returns the value of attribute checksum.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def checksum @checksum end |
#configuration ⇒ Object
Returns the value of attribute configuration.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def configuration @configuration end |
#context ⇒ Object
Returns the value of attribute context.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def context @context end |
#culprit ⇒ Object
Returns the value of attribute culprit.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def culprit @culprit end |
#extra ⇒ Object
Returns the value of attribute extra.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def extra @extra end |
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def fingerprint @fingerprint end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
26 27 28 |
# File 'lib/raven/event.rb', line 26 def id @id end |
#level ⇒ Object
Returns the value of attribute level.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def level @level end |
#logger ⇒ Object
Returns the value of attribute logger.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def logger @logger end |
#message ⇒ Object
Returns the value of attribute message.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def @message end |
#modules ⇒ Object
Returns the value of attribute modules.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def modules @modules end |
#project ⇒ Object
Returns the value of attribute project.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def project @project end |
#release ⇒ Object
Returns the value of attribute release.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def release @release end |
#server_name ⇒ Object
Returns the value of attribute server_name.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def server_name @server_name end |
#tags ⇒ Object
Returns the value of attribute tags.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def @tags end |
#time_spent ⇒ Object
Returns the value of attribute time_spent.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def time_spent @time_spent end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
27 28 29 |
# File 'lib/raven/event.rb', line 27 def @timestamp end |
Class Method Details
.from_exception(exc, options = {}, &block) ⇒ Object Also known as: captureException, capture_exception
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/raven/event.rb', line 73 def from_exception(exc, = {}, &block) exception_context = get_exception_context(exc) || {} = Raven::Utils::DeepMergeHash.deep_merge(exception_context, ) configuration = [:configuration] || Raven.configuration if exc.is_a?(Raven::Error) # Try to prevent error reporting loops Raven.logger.info "Refusing to capture Raven error: #{exc.inspect}" return nil end if configuration[:excluded_exceptions].any? { |x| (x === exc rescue false) || x == exc.class.name } Raven.logger.info "User excluded error: #{exc.inspect}" return nil end new() do |evt| evt.configuration = configuration evt. = "#{exc.class}: #{exc.}" evt.level = [:level] || :error add_exception_interface(evt, exc) yield evt if block end end |
.from_message(message, options = {}) ⇒ Object Also known as: captureMessage, capture_message
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/raven/event.rb', line 99 def (, = {}) configuration = [:configuration] || Raven.configuration new() do |evt| evt.configuration = configuration evt. = evt.level = [:level] || :error evt.interface :message do |int| int. = end if [:backtrace] evt.interface(:stacktrace) do |int| stacktrace_interface_from(int, evt, [:backtrace]) end end end end |
Instance Method Details
#[](key) ⇒ Object
200 201 202 |
# File 'lib/raven/event.rb', line 200 def [](key) interface(key) end |
#[]=(key, value) ⇒ Object
204 205 206 |
# File 'lib/raven/event.rb', line 204 def []=(key, value) interface(key, value) end |
#get_culprit(frames) ⇒ Object
242 243 244 245 |
# File 'lib/raven/event.rb', line 242 def get_culprit(frames) lastframe = frames.reverse.find(&:in_app) || frames.last "#{lastframe.filename} in #{lastframe.function} at line #{lastframe.lineno}" if lastframe end |
#get_file_context(filename, lineno, context) ⇒ Object
234 235 236 237 238 239 240 |
# File 'lib/raven/event.rb', line 234 def get_file_context(filename, lineno, context) return nil, nil, nil unless Raven::LineCache.is_valid_file(filename) lines = Array.new(2 * context + 1) do |i| Raven::LineCache.getline(filename, lineno - context + i) end [lines[0..(context - 1)], lines[context], lines[(context + 1)..-1]] end |
#interface(name, value = nil, &block) ⇒ Object
193 194 195 196 197 198 |
# File 'lib/raven/event.rb', line 193 def interface(name, value = nil, &block) int = Raven.find_interface(name) raise Error.new("Unknown interface: #{name}") unless int @interfaces[int.name] = int.new(value, &block) if value || block @interfaces[int.name] end |
#list_gem_specs ⇒ Object
188 189 190 191 |
# File 'lib/raven/event.rb', line 188 def list_gem_specs # Older versions of Rubygems don't support iterating over all specs Hash[Gem::Specification.map { |spec| [spec.name, spec.version.to_s] }] if Gem::Specification.respond_to?(:map) end |
#to_hash ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/raven/event.rb', line 208 def to_hash data = { :event_id => @id, :message => @message, :timestamp => @timestamp, :time_spent => @time_spent, :level => @level, :project => @project, :platform => PLATFORM, } data[:logger] = @logger if @logger data[:culprit] = @culprit if @culprit data[:server_name] = @server_name if @server_name data[:release] = @release if @release data[:fingerprint] = @fingerprint if @fingerprint data[:modules] = @modules if @modules data[:extra] = @extra if @extra data[:tags] = @tags if @tags data[:user] = @user if @user data[:checksum] = @checksum if @checksum @interfaces.each_pair do |name, int_data| data[name.to_sym] = int_data.to_hash end data end |