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.
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 82 |
# File 'lib/sentry/event.rb', line 52 def initialize(configuration:, integration_meta: nil, message: nil) # Set some simple default values @event_id = Utils.uuid @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>
47 48 49 |
# File 'lib/sentry/event.rb', line 47 def @attachments end |
#dynamic_sampling_context ⇒ Hash?
Dynamic Sampling Context (DSC) that gets attached as the trace envelope header in the transport.
44 45 46 |
# File 'lib/sentry/event.rb', line 44 def dynamic_sampling_context @dynamic_sampling_context end |
#request ⇒ RequestInterface (readonly)
39 40 41 |
# File 'lib/sentry/event.rb', line 39 def request @request end |
Instance Method Details
#configuration ⇒ Configuration
This method will be removed in v5.0.0. Please just use Sentry.configuration
86 87 88 |
# File 'lib/sentry/event.rb', line 86 def configuration Sentry.configuration end |
#level=(level) ⇒ void
This method returns an undefined value.
Sets the event’s level.
100 101 102 |
# File 'lib/sentry/event.rb', line 100 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.
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/sentry/event.rb', line 108 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.
93 94 95 |
# File 'lib/sentry/event.rb', line 93 def (time) @timestamp = time.is_a?(Time) ? time.to_f : time end |
#to_hash ⇒ Hash
121 122 123 124 125 126 |
# File 'lib/sentry/event.rb', line 121 def to_hash data = serialize_attributes data[:breadcrumbs] = .to_hash if data[:request] = request.to_hash if request data end |
#to_json_compatible ⇒ Hash
129 130 131 |
# File 'lib/sentry/event.rb', line 129 def to_json_compatible JSON.parse(JSON.generate(to_hash)) end |