Class: Sentry::Event

Inherits:
Object
  • Object
show all
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

CheckInEvent, ErrorEvent, TransactionEvent

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

Instance Method Summary collapse

Constructor Details

#initialize(configuration:, integration_meta: nil, message: nil) ⇒ Event

Returns a new instance of Event.

Parameters:

  • configuration (Configuration)
  • integration_meta (Hash, nil) (defaults to: nil)
  • message (String, nil) (defaults to: nil)


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("-")
  @timestamp     = Sentry.utc_now.iso8601
  @platform      = :ruby
  @type          = self.class::TYPE
  @sdk           = integration_meta || Sentry.sdk_meta

  @user          = {}
  @extra         = {}
  @contexts      = {}
  @tags          = {}

  @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 = (message || "").byteslice(0..MAX_MESSAGE_SIZE_IN_BYTES)
end

Instance Attribute Details

#dynamic_sampling_contextHash?

Dynamic Sampling Context (DSC) that gets attached as the trace envelope header in the transport.

Returns:

  • (Hash, nil)


43
44
45
# File 'lib/sentry/event.rb', line 43

def dynamic_sampling_context
  @dynamic_sampling_context
end

#requestRequestInterface (readonly)

Returns:



38
39
40
# File 'lib/sentry/event.rb', line 38

def request
  @request
end

Instance Method Details

#configurationConfiguration

Deprecated.

This method will be removed in v5.0.0. Please just use Sentry.configuration

Returns:



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.

Parameters:

  • level (String, Symbol)


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.

Parameters:

  • env (Hash)

See Also:



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)
      tags[:request_id] = request_id
    end
  end
end

#timestamp=(time) ⇒ void

This method returns an undefined value.

Sets the event’s timestamp.

Parameters:

  • time (Time, Float)


88
89
90
# File 'lib/sentry/event.rb', line 88

def timestamp=(time)
  @timestamp = time.is_a?(Time) ? time.to_f : time
end

#to_hashHash

Returns:

  • (Hash)


116
117
118
119
120
121
# File 'lib/sentry/event.rb', line 116

def to_hash
  data = serialize_attributes
  data[:breadcrumbs] = breadcrumbs.to_hash if breadcrumbs
  data[:request] = request.to_hash if request
  data
end

#to_json_compatibleHash

Returns:

  • (Hash)


124
125
126
# File 'lib/sentry/event.rb', line 124

def to_json_compatible
  JSON.parse(JSON.generate(to_hash))
end