55import io .sentry .ISpan ;
66import io .sentry .PropagationContext ;
77import io .sentry .Scopes ;
8+ import io .sentry .SentryAttribute ;
9+ import io .sentry .SentryAttributeType ;
10+ import io .sentry .SentryAttributes ;
811import io .sentry .SentryDate ;
912import io .sentry .SentryLevel ;
1013import io .sentry .SentryLogEvent ;
1720import io .sentry .util .Platform ;
1821import io .sentry .util .TracingUtils ;
1922import java .util .HashMap ;
20- import java .util .Map ;
2123import org .jetbrains .annotations .ApiStatus ;
2224import org .jetbrains .annotations .NotNull ;
2325import org .jetbrains .annotations .Nullable ;
@@ -66,7 +68,7 @@ public void log(
6668 final @ NotNull SentryLogLevel level ,
6769 final @ Nullable String message ,
6870 final @ Nullable Object ... args ) {
69- captureLog (null , level , null , message , args );
71+ captureLog (level , SentryLogParameters . create ( null , null ) , message , args );
7072 }
7173
7274 @ Override
@@ -75,33 +77,22 @@ public void log(
7577 final @ Nullable SentryDate timestamp ,
7678 final @ Nullable String message ,
7779 final @ Nullable Object ... args ) {
78- captureLog (null , level , timestamp , message , args );
80+ captureLog (level , SentryLogParameters . create ( timestamp , null ) , message , args );
7981 }
8082
8183 @ Override
8284 public void log (
83- final @ Nullable Map <String , Object > attributes ,
8485 final @ NotNull SentryLogLevel level ,
85- final @ Nullable SentryDate timestamp ,
86+ final @ NotNull SentryLogParameters params ,
8687 final @ Nullable String message ,
8788 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 );
89+ captureLog (level , params , message , args );
9890 }
9991
10092 @ SuppressWarnings ("AnnotateFormatMethod" )
10193 private void captureLog (
102- final @ Nullable Map <String , Object > attributes ,
10394 final @ NotNull SentryLogLevel level ,
104- final @ Nullable SentryDate timestamp ,
95+ final @ NotNull SentryLogParameters params ,
10596 final @ Nullable String message ,
10697 final @ Nullable Object ... args ) {
10798 final @ NotNull SentryOptions options = scopes .getOptions ();
@@ -124,6 +115,7 @@ private void captureLog(
124115 return ;
125116 }
126117
118+ final @ Nullable SentryDate timestamp = params .getTimestamp ();
127119 final @ NotNull SentryDate timestampToUse =
128120 timestamp == null ? options .getDateProvider ().now () : timestamp ;
129121 final @ NotNull String messageToUse = maybeFormatMessage (message , args );
@@ -140,7 +132,7 @@ private void captureLog(
140132 span == null ? propagationContext .getSpanId () : span .getSpanContext ().getSpanId ();
141133 final SentryLogEvent logEvent =
142134 new SentryLogEvent (traceId , timestampToUse , messageToUse , level );
143- logEvent .setAttributes (createAttributes (attributes , message , spanId , args ));
135+ logEvent .setAttributes (createAttributes (params . getAttributes () , message , spanId , args ));
144136 logEvent .setSeverityNumber (level .getSeverityNumber ());
145137
146138 scopes .getClient ().captureLog (logEvent , combinedScope );
@@ -167,24 +159,25 @@ private void captureLog(
167159 }
168160
169161 private @ NotNull HashMap <String , SentryLogEventAttributeValue > createAttributes (
170- final @ Nullable Map < String , Object > incomingAttributes ,
162+ final @ Nullable SentryAttributes incomingAttributes ,
171163 final @ NotNull String message ,
172164 final @ NotNull SpanId spanId ,
173165 final @ Nullable Object ... args ) {
174166 final @ NotNull HashMap <String , SentryLogEventAttributeValue > attributes = new HashMap <>();
175167
176168 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 ));
169+ for (SentryAttribute attribute : incomingAttributes .getAttributes ().values ()) {
170+ final @ Nullable Object value = attribute .getValue ();
171+ final @ NotNull SentryAttributeType type =
172+ attribute .getType () == null ? getType (value ) : attribute .getType ();
173+ attributes .put (attribute .getName (), new SentryLogEventAttributeValue (type , value ));
181174 }
182175 }
183176
184177 if (args != null ) {
185178 int i = 0 ;
186179 for (Object arg : args ) {
187- final @ NotNull String type = getType (arg );
180+ final @ NotNull SentryAttributeType type = getType (arg );
188181 attributes .put (
189182 "sentry.message.parameter." + i , new SentryLogEventAttributeValue (type , arg ));
190183 i ++;
@@ -238,16 +231,16 @@ private void setServerName(
238231 }
239232 }
240233
241- private @ NotNull String getType (final @ Nullable Object arg ) {
234+ private @ NotNull SentryAttributeType getType (final @ Nullable Object arg ) {
242235 if (arg instanceof Boolean ) {
243- return "boolean" ;
236+ return SentryAttributeType . BOOLEAN ;
244237 }
245238 if (arg instanceof Integer ) {
246- return "integer" ;
239+ return SentryAttributeType . INTEGER ;
247240 }
248241 if (arg instanceof Number ) {
249- return "double" ;
242+ return SentryAttributeType . DOUBLE ;
250243 }
251- return "string" ;
244+ return SentryAttributeType . STRING ;
252245 }
253246}
0 commit comments