Class: Raven::Event
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
- REQUIRED_OPTION_KEYS =
[:configuration, :context, :breadcrumbs].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.
-
#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(options) {|_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(options) {|_self| ... } ⇒ Event
Returns a new instance of Event.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/raven/event.rb', line 23 def initialize() # 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 unless REQUIRED_OPTION_KEYS.all? { |key| .key?(key) } raise "you must provide configuration, context, and breadcrumbs when initializing a Raven::Event" end self.configuration = [:configuration] self.context = [:context] self. = [:breadcrumbs] # Allow attributes to be set on the event at initialization yield self if block_given? .each_pair { |key, val| public_send("#{key}=", val) unless val.nil? } set_core_attributes_from_configuration set_core_attributes_from_context end |
Instance Attribute Details
#backtrace ⇒ Object
Returns the value of attribute backtrace.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def backtrace @backtrace end |
#breadcrumbs ⇒ Object
Returns the value of attribute breadcrumbs.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def @breadcrumbs end |
#checksum ⇒ Object
Returns the value of attribute checksum.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def checksum @checksum end |
#configuration ⇒ Object
Returns the value of attribute configuration.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def configuration @configuration end |
#context ⇒ Object
Returns the value of attribute context.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def context @context end |
#environment ⇒ Object
Returns the value of attribute environment.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def environment @environment end |
#extra ⇒ Object
Returns the value of attribute extra.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def extra @extra end |
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def fingerprint @fingerprint end |
#id ⇒ Object Also known as: event_id
Returns the value of attribute id.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def id @id end |
#level ⇒ Object
Returns the value of attribute level.
21 22 23 |
# File 'lib/raven/event.rb', line 21 def level @level end |
#logger ⇒ Object
Returns the value of attribute logger.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def logger @logger end |
#modules ⇒ Object
Returns the value of attribute modules.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def modules @modules end |
#platform ⇒ Object
Returns the value of attribute platform.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def platform @platform end |
#release ⇒ Object
Returns the value of attribute release.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def release @release end |
#runtime ⇒ Object
Returns the value of attribute runtime.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def runtime @runtime end |
#sdk ⇒ Object
Returns the value of attribute sdk.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def sdk @sdk end |
#server_name ⇒ Object
Returns the value of attribute server_name.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def server_name @server_name end |
#server_os ⇒ Object
Returns the value of attribute server_os.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def server_os @server_os end |
#tags ⇒ Object
Returns the value of attribute tags.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def @tags end |
#time_spent ⇒ Object
Returns the value of attribute time_spent.
21 22 23 |
# File 'lib/raven/event.rb', line 21 def time_spent @time_spent end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
21 22 23 |
# File 'lib/raven/event.rb', line 21 def @timestamp end |
#transaction ⇒ Object
Returns the value of attribute transaction.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def transaction @transaction end |
#user ⇒ Object
Returns the value of attribute user.
15 16 17 |
# File 'lib/raven/event.rb', line 15 def user @user end |
Class Method Details
.from_exception(exc, options = {}, &block) ⇒ Object Also known as: captureException, capture_exception
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/raven/event.rb', line 56 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, ) return unless [:configuration].exception_class_allowed?(exc) new() do |evt| evt.add_exception_interface(exc) yield evt if block end end |
.from_message(message, options = {}) ⇒ Object Also known as: captureMessage, capture_message
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/raven/event.rb', line 74 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
127 128 129 |
# File 'lib/raven/event.rb', line 127 def [](key) interface(key) end |
#[]=(key, value) ⇒ Object
131 132 133 |
# File 'lib/raven/event.rb', line 131 def []=(key, value) interface(key, value) end |
#add_exception_interface(exc) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/raven/event.rb', line 155 def add_exception_interface(exc) interface(:exception) do |exc_int| exceptions = Raven::Utils::ExceptionCauseChain.exception_to_array(exc).reverse 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
119 120 121 122 123 124 125 |
# File 'lib/raven/event.rb', line 119 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
85 86 87 |
# File 'lib/raven/event.rb', line 85 def @interfaces[:logentry]&. end |
#message=(args) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/raven/event.rb', line 89 def (args) if args.is_a?(Array) , params = args[0], args[0..-1] else = args end unless .is_a?(String) configuration.logger.debug("You're passing a non-string message") = .to_s end 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
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/raven/event.rb', line 177 def stacktrace_interface_from(backtrace) Backtrace.parse(backtrace, { configuration: configuration }).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
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/raven/event.rb', line 135 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
150 151 152 153 |
# File 'lib/raven/event.rb', line 150 def to_json_compatible cleaned_hash = async_json_processors.reduce(to_hash) { |a, e| e.process(a) } JSON.parse(JSON.generate(cleaned_hash)) end |