Class: Sentry::LogEvent

Inherits:
Object
  • Object
show all
Includes:
Utils::TelemetryAttributes
Defined in:
lib/sentry/log_event.rb

Overview

Event type that represents a log entry with its attributes

Constant Summary collapse

TYPE =
"log"
DEFAULT_PARAMETERS =
[].freeze
PARAMETER_PREFIX =
"sentry.message.parameter"
LEVELS =
%i[trace debug info warn error fatal].freeze
TOKEN_REGEXP =
/%\{(\w+)\}/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ LogEvent

Returns a new instance of LogEvent.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/sentry/log_event.rb', line 25

def initialize(**options)
  @type = TYPE
  @timestamp = Sentry.utc_now
  @level = options.fetch(:level)
  @body = options[:body]
  @template = @body if is_template?
  @attributes = options[:attributes] || {}
  @origin = options[:origin]
  @trace_id = nil
  @span_id = nil
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



20
21
22
# File 'lib/sentry/log_event.rb', line 20

def attributes
  @attributes
end

#bodyObject

Returns the value of attribute body.



20
21
22
# File 'lib/sentry/log_event.rb', line 20

def body
  @body
end

#levelObject

Returns the value of attribute level.



20
21
22
# File 'lib/sentry/log_event.rb', line 20

def level
  @level
end

#originObject

Returns the value of attribute origin.



20
21
22
# File 'lib/sentry/log_event.rb', line 20

def origin
  @origin
end

#span_idObject

Returns the value of attribute span_id.



20
21
22
# File 'lib/sentry/log_event.rb', line 20

def span_id
  @span_id
end

#templateObject

Returns the value of attribute template.



20
21
22
# File 'lib/sentry/log_event.rb', line 20

def template
  @template
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



21
22
23
# File 'lib/sentry/log_event.rb', line 21

def timestamp
  @timestamp
end

#trace_idObject

Returns the value of attribute trace_id.



20
21
22
# File 'lib/sentry/log_event.rb', line 20

def trace_id
  @trace_id
end

Instance Method Details

#to_hObject



37
38
39
40
41
42
43
44
45
46
# File 'lib/sentry/log_event.rb', line 37

def to_h
  {
    level: level.to_s,
    timestamp: timestamp.to_f,
    trace_id: @trace_id,
    span_id: @span_id,
    body: serialize_body,
    attributes: serialize_attributes
  }.compact
end