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.
-
#threads ⇒ Object
readonly
Returns the value of attribute threads.
Class Method Summary collapse
Instance Method Summary collapse
- #add_exception_interface(exception) ⇒ 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.
-
#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 |
#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 59 60 61 62 63 64 65 66 67 |
# File 'lib/sentry/event.rb', line 53 def (event_hash) = event_hash[:message] || event_hash['message'] return unless .nil? || .empty? = (event_hash) return unless .nil? || .empty? = event_hash[:transaction] || event_hash["transaction"] return unless .nil? || .empty? '<no message value>' end |
.get_message_from_exception(event_hash) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/sentry/event.rb', line 69 def (event_hash) if exception = event_hash.dig(:exception, :values, 0) "#{exception[:type]}: #{exception[:value]}" elsif exception = event_hash.dig("exception", "values", 0) "#{exception["type"]}: #{exception["value"]}" end end |
Instance Method Details
#add_exception_interface(exception) ⇒ Object
132 133 134 135 136 137 138 |
# File 'lib/sentry/event.rb', line 132 def add_exception_interface(exception) if exception.respond_to?(:sentry_context) @extra.merge!(exception.sentry_context) end @exception = Sentry::ExceptionInterface.build(exception: exception, stacktrace_builder: configuration.stacktrace_builder) end |
#add_request_interface(env) ⇒ Object
120 121 122 |
# File 'lib/sentry/event.rb', line 120 def add_request_interface(env) @request = Sentry::RequestInterface.build(env: env) end |
#add_threads_interface(backtrace: nil, **options) ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/sentry/event.rb', line 124 def add_threads_interface(backtrace: nil, **) @threads = ThreadsInterface.build( backtrace: backtrace, stacktrace_builder: configuration.stacktrace_builder, ** ) end |
#level=(new_level) ⇒ Object
needed to meet the Sentry spec
82 83 84 |
# File 'lib/sentry/event.rb', line 82 def level=(new_level) # needed to meet the Sentry spec @level = new_level.to_s == "warn" ? :warning : new_level end |
#rack_env=(env) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/sentry/event.rb', line 86 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
78 79 80 |
# File 'lib/sentry/event.rb', line 78 def (time) @timestamp = time.is_a?(Time) ? time.to_f : time end |
#to_hash ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/sentry/event.rb', line 106 def to_hash data = serialize_attributes data[:breadcrumbs] = .to_hash if 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
116 117 118 |
# File 'lib/sentry/event.rb', line 116 def to_json_compatible JSON.parse(JSON.generate(to_hash)) end |
#type ⇒ Object
102 103 104 |
# File 'lib/sentry/event.rb', line 102 def type "event" end |