Class: Sentry::Event
- Inherits:
-
Object
- Object
- Sentry::Event
- Includes:
- CustomInspection
- Defined in:
- lib/sentry/event.rb
Overview
This is an abstract class that defines the shared attributes of an event. Please don’t use it directly. The user-facing classes are its child classes.
Direct Known Subclasses
Constant Summary collapse
- TYPE =
"event"- SERIALIZEABLE_ATTRIBUTES =
These are readable attributes.
i[ event_id level release environment server_name modules user contexts extra fingerprint transaction transaction_info platform sdk type ]
- WRITER_ATTRIBUTES =
These are writable attributes.
SERIALIZEABLE_ATTRIBUTES - i[type level]
- MAX_MESSAGE_SIZE_IN_BYTES =
1024 * 8
- SKIP_INSPECTION_ATTRIBUTES =
[:@modules, :@stacktrace_builder, :@send_default_pii, :@trusted_proxies, :@rack_env_whitelist]
Instance Attribute Summary collapse
-
#dynamic_sampling_context ⇒ Hash?
Dynamic Sampling Context (DSC) that gets attached as the trace envelope header in the transport.
- #request ⇒ RequestInterface readonly
Instance Method Summary collapse
-
#configuration ⇒ Configuration
deprecated
Deprecated.
This method will be removed in v5.0.0. Please just use Sentry.configuration
-
#initialize(configuration:, integration_meta: nil, message: nil) ⇒ Event
constructor
A new instance of Event.
-
#level=(level) ⇒ void
Sets the event’s level.
-
#rack_env=(env) ⇒ void
Sets the event’s request environment data with RequestInterface.
-
#timestamp=(time) ⇒ void
Sets the event’s timestamp.
- #to_hash ⇒ Hash
- #to_json_compatible ⇒ Hash
Constructor Details
#initialize(configuration:, integration_meta: nil, message: nil) ⇒ Event
Returns a new instance of Event.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/sentry/event.rb', line 48 def initialize(configuration:, integration_meta: nil, message: nil) # Set some simple default values @event_id = SecureRandom.uuid.delete("-") = Sentry.utc_now.iso8601 @platform = :ruby @type = self.class::TYPE @sdk = || Sentry. @user = {} @extra = {} @contexts = {} = {} @fingerprint = [] @dynamic_sampling_context = nil # configuration data that's directly used by events @server_name = configuration.server_name @environment = configuration.environment @release = configuration.release @modules = configuration.gem_specs if configuration.send_modules # configuration options to help events process data @send_default_pii = configuration.send_default_pii @trusted_proxies = configuration.trusted_proxies @stacktrace_builder = configuration.stacktrace_builder @rack_env_whitelist = configuration.rack_env_whitelist = ( || "").byteslice(0..MAX_MESSAGE_SIZE_IN_BYTES) end |
Instance Attribute Details
#dynamic_sampling_context ⇒ Hash?
Dynamic Sampling Context (DSC) that gets attached as the trace envelope header in the transport.
43 44 45 |
# File 'lib/sentry/event.rb', line 43 def dynamic_sampling_context @dynamic_sampling_context end |
#request ⇒ RequestInterface (readonly)
38 39 40 |
# File 'lib/sentry/event.rb', line 38 def request @request end |
Instance Method Details
#configuration ⇒ Configuration
This method will be removed in v5.0.0. Please just use Sentry.configuration
81 82 83 |
# File 'lib/sentry/event.rb', line 81 def configuration Sentry.configuration end |
#level=(level) ⇒ void
This method returns an undefined value.
Sets the event’s level.
95 96 97 |
# File 'lib/sentry/event.rb', line 95 def level=(level) # needed to meet the Sentry spec @level = level.to_s == "warn" ? :warning : level end |
#rack_env=(env) ⇒ void
This method returns an undefined value.
Sets the event’s request environment data with RequestInterface.
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/sentry/event.rb', line 103 def rack_env=(env) unless request || env.empty? add_request_interface(env) user[:ip_address] ||= calculate_real_ip_from_rack(env) if @send_default_pii if request_id = Utils::RequestId.read_from(env) [:request_id] = request_id end end end |
#timestamp=(time) ⇒ void
This method returns an undefined value.
Sets the event’s timestamp.
88 89 90 |
# File 'lib/sentry/event.rb', line 88 def (time) = time.is_a?(Time) ? time.to_f : time end |
#to_hash ⇒ Hash
116 117 118 119 120 121 |
# File 'lib/sentry/event.rb', line 116 def to_hash data = serialize_attributes data[:breadcrumbs] = .to_hash if data[:request] = request.to_hash if request data end |
#to_json_compatible ⇒ Hash
124 125 126 |
# File 'lib/sentry/event.rb', line 124 def to_json_compatible JSON.parse(JSON.generate(to_hash)) end |