1717import io .sentry .util .Platform ;
1818import io .sentry .util .TracingUtils ;
1919import java .util .HashMap ;
20+ import java .util .Map ;
2021import org .jetbrains .annotations .ApiStatus ;
2122import org .jetbrains .annotations .NotNull ;
2223import org .jetbrains .annotations .Nullable ;
@@ -65,7 +66,7 @@ public void log(
6566 final @ NotNull SentryLogLevel level ,
6667 final @ Nullable String message ,
6768 final @ Nullable Object ... args ) {
68- log ( level , null , message , args );
69+ captureLog ( null , level , null , message , args );
6970 }
7071
7172 @ Override
@@ -74,11 +75,31 @@ public void log(
7475 final @ Nullable SentryDate timestamp ,
7576 final @ Nullable String message ,
7677 final @ Nullable Object ... args ) {
77- captureLog (level , timestamp , message , args );
78+ captureLog (null , level , timestamp , message , args );
79+ }
80+
81+ @ Override
82+ public void log (
83+ final @ Nullable Map <String , Object > attributes ,
84+ final @ NotNull SentryLogLevel level ,
85+ final @ Nullable SentryDate timestamp ,
86+ final @ Nullable String message ,
87+ final @ Nullable Object ... args ) {
88+ captureLog (attributes , level , timestamp , message , args );
89+ }
90+
91+ @ Override
92+ public void log (
93+ final @ Nullable Map <String , Object > attributes ,
94+ final @ NotNull SentryLogLevel level ,
95+ final @ Nullable String message ,
96+ final @ Nullable Object ... args ) {
97+ captureLog (attributes , level , null , message , args );
7898 }
7999
80100 @ SuppressWarnings ("AnnotateFormatMethod" )
81101 private void captureLog (
102+ final @ Nullable Map <String , Object > attributes ,
82103 final @ NotNull SentryLogLevel level ,
83104 final @ Nullable SentryDate timestamp ,
84105 final @ Nullable String message ,
@@ -119,7 +140,7 @@ private void captureLog(
119140 span == null ? propagationContext .getSpanId () : span .getSpanContext ().getSpanId ();
120141 final SentryLogEvent logEvent =
121142 new SentryLogEvent (traceId , timestampToUse , messageToUse , level );
122- logEvent .setAttributes (createAttributes (message , spanId , args ));
143+ logEvent .setAttributes (createAttributes (attributes , message , spanId , args ));
123144 logEvent .setSeverityNumber (level .getSeverityNumber ());
124145
125146 scopes .getClient ().captureLog (logEvent , combinedScope );
@@ -146,8 +167,20 @@ private void captureLog(
146167 }
147168
148169 private @ NotNull HashMap <String , SentryLogEventAttributeValue > createAttributes (
149- final @ NotNull String message , final @ NotNull SpanId spanId , final @ Nullable Object ... args ) {
170+ final @ Nullable Map <String , Object > incomingAttributes ,
171+ final @ NotNull String message ,
172+ final @ NotNull SpanId spanId ,
173+ final @ Nullable Object ... args ) {
150174 final @ NotNull HashMap <String , SentryLogEventAttributeValue > attributes = new HashMap <>();
175+
176+ if (incomingAttributes != null ) {
177+ for (Map .Entry <String , Object > attributeEntry : incomingAttributes .entrySet ()) {
178+ final @ Nullable Object value = attributeEntry .getValue ();
179+ final @ NotNull String type = getType (value );
180+ attributes .put (attributeEntry .getKey (), new SentryLogEventAttributeValue (type , value ));
181+ }
182+ }
183+
151184 if (args != null ) {
152185 int i = 0 ;
153186 for (Object arg : args ) {
0 commit comments