1717import io .sentry .SpanId ;
1818import io .sentry .protocol .SdkVersion ;
1919import io .sentry .protocol .SentryId ;
20+ import io .sentry .protocol .User ;
2021import io .sentry .util .Platform ;
2122import io .sentry .util .TracingUtils ;
2223import java .util .HashMap ;
@@ -184,35 +185,43 @@ private void captureLog(
184185 }
185186 if (i > 0 ) {
186187 attributes .put (
187- "sentry.message.template" , new SentryLogEventAttributeValue ("string" , message ));
188+ "sentry.message.template" ,
189+ new SentryLogEventAttributeValue (SentryAttributeType .STRING , message ));
188190 }
189191 }
190192
191193 final @ Nullable SdkVersion sdkVersion = scopes .getOptions ().getSdkVersion ();
192194 if (sdkVersion != null ) {
193195 attributes .put (
194- "sentry.sdk.name" , new SentryLogEventAttributeValue ("string" , sdkVersion .getName ()));
196+ "sentry.sdk.name" ,
197+ new SentryLogEventAttributeValue (SentryAttributeType .STRING , sdkVersion .getName ()));
195198 attributes .put (
196199 "sentry.sdk.version" ,
197- new SentryLogEventAttributeValue ("string" , sdkVersion .getVersion ()));
200+ new SentryLogEventAttributeValue (SentryAttributeType . STRING , sdkVersion .getVersion ()));
198201 }
199202
200203 final @ Nullable String environment = scopes .getOptions ().getEnvironment ();
201204 if (environment != null ) {
202- attributes .put ("sentry.environment" , new SentryLogEventAttributeValue ("string" , environment ));
205+ attributes .put (
206+ "sentry.environment" ,
207+ new SentryLogEventAttributeValue (SentryAttributeType .STRING , environment ));
203208 }
204209 final @ Nullable String release = scopes .getOptions ().getRelease ();
205210 if (release != null ) {
206- attributes .put ("sentry.release" , new SentryLogEventAttributeValue ("string" , release ));
211+ attributes .put (
212+ "sentry.release" , new SentryLogEventAttributeValue (SentryAttributeType .STRING , release ));
207213 }
208214
209215 attributes .put (
210- "sentry.trace.parent_span_id" , new SentryLogEventAttributeValue ("string" , spanId ));
216+ "sentry.trace.parent_span_id" ,
217+ new SentryLogEventAttributeValue (SentryAttributeType .STRING , spanId ));
211218
212219 if (Platform .isJvm ()) {
213220 setServerName (attributes );
214221 }
215222
223+ setUser (attributes );
224+
216225 return attributes ;
217226 }
218227
@@ -222,11 +231,34 @@ private void setServerName(
222231 final @ Nullable String optionsServerName = options .getServerName ();
223232 if (optionsServerName != null ) {
224233 attributes .put (
225- "server.address" , new SentryLogEventAttributeValue ("string" , optionsServerName ));
234+ "server.address" ,
235+ new SentryLogEventAttributeValue (SentryAttributeType .STRING , optionsServerName ));
226236 } else if (options .isAttachServerName ()) {
227237 final @ Nullable String hostname = HostnameCache .getInstance ().getHostname ();
228238 if (hostname != null ) {
229- attributes .put ("server.address" , new SentryLogEventAttributeValue ("string" , hostname ));
239+ attributes .put (
240+ "server.address" ,
241+ new SentryLogEventAttributeValue (SentryAttributeType .STRING , hostname ));
242+ }
243+ }
244+ }
245+
246+ private void setUser (final @ NotNull HashMap <String , SentryLogEventAttributeValue > attributes ) {
247+ final @ Nullable User user = scopes .getCombinedScopeView ().getUser ();
248+ if (user != null ) {
249+ final @ Nullable String id = user .getId ();
250+ if (id != null ) {
251+ attributes .put ("user.id" , new SentryLogEventAttributeValue (SentryAttributeType .STRING , id ));
252+ }
253+ final @ Nullable String username = user .getUsername ();
254+ if (username != null ) {
255+ attributes .put (
256+ "user.name" , new SentryLogEventAttributeValue (SentryAttributeType .STRING , username ));
257+ }
258+ final @ Nullable String email = user .getEmail ();
259+ if (email != null ) {
260+ attributes .put (
261+ "user.email" , new SentryLogEventAttributeValue (SentryAttributeType .STRING , email ));
230262 }
231263 }
232264 }
0 commit comments