5
5
import io .sentry .ISpan ;
6
6
import io .sentry .PropagationContext ;
7
7
import io .sentry .Scopes ;
8
+ import io .sentry .SentryAttribute ;
9
+ import io .sentry .SentryAttributeType ;
10
+ import io .sentry .SentryAttributes ;
8
11
import io .sentry .SentryDate ;
9
12
import io .sentry .SentryLevel ;
10
13
import io .sentry .SentryLogEvent ;
17
20
import io .sentry .util .Platform ;
18
21
import io .sentry .util .TracingUtils ;
19
22
import java .util .HashMap ;
20
- import java .util .Map ;
21
23
import org .jetbrains .annotations .ApiStatus ;
22
24
import org .jetbrains .annotations .NotNull ;
23
25
import org .jetbrains .annotations .Nullable ;
@@ -66,7 +68,7 @@ public void log(
66
68
final @ NotNull SentryLogLevel level ,
67
69
final @ Nullable String message ,
68
70
final @ Nullable Object ... args ) {
69
- captureLog (null , level , null , message , args );
71
+ captureLog (level , SentryLogParameters . create ( null , null ) , message , args );
70
72
}
71
73
72
74
@ Override
@@ -75,33 +77,22 @@ public void log(
75
77
final @ Nullable SentryDate timestamp ,
76
78
final @ Nullable String message ,
77
79
final @ Nullable Object ... args ) {
78
- captureLog (null , level , timestamp , message , args );
80
+ captureLog (level , SentryLogParameters . create ( timestamp , null ) , message , args );
79
81
}
80
82
81
83
@ Override
82
84
public void log (
83
- final @ Nullable Map <String , Object > attributes ,
84
85
final @ NotNull SentryLogLevel level ,
85
- final @ Nullable SentryDate timestamp ,
86
+ final @ NotNull SentryLogParameters params ,
86
87
final @ Nullable String message ,
87
88
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 );
98
90
}
99
91
100
92
@ SuppressWarnings ("AnnotateFormatMethod" )
101
93
private void captureLog (
102
- final @ Nullable Map <String , Object > attributes ,
103
94
final @ NotNull SentryLogLevel level ,
104
- final @ Nullable SentryDate timestamp ,
95
+ final @ NotNull SentryLogParameters params ,
105
96
final @ Nullable String message ,
106
97
final @ Nullable Object ... args ) {
107
98
final @ NotNull SentryOptions options = scopes .getOptions ();
@@ -124,6 +115,7 @@ private void captureLog(
124
115
return ;
125
116
}
126
117
118
+ final @ Nullable SentryDate timestamp = params .getTimestamp ();
127
119
final @ NotNull SentryDate timestampToUse =
128
120
timestamp == null ? options .getDateProvider ().now () : timestamp ;
129
121
final @ NotNull String messageToUse = maybeFormatMessage (message , args );
@@ -140,7 +132,7 @@ private void captureLog(
140
132
span == null ? propagationContext .getSpanId () : span .getSpanContext ().getSpanId ();
141
133
final SentryLogEvent logEvent =
142
134
new SentryLogEvent (traceId , timestampToUse , messageToUse , level );
143
- logEvent .setAttributes (createAttributes (attributes , message , spanId , args ));
135
+ logEvent .setAttributes (createAttributes (params . getAttributes () , message , spanId , args ));
144
136
logEvent .setSeverityNumber (level .getSeverityNumber ());
145
137
146
138
scopes .getClient ().captureLog (logEvent , combinedScope );
@@ -167,24 +159,25 @@ private void captureLog(
167
159
}
168
160
169
161
private @ NotNull HashMap <String , SentryLogEventAttributeValue > createAttributes (
170
- final @ Nullable Map < String , Object > incomingAttributes ,
162
+ final @ Nullable SentryAttributes incomingAttributes ,
171
163
final @ NotNull String message ,
172
164
final @ NotNull SpanId spanId ,
173
165
final @ Nullable Object ... args ) {
174
166
final @ NotNull HashMap <String , SentryLogEventAttributeValue > attributes = new HashMap <>();
175
167
176
168
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 ));
181
174
}
182
175
}
183
176
184
177
if (args != null ) {
185
178
int i = 0 ;
186
179
for (Object arg : args ) {
187
- final @ NotNull String type = getType (arg );
180
+ final @ NotNull SentryAttributeType type = getType (arg );
188
181
attributes .put (
189
182
"sentry.message.parameter." + i , new SentryLogEventAttributeValue (type , arg ));
190
183
i ++;
@@ -238,16 +231,16 @@ private void setServerName(
238
231
}
239
232
}
240
233
241
- private @ NotNull String getType (final @ Nullable Object arg ) {
234
+ private @ NotNull SentryAttributeType getType (final @ Nullable Object arg ) {
242
235
if (arg instanceof Boolean ) {
243
- return "boolean" ;
236
+ return SentryAttributeType . BOOLEAN ;
244
237
}
245
238
if (arg instanceof Integer ) {
246
- return "integer" ;
239
+ return SentryAttributeType . INTEGER ;
247
240
}
248
241
if (arg instanceof Number ) {
249
- return "double" ;
242
+ return SentryAttributeType . DOUBLE ;
250
243
}
251
- return "string" ;
244
+ return SentryAttributeType . STRING ;
252
245
}
253
246
}
0 commit comments