Class: Raven::Event
- Inherits:
-
Object
- Object
- Raven::Event
- Defined in:
- lib/raven/event.rb
Constant Summary collapse
- MAX_MESSAGE_SIZE_IN_BYTES =
See Sentry server default limits at github.com/getsentry/sentry/blob/master/src/sentry/conf/server.py
1024 * 8
- 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.
-
#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
(also: #event_id)
Returns the value of attribute id.
-
#level ⇒ Object
Returns the value of attribute level.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#modules ⇒ Object
Returns the value of attribute modules.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#release ⇒ Object
Returns the value of attribute release.
-
#runtime ⇒ Object
Returns the value of attribute runtime.
-
#sdk ⇒ Object
Returns the value of attribute sdk.
-
#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.
-
#transaction ⇒ Object
Returns the value of attribute transaction.
-
#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
- #add_exception_interface(exc) ⇒ Object
-
#initialize(init = {}) {|_self| ... } ⇒ Event
constructor
A new instance of Event.
- #interface(name, value = nil, &block) ⇒ Object
- #message ⇒ Object
- #message=(args) ⇒ Object
- #stacktrace_interface_from(backtrace) ⇒ Object
- #to_hash ⇒ Object
- #to_json_compatible ⇒ Object
Constructor Details
#initialize(init = {}) {|_self| ... } ⇒ Event
Returns a new instance of Event.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/raven/event.rb', line 21 def initialize(init = {}) # Set some simple default values self.id = SecureRandom.uuid.delete("-") self. = Time.now.utc self.level = :error self.logger = :ruby self.platform = :ruby self.sdk = SDK # Set some attributes with empty hashes to allow merging @interfaces = {} self.user = {} # TODO: contexts self.extra = {} # TODO: contexts self.server_os = {} # TODO: contexts self.runtime = {} # TODO: contexts self. = {} # TODO: contexts copy_initial_state # Allow attributes to be set on the event at initialization yield self if block_given? init.each_pair { |key, val| public_send("#{key}=", val) } set_core_attributes_from_configuration set_core_attributes_from_context end |
Instance Attribute Details
#backtrace ⇒ Object
Returns the value of attribute backtrace.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def backtrace @backtrace end |
#breadcrumbs ⇒ Object
Returns the value of attribute breadcrumbs.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def @breadcrumbs end |
#checksum ⇒ Object
Returns the value of attribute checksum.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def checksum @checksum end |
#configuration ⇒ Object
Returns the value of attribute configuration.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def configuration @configuration end |
#context ⇒ Object
Returns the value of attribute context.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def context @context end |
#environment ⇒ Object
Returns the value of attribute environment.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def environment @environment end |
#extra ⇒ Object
Returns the value of attribute extra.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def extra @extra end |
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def fingerprint @fingerprint end |
#id ⇒ Object Also known as: event_id
Returns the value of attribute id.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def id @id end |
#level ⇒ Object
Returns the value of attribute level.
19 20 21 |
# File 'lib/raven/event.rb', line 19 def level @level end |
#logger ⇒ Object
Returns the value of attribute logger.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def logger @logger end |
#modules ⇒ Object
Returns the value of attribute modules.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def modules @modules end |
#platform ⇒ Object
Returns the value of attribute platform.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def platform @platform end |
#release ⇒ Object
Returns the value of attribute release.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def release @release end |
#runtime ⇒ Object
Returns the value of attribute runtime.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def runtime @runtime end |
#sdk ⇒ Object
Returns the value of attribute sdk.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def sdk @sdk end |
#server_name ⇒ Object
Returns the value of attribute server_name.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def server_name @server_name end |
#server_os ⇒ Object
Returns the value of attribute server_os.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def server_os @server_os end |
#tags ⇒ Object
Returns the value of attribute tags.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def @tags end |
#time_spent ⇒ Object
Returns the value of attribute time_spent.
19 20 21 |
# File 'lib/raven/event.rb', line 19 def time_spent @time_spent end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
19 20 21 |
# File 'lib/raven/event.rb', line 19 def @timestamp end |
#transaction ⇒ Object
Returns the value of attribute transaction.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def transaction @transaction end |
#user ⇒ Object
Returns the value of attribute user.
13 14 15 |
# File 'lib/raven/event.rb', line 13 def user @user end |
Class Method Details
.from_exception(exc, options = {}, &block) ⇒ Object Also known as: captureException, capture_exception
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/raven/event.rb', line 48 def self.from_exception(exc, = {}, &block) exception_context = if exc.instance_variable_defined?(:@__raven_context) exc.instance_variable_get(:@__raven_context) elsif exc.respond_to?(:raven_context) exc.raven_context else {} end = Raven::Utils::DeepMergeHash.deep_merge(exception_context, ) configuration = [:configuration] || Raven.configuration return unless configuration.exception_class_allowed?(exc) new() do |evt| evt. = "#{exc.class}: #{exc.}" evt.add_exception_interface(exc) yield evt if block end end |
.from_message(message, options = {}) ⇒ Object Also known as: captureMessage, capture_message
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/raven/event.rb', line 70 def self.(, = {}) new() do |evt| evt. = , [:message_params] || [] if [:backtrace] evt.interface(:stacktrace) do |int| int.frames = evt.stacktrace_interface_from([:backtrace]) end end end end |
Instance Method Details
#[](key) ⇒ Object
112 113 114 |
# File 'lib/raven/event.rb', line 112 def [](key) interface(key) end |
#[]=(key, value) ⇒ Object
116 117 118 |
# File 'lib/raven/event.rb', line 116 def []=(key, value) interface(key, value) end |
#add_exception_interface(exc) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/raven/event.rb', line 140 def add_exception_interface(exc) interface(:exception) do |exc_int| exceptions = exception_chain_to_array(exc) backtraces = Set.new exc_int.values = exceptions.map do |e| SingleExceptionInterface.new do |int| int.type = e.class.to_s int.value = e.to_s int.module = e.class.to_s.split('::')[0...-1].join('::') int.stacktrace = if e.backtrace && !backtraces.include?(e.backtrace.object_id) backtraces << e.backtrace.object_id StacktraceInterface.new do |stacktrace| stacktrace.frames = stacktrace_interface_from(e.backtrace) end end end end end end |
#interface(name, value = nil, &block) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/raven/event.rb', line 105 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 |
#message ⇒ Object
81 82 83 |
# File 'lib/raven/event.rb', line 81 def @interfaces[:logentry] && @interfaces[:logentry]. end |
#message=(args) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/raven/event.rb', line 85 def (args) , params = *args interface(:message) do |int| int. = .byteslice(0...MAX_MESSAGE_SIZE_IN_BYTES) # Messages limited to 10kb int.params = params end end |
#stacktrace_interface_from(backtrace) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/raven/event.rb', line 162 def stacktrace_interface_from(backtrace) Backtrace.parse(backtrace).lines.reverse.each_with_object([]) do |line, memo| frame = StacktraceInterface::Frame.new frame.abs_path = line.file if line.file frame.function = line.method if line.method frame.lineno = line.number frame.in_app = line.in_app frame.module = line.module_name if line.module_name if configuration[:context_lines] && frame.abs_path frame.pre_context, frame.context_line, frame.post_context = \ configuration.linecache.get_file_context(frame.abs_path, frame.lineno, configuration[:context_lines]) end memo << frame if frame.filename end end |
#to_hash ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/raven/event.rb', line 120 def to_hash data = [:checksum, :environment, :event_id, :extra, :fingerprint, :level, :logger, :message, :modules, :platform, :release, :sdk, :server_name, :tags, :time_spent, :timestamp, :transaction, :user].each_with_object({}) do |att, memo| memo[att] = public_send(att) if public_send(att) end data[:breadcrumbs] = @breadcrumbs.to_hash unless @breadcrumbs.empty? @interfaces.each_pair do |name, int_data| data[name.to_sym] = int_data.to_hash end data end |
#to_json_compatible ⇒ Object
135 136 137 138 |
# File 'lib/raven/event.rb', line 135 def to_json_compatible cleaned_hash = async_json_processors.reduce(to_hash) { |a, e| e.process(a) } JSON.parse(JSON.generate(cleaned_hash)) end |