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 `(.+?)')?$/
- MAX_MESSAGE_SIZE_IN_BYTES =
See Sentry server default limits at github.com/getsentry/sentry/blob/master/src/sentry/conf/server.py
1024 * 8
- PLATFORM =
"ruby".freeze
- SDK =
{ "name" => "raven-ruby", "version" => Raven::VERSION }.freeze
Instance Attribute Summary collapse
-
#backtrace ⇒ Object
Returns the value of attribute backtrace.
-
#breadcrumbs ⇒ Object
Returns the value of attribute breadcrumbs.
-
#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.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#extra ⇒ Object
Returns the value of attribute extra.
-
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
-
#id ⇒ Object
Returns the value of attribute id.
-
#level ⇒ Object
Returns the value of attribute level.
-
#linecache ⇒ Object
Returns the value of attribute linecache.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#modules ⇒ Object
Returns the value of attribute modules.
-
#release ⇒ Object
Returns the value of attribute release.
-
#runtime ⇒ Object
Returns the value of attribute runtime.
-
#server_name ⇒ Object
Returns the value of attribute server_name.
-
#server_os ⇒ Object
Returns the value of attribute server_os.
-
#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.
-
#user ⇒ Object
Returns the value of attribute user.
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
- #message ⇒ Object
- #message=(args) ⇒ Object
- #to_hash ⇒ Object
- #to_json_compatible ⇒ Object
Constructor Details
#initialize(init = {}) {|_self| ... } ⇒ Event
Returns a new instance of Event.
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 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/raven/event.rb', line 34 def initialize(init = {}) @configuration = init[:configuration] || Raven.configuration @interfaces = {} @breadcrumbs = init[:breadcrumbs] || Raven. @context = init[:context] || Raven.context @linecache = @configuration.linecache @id = SecureRandom.uuid.delete("-") @timestamp = Time.now.utc @time_spent = nil @level = :error @logger = 'ruby' @culprit = nil @server_name = @configuration.server_name @release = @configuration.release @modules = list_gem_specs if @configuration.send_modules @user = {} # TODO: contexts @extra = {} # TODO: contexts @server_os = {} # TODO: contexts @runtime = {} # TODO: contexts @tags = {} # TODO: contexts @checksum = nil @fingerprint = nil @environment = @configuration.current_environment yield self if block_given? if !self[:http] && @context.rack_env interface :http do |int| int.from_rack(@context.rack_env) end end if @context.rack_env # TODO: contexts @context.user[:ip_address] = calculate_real_ip_from_rack end init.each_pair { |key, val| public_send(key.to_s + "=", val) } @user = @context.user.merge(@user) # TODO: contexts @extra = @context.extra.merge(@extra) # TODO: contexts @tags = @configuration..merge(@context.).merge(@tags) # TODO: contexts # 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
#backtrace ⇒ Object
Returns the value of attribute backtrace.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def backtrace @backtrace end |
#breadcrumbs ⇒ Object
Returns the value of attribute breadcrumbs.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def @breadcrumbs end |
#checksum ⇒ Object
Returns the value of attribute checksum.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def checksum @checksum end |
#configuration ⇒ Object
Returns the value of attribute configuration.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def configuration @configuration end |
#context ⇒ Object
Returns the value of attribute context.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def context @context end |
#culprit ⇒ Object
Returns the value of attribute culprit.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def culprit @culprit end |
#environment ⇒ Object
Returns the value of attribute environment.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def environment @environment end |
#extra ⇒ Object
Returns the value of attribute extra.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def extra @extra end |
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def fingerprint @fingerprint end |
#id ⇒ Object
Returns the value of attribute id.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def id @id end |
#level ⇒ Object
Returns the value of attribute level.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def level @level end |
#linecache ⇒ Object
Returns the value of attribute linecache.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def linecache @linecache end |
#logger ⇒ Object
Returns the value of attribute logger.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def logger @logger end |
#modules ⇒ Object
Returns the value of attribute modules.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def modules @modules end |
#release ⇒ Object
Returns the value of attribute release.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def release @release end |
#runtime ⇒ Object
Returns the value of attribute runtime.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def runtime @runtime end |
#server_name ⇒ Object
Returns the value of attribute server_name.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def server_name @server_name end |
#server_os ⇒ Object
Returns the value of attribute server_os.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def server_os @server_os end |
#tags ⇒ Object
Returns the value of attribute tags.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def @tags end |
#time_spent ⇒ Object
Returns the value of attribute time_spent.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def time_spent @time_spent end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def @timestamp end |
#user ⇒ Object
Returns the value of attribute user.
29 30 31 |
# File 'lib/raven/event.rb', line 29 def user @user end |
Class Method Details
.from_exception(exc, options = {}, &block) ⇒ Object Also known as: captureException, capture_exception
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/raven/event.rb', line 95 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 configuration.logger.debug "Refusing to capture Raven error: #{exc.inspect}" return nil end if configuration[:excluded_exceptions].any? { |x| get_exception_class(x) === exc } configuration.logger.debug "User excluded error: #{exc.inspect}" return nil end new() do |evt| evt.configuration = configuration evt. = "#{exc.class}: #{exc.}".byteslice(0...MAX_MESSAGE_SIZE_IN_BYTES) # Messages limited to 10kb 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
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/raven/event.rb', line 121 def (, = {}) = .byteslice(0...MAX_MESSAGE_SIZE_IN_BYTES) configuration = [:configuration] || Raven.configuration new() do |evt| evt.configuration = configuration evt.level = [:level] || :error evt. = , [:message_params] || [] if [:backtrace] evt.interface(:stacktrace) do |int| stacktrace_interface_from(int, evt, [:backtrace]) end end end end |
Instance Method Details
#[](key) ⇒ Object
234 235 236 |
# File 'lib/raven/event.rb', line 234 def [](key) interface(key) end |
#[]=(key, value) ⇒ Object
238 239 240 |
# File 'lib/raven/event.rb', line 238 def []=(key, value) interface(key, value) end |
#get_culprit(frames) ⇒ Object
276 277 278 279 |
# File 'lib/raven/event.rb', line 276 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
272 273 274 |
# File 'lib/raven/event.rb', line 272 def get_file_context(filename, lineno, context) linecache.get_file_context(filename, lineno, context) end |
#interface(name, value = nil, &block) ⇒ Object
227 228 229 230 231 232 |
# File 'lib/raven/event.rb', line 227 def interface(name, value = nil, &block) int = Interface.registered[name] raise(Error, "Unknown interface: #{name}") unless int @interfaces[int.sentry_alias] = int.new(value, &block) if value || block @interfaces[int.sentry_alias] end |
#list_gem_specs ⇒ Object
222 223 224 225 |
# File 'lib/raven/event.rb', line 222 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 |
#message ⇒ Object
82 83 84 |
# File 'lib/raven/event.rb', line 82 def @interfaces[:logentry] && @interfaces[:logentry]. end |
#message=(args) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/raven/event.rb', line 86 def (args) , params = *args interface(:message) do |int| int. = int.params = params end end |
#to_hash ⇒ Object
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/raven/event.rb', line 242 def to_hash data = { :event_id => @id, :timestamp => @timestamp, :time_spent => @time_spent, :level => @level, :platform => PLATFORM, :sdk => SDK } data[:logger] = @logger if @logger data[:culprit] = @culprit if @culprit data[:server_name] = @server_name if @server_name data[:release] = @release if @release data[:environment] = @environment if @environment 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[:breadcrumbs] = @breadcrumbs.to_hash unless @breadcrumbs.empty? data[:checksum] = @checksum if @checksum @interfaces.each_pair do |name, int_data| data[name.to_sym] = int_data.to_hash end data[:message] = data end |
#to_json_compatible ⇒ Object
281 282 283 284 |
# File 'lib/raven/event.rb', line 281 def to_json_compatible cleaned_hash = async_json_processors.reduce(to_hash) { |a, e| e.process(a) } JSON.parse(JSON.generate(cleaned_hash)) end |