Class: Sentry::LogEvent

Inherits:
Object
  • Object
show all
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
DEFAULT_ATTRIBUTES =
{}.freeze
SERIALIZEABLE_ATTRIBUTES =
%i[
  level
  body
  timestamp
  environment
  release
  server_name
  trace_id
  attributes
  contexts
]
SENTRY_ATTRIBUTES =
{
  "sentry.trace.parent_span_id" => :parent_span_id,
  "sentry.environment" => :environment,
  "sentry.release" => :release,
  "sentry.address" => :server_name,
  "sentry.sdk.name" => :sdk_name,
  "sentry.sdk.version" => :sdk_version,
  "sentry.message.template" => :template
}
USER_ATTRIBUTES =
{
  "user.id" => :user_id,
  "user.name" => :user_username,
  "user.email" => :user_email
}
LEVELS =
%i[trace debug info warn error fatal].freeze
SERIALIZERS =
%i[
  attributes
  body
  level
  parent_span_id
  sdk_name
  sdk_version
  timestamp
  trace_id
  user_id
  user_username
  user_email
].map { |name| [name, :"serialize_#{name}"] }.to_h
VALUE_TYPES =
Hash.new("string").merge!({
  TrueClass => "boolean",
  FalseClass => "boolean",
  Integer => "integer",
  Float => "double"
}).freeze
TOKEN_REGEXP =
/%\{(\w+)\}/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration: Sentry.configuration, **options) ⇒ LogEvent

Returns a new instance of LogEvent.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/sentry/log_event.rb', line 70

def initialize(configuration: Sentry.configuration, **options)
  @configuration = configuration
  @type = TYPE
  @server_name = configuration.server_name
  @environment = configuration.environment
  @release = configuration.release
  @timestamp = Sentry.utc_now
  @level = options.fetch(:level)
  @body = options[:body]
  @template = @body if is_template?
  @attributes = options[:attributes] || DEFAULT_ATTRIBUTES
  @user = options[:user] || {}
  @contexts = {}
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



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

def attributes
  @attributes
end

#bodyObject

Returns the value of attribute body.



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

def body
  @body
end

#levelObject

Returns the value of attribute level.



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

def level
  @level
end

#templateObject

Returns the value of attribute template.



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

def template
  @template
end

#userObject

Returns the value of attribute user.



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

def user
  @user
end

Instance Method Details

#to_hashObject



85
86
87
88
89
# File 'lib/sentry/log_event.rb', line 85

def to_hash
  SERIALIZEABLE_ATTRIBUTES.each_with_object({}) do |name, memo|
    memo[name] = serialize(name)
  end
end