@@ -32,9 +32,15 @@ class LogEvent
3232 "sentry.message.template" => :template
3333 }
3434
35+ USER_ATTRIBUTES = {
36+ "user.id" => :user_id ,
37+ "user.name" => :user_username ,
38+ "user.email" => :user_email
39+ }
40+
3541 LEVELS = %i[ trace debug info warn error fatal ] . freeze
3642
37- attr_accessor :level , :body , :template , :attributes
43+ attr_accessor :level , :body , :template , :attributes , :user
3844
3945 attr_reader :configuration , *SERIALIZEABLE_ATTRIBUTES
4046
@@ -47,6 +53,9 @@ class LogEvent
4753 sdk_version
4854 timestamp
4955 trace_id
56+ user_id
57+ user_username
58+ user_email
5059 ] . map { |name | [ name , :"serialize_#{ name } " ] } . to_h
5160
5261 VALUE_TYPES = Hash . new ( "string" ) . merge! ( {
@@ -69,6 +78,7 @@ def initialize(configuration: Sentry.configuration, **options)
6978 @body = options [ :body ]
7079 @template = @body if is_template?
7180 @attributes = options [ :attributes ] || DEFAULT_ATTRIBUTES
81+ @user = options [ :user ] || { }
7282 @contexts = { }
7383 end
7484
@@ -124,6 +134,18 @@ def serialize_body
124134 end
125135 end
126136
137+ def serialize_user_id
138+ user [ :id ]
139+ end
140+
141+ def serialize_user_username
142+ user [ :username ]
143+ end
144+
145+ def serialize_user_email
146+ user [ :email ]
147+ end
148+
127149 def serialize_attributes
128150 hash = { }
129151
@@ -137,6 +159,12 @@ def serialize_attributes
137159 end
138160 end
139161
162+ USER_ATTRIBUTES . each do |key , name |
163+ if ( value = serialize ( name ) )
164+ hash [ key ] = value
165+ end
166+ end
167+
140168 hash
141169 end
142170
0 commit comments