Class: Sentry::Event
Direct Known Subclasses
Constant Summary collapse
- ATTRIBUTES =
%i( event_id level timestamp release environment server_name modules message user tags contexts extra fingerprint breadcrumbs backtrace transaction platform sdk type )
- MAX_MESSAGE_SIZE_IN_BYTES =
1024 * 8
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#stacktrace ⇒ Object
readonly
Returns the value of attribute stacktrace.
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
Class Method Summary collapse
Instance Method Summary collapse
- #add_exception_interface(exc) ⇒ Object
- #add_request_interface(env) ⇒ Object
- #add_threads_interface(backtrace: nil, **options) ⇒ Object
-
#initialize(configuration:, integration_meta: nil, message: nil) ⇒ Event
constructor
A new instance of Event.
- #initialize_stacktrace_interface(backtrace) ⇒ Object
-
#level=(new_level) ⇒ Object
needed to meet the Sentry spec.
- #rack_env=(env) ⇒ Object
- #timestamp=(time) ⇒ Object
- #to_hash ⇒ Object
- #to_json_compatible ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(configuration:, integration_meta: nil, message: nil) ⇒ Event
Returns a new instance of Event.
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 |
# File 'lib/sentry/event.rb', line 25 def initialize(configuration:, integration_meta: nil, message: nil) # this needs to go first because some setters rely on configuration @configuration = configuration # Set some simple default values @event_id = SecureRandom.uuid.delete("-") @timestamp = Sentry.utc_now.iso8601 @platform = :ruby @sdk = || Sentry. @user = {} @extra = {} @contexts = {} @tags = {} @fingerprint = [] @server_name = configuration.server_name @environment = configuration.environment @release = configuration.release @modules = configuration.gem_specs if configuration.send_modules @message = ( || "").byteslice(0..MAX_MESSAGE_SIZE_IN_BYTES) self.level = :error end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
23 24 25 |
# File 'lib/sentry/event.rb', line 23 def configuration @configuration end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
23 24 25 |
# File 'lib/sentry/event.rb', line 23 def exception @exception end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
23 24 25 |
# File 'lib/sentry/event.rb', line 23 def request @request end |
#stacktrace ⇒ Object (readonly)
Returns the value of attribute stacktrace.
23 24 25 |
# File 'lib/sentry/event.rb', line 23 def stacktrace @stacktrace end |
#threads ⇒ Object (readonly)
Returns the value of attribute threads.
23 24 25 |
# File 'lib/sentry/event.rb', line 23 def threads @threads end |
Class Method Details
.get_log_message(event_hash) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/sentry/event.rb', line 53 def (event_hash) = event_hash[:message] || event_hash['message'] = (event_hash) if .nil? || .empty? = '<no message value>' if .nil? || .empty? end |
.get_message_from_exception(event_hash) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/sentry/event.rb', line 60 def (event_hash) ( event_hash && event_hash[:exception] && event_hash[:exception][:values] && event_hash[:exception][:values][0] && "#{event_hash[:exception][:values][0][:type]}: #{event_hash[:exception][:values][0][:value]}" ) end |
Instance Method Details
#add_exception_interface(exc) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/sentry/event.rb', line 123 def add_exception_interface(exc) if exc.respond_to?(:sentry_context) @extra.merge!(exc.sentry_context) end @exception = Sentry::ExceptionInterface.new.tap do |exc_int| exceptions = Sentry::Utils::ExceptionCauseChain.exception_to_array(exc).reverse backtraces = Set.new exc_int.values = exceptions.map do |e| SingleExceptionInterface.new.tap do |int| int.type = e.class.to_s int.value = e..byteslice(0..MAX_MESSAGE_SIZE_IN_BYTES) int.module = e.class.to_s.split('::')[0...-1].join('::') int.thread_id = Thread.current.object_id int.stacktrace = if e.backtrace && !backtraces.include?(e.backtrace.object_id) backtraces << e.backtrace.object_id initialize_stacktrace_interface(e.backtrace) end end end end end |
#add_request_interface(env) ⇒ Object
114 115 116 |
# File 'lib/sentry/event.rb', line 114 def add_request_interface(env) @request = Sentry::RequestInterface.from_rack(env) end |
#add_threads_interface(backtrace: nil, **options) ⇒ Object
118 119 120 121 |
# File 'lib/sentry/event.rb', line 118 def add_threads_interface(backtrace: nil, **) @threads = ThreadsInterface.new(**) @threads.stacktrace = initialize_stacktrace_interface(backtrace) if backtrace end |
#initialize_stacktrace_interface(backtrace) ⇒ Object
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/sentry/event.rb', line 148 def initialize_stacktrace_interface(backtrace) StacktraceInterface.new( backtrace: backtrace, project_root: configuration.project_root.to_s, app_dirs_pattern: configuration.app_dirs_pattern, linecache: configuration.linecache, context_lines: configuration.context_lines, backtrace_cleanup_callback: configuration.backtrace_cleanup_callback ) end |
#level=(new_level) ⇒ Object
needed to meet the Sentry spec
75 76 77 |
# File 'lib/sentry/event.rb', line 75 def level=(new_level) # needed to meet the Sentry spec @level = new_level.to_s == "warn" ? :warning : new_level end |
#rack_env=(env) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/sentry/event.rb', line 79 def rack_env=(env) unless request || env.empty? env = env.dup add_request_interface(env) if configuration.send_default_pii user[:ip_address] = calculate_real_ip_from_rack(env) end if request_id = Utils::RequestId.read_from(env) [:request_id] = request_id end end end |
#timestamp=(time) ⇒ Object
71 72 73 |
# File 'lib/sentry/event.rb', line 71 def (time) @timestamp = time.is_a?(Time) ? time.to_f : time end |
#to_hash ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/sentry/event.rb', line 99 def to_hash data = serialize_attributes data[:breadcrumbs] = .to_hash if data[:stacktrace] = stacktrace.to_hash if stacktrace data[:request] = request.to_hash if request data[:exception] = exception.to_hash if exception data[:threads] = threads.to_hash if threads data end |
#to_json_compatible ⇒ Object
110 111 112 |
# File 'lib/sentry/event.rb', line 110 def to_json_compatible JSON.parse(JSON.generate(to_hash)) end |
#type ⇒ Object
95 96 97 |
# File 'lib/sentry/event.rb', line 95 def type "event" end |