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 timestamp release environment server_name modules message user tags contexts extra fingerprint breadcrumbs transaction transaction_info platform sdk type ]
- WRITER_ATTRIBUTES =
These are writable attributes.
SERIALIZEABLE_ATTRIBUTES - %i[type timestamp 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
- #attachments ⇒ Array<Attachment>
-
#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.
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 78 79 80 81 |
# File 'lib/sentry/event.rb', line 51 def initialize(configuration:, integration_meta: nil, message: nil) # Set some simple default values @event_id = SecureRandom.uuid.delete("-") @timestamp = Sentry.utc_now.iso8601 @platform = :ruby @type = self.class::TYPE @sdk = || Sentry. @user = {} @extra = {} @contexts = {} @tags = {} @attachments = [] @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 @message = ( || "").byteslice(0..MAX_MESSAGE_SIZE_IN_BYTES) end |
Instance Attribute Details
#attachments ⇒ Array<Attachment>
46 47 48 |
# File 'lib/sentry/event.rb', line 46 def @attachments end |
#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
85 86 87 |
# File 'lib/sentry/event.rb', line 85 def configuration Sentry.configuration end |
#level=(level) ⇒ void
This method returns an undefined value.
Sets the event’s level.
99 100 101 |
# File 'lib/sentry/event.rb', line 99 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.
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/sentry/event.rb', line 107 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.
92 93 94 |
# File 'lib/sentry/event.rb', line 92 def (time) @timestamp = time.is_a?(Time) ? time.to_f : time end |
#to_hash ⇒ Hash
120 121 122 123 124 125 |
# File 'lib/sentry/event.rb', line 120 def to_hash data = serialize_attributes data[:breadcrumbs] = .to_hash if data[:request] = request.to_hash if request data end |
#to_json_compatible ⇒ Hash
128 129 130 |
# File 'lib/sentry/event.rb', line 128 def to_json_compatible JSON.parse(JSON.generate(to_hash)) end |