class Sentry::Event
Constants
- MAX_MESSAGE_SIZE_IN_BYTES
- SERIALIZEABLE_ATTRIBUTES
- WRITER_ATTRIBUTES
Attributes
configuration[R]
exception[R]
request[R]
threads[R]
Public Class Methods
get_log_message(event_hash)
click to toggle source
# File lib/sentry/event.rb, line 57 def get_log_message(event_hash) message = event_hash[:message] || event_hash['message'] return message unless message.nil? || message.empty? message = get_message_from_exception(event_hash) return message unless message.nil? || message.empty? message = event_hash[:transaction] || event_hash["transaction"] return message unless message.nil? || message.empty? '<no message value>' end
get_message_from_exception(event_hash)
click to toggle source
# File lib/sentry/event.rb, line 73 def get_message_from_exception(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
new(configuration:, integration_meta: nil, message: nil)
click to toggle source
# File lib/sentry/event.rb, line 29 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 = integration_meta || Sentry.sdk_meta @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 = (message || "").byteslice(0..MAX_MESSAGE_SIZE_IN_BYTES) self.level = :error end
Public Instance Methods
add_exception_interface(exception)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/sentry/event.rb, line 124 def add_threads_interface(backtrace: nil, **options) @threads = ThreadsInterface.build( backtrace: backtrace, stacktrace_builder: configuration.stacktrace_builder, **options ) end
level=(new_level)
click to toggle source
# File lib/sentry/event.rb, line 86 def level=(new_level) # needed to meet the Sentry spec @level = new_level.to_s == "warn" ? :warning : new_level end
rack_env=(env)
click to toggle source
# File lib/sentry/event.rb, line 90 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) tags[:request_id] = request_id end end end
timestamp=(time)
click to toggle source
# File lib/sentry/event.rb, line 82 def timestamp=(time) @timestamp = time.is_a?(Time) ? time.to_f : time end
to_hash()
click to toggle source
# File lib/sentry/event.rb, line 106 def to_hash data = serialize_attributes data[:breadcrumbs] = breadcrumbs.to_hash if breadcrumbs 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()
click to toggle source
# File lib/sentry/event.rb, line 116 def to_json_compatible JSON.parse(JSON.generate(to_hash)) end
Private Instance Methods
calculate_real_ip_from_rack(env)
click to toggle source
When behind a proxy (or if the user is using a proxy), we can't use REMOTE_ADDR to determine the Event
IP, and must use other headers instead.
# File lib/sentry/event.rb, line 152 def calculate_real_ip_from_rack(env) Utils::RealIp.new( :remote_addr => env["REMOTE_ADDR"], :client_ip => env["HTTP_CLIENT_IP"], :real_ip => env["HTTP_X_REAL_IP"], :forwarded_for => env["HTTP_X_FORWARDED_FOR"], :trusted_proxies => configuration.trusted_proxies ).calculate_ip end
serialize_attributes()
click to toggle source
# File lib/sentry/event.rb, line 142 def serialize_attributes self.class::SERIALIZEABLE_ATTRIBUTES.each_with_object({}) do |att, memo| if value = public_send(att) memo[att] = value end end end