Skip to content

Commit f1b17ef

Browse files
committed
Properly check logging values
1 parent f03818a commit f1b17ef

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

packages/core/android/src/main/java/io/sentry/react/RNSentryStart.java

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -217,35 +217,54 @@ private static void configureAndroidProfiling(
217217

218218
// Set profile session sample rate
219219
if (androidProfilingOptions.hasKey("profileSessionSampleRate")) {
220-
final double profileSessionSampleRate =
221-
androidProfilingOptions.getDouble("profileSessionSampleRate");
222-
options.setProfileSessionSampleRate(profileSessionSampleRate);
223-
logger.log(
224-
SentryLevel.INFO,
225-
String.format(
226-
"Android UI Profiling profileSessionSampleRate set to: %.2f",
227-
profileSessionSampleRate));
220+
if (androidProfilingOptions.getType("profileSessionSampleRate") == ReadableType.Number) {
221+
final double profileSessionSampleRate =
222+
androidProfilingOptions.getDouble("profileSessionSampleRate");
223+
options.setProfileSessionSampleRate(profileSessionSampleRate);
224+
logger.log(
225+
SentryLevel.INFO,
226+
String.format(
227+
"Android UI Profiling profileSessionSampleRate set to: %.2f",
228+
profileSessionSampleRate));
229+
} else {
230+
logger.log(
231+
SentryLevel.WARNING,
232+
"Android UI Profiling profileSessionSampleRate must be a number, ignoring invalid"
233+
+ " value");
234+
}
228235
}
229236

230237
// Set profiling lifecycle mode
231238
if (androidProfilingOptions.hasKey("lifecycle")) {
232-
final String lifecycle = androidProfilingOptions.getString("lifecycle");
233-
if ("manual".equalsIgnoreCase(lifecycle)) {
234-
options.setProfileLifecycle(ProfileLifecycle.MANUAL);
235-
logger.log(SentryLevel.INFO, "Android UI Profile Lifecycle set to MANUAL");
236-
} else if ("trace".equalsIgnoreCase(lifecycle)) {
237-
options.setProfileLifecycle(ProfileLifecycle.TRACE);
238-
logger.log(SentryLevel.INFO, "Android UI Profile Lifecycle set to TRACE");
239+
if (androidProfilingOptions.getType("lifecycle") == ReadableType.String) {
240+
final String lifecycle = androidProfilingOptions.getString("lifecycle");
241+
if ("manual".equalsIgnoreCase(lifecycle)) {
242+
options.setProfileLifecycle(ProfileLifecycle.MANUAL);
243+
logger.log(SentryLevel.INFO, "Android UI Profile Lifecycle set to MANUAL");
244+
} else if ("trace".equalsIgnoreCase(lifecycle)) {
245+
options.setProfileLifecycle(ProfileLifecycle.TRACE);
246+
logger.log(SentryLevel.INFO, "Android UI Profile Lifecycle set to TRACE");
247+
}
248+
} else {
249+
logger.log(
250+
SentryLevel.WARNING,
251+
"Android UI Profiling lifecycle must be a string, ignoring invalid value");
239252
}
240253
}
241254

242255
// Set start on app start
243256
if (androidProfilingOptions.hasKey("startOnAppStart")) {
244-
final boolean startOnAppStart = androidProfilingOptions.getBoolean("startOnAppStart");
245-
options.setStartProfilerOnAppStart(startOnAppStart);
246-
logger.log(
247-
SentryLevel.INFO,
248-
String.format("Android UI Profiling startOnAppStart set to %b", startOnAppStart));
257+
if (androidProfilingOptions.getType("startOnAppStart") == ReadableType.Boolean) {
258+
final boolean startOnAppStart = androidProfilingOptions.getBoolean("startOnAppStart");
259+
options.setStartProfilerOnAppStart(startOnAppStart);
260+
logger.log(
261+
SentryLevel.INFO,
262+
String.format("Android UI Profiling startOnAppStart set to %b", startOnAppStart));
263+
} else {
264+
logger.log(
265+
SentryLevel.WARNING,
266+
"Android UI Profiling startOnAppStart must be a boolean, ignoring invalid value");
267+
}
249268
}
250269
}
251270

0 commit comments

Comments
 (0)