Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions sentry-ruby/lib/sentry/log_event.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "json"

module Sentry
# Event type that represents a log entry with its attributes
#
Expand Down Expand Up @@ -62,13 +64,6 @@ class LogEvent
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+)\}/

def initialize(configuration: Sentry.configuration, **options)
Expand Down Expand Up @@ -178,11 +173,22 @@ def serialize_attributes
end

def attribute_hash(value)
{ value: value, type: value_type(value) }
end

def value_type(value)
VALUE_TYPES[value.class]
case value
when String
{ value: value, type: "string" }
when TrueClass, FalseClass
{ value: value, type: "boolean" }
when Integer
{ value: value, type: "integer" }
when Float
{ value: value, type: "double" }
else
begin
{ value: JSON.generate(value), type: "string" }
rescue
{ value: value, type: "string" }
end
end
end

def parameters
Expand Down
Loading