|
7 | 7 | import com.facebook.react.common.JavascriptException; |
8 | 8 | import io.sentry.ILogger; |
9 | 9 | import io.sentry.Integration; |
| 10 | +import io.sentry.ProfileLifecycle; |
10 | 11 | import io.sentry.Sentry; |
11 | 12 | import io.sentry.SentryEvent; |
12 | 13 | import io.sentry.SentryLevel; |
@@ -162,6 +163,9 @@ static void getSentryAndroidOptions( |
162 | 163 | options.getReplayController().setBreadcrumbConverter(new RNSentryReplayBreadcrumbConverter()); |
163 | 164 | } |
164 | 165 |
|
| 166 | + // Configure Android UI Profiling |
| 167 | + configureAndroidProfiling(options, rnOptions); |
| 168 | + |
165 | 169 | // Exclude Dev Server and Sentry Dsn request from Breadcrumbs |
166 | 170 | String dsn = getURLFromDSN(rnOptions.getString("dsn")); |
167 | 171 | String devServerUrl = rnOptions.getString("devServerUrl"); |
@@ -192,6 +196,57 @@ static void getSentryAndroidOptions( |
192 | 196 | SentryLevel.INFO, String.format("Native Integrations '%s'", options.getIntegrations())); |
193 | 197 | } |
194 | 198 |
|
| 199 | + private void configureAndroidProfiling( |
| 200 | + @NotNull SentryAndroidOptions options, @NotNull ReadableMap rnOptions) { |
| 201 | + if (!rnOptions.hasKey("_experiments")) { |
| 202 | + return; |
| 203 | + } |
| 204 | + |
| 205 | + @Nullable final ReadableMap experiments = rnOptions.getMap("_experiments"); |
| 206 | + if (experiments == null || !experiments.hasKey("androidProfilingOptions")) { |
| 207 | + return; |
| 208 | + } |
| 209 | + |
| 210 | + @Nullable |
| 211 | + final ReadableMap androidProfilingOptions = experiments.getMap("androidProfilingOptions"); |
| 212 | + if (androidProfilingOptions == null) { |
| 213 | + return; |
| 214 | + } |
| 215 | + |
| 216 | + // Set profile session sample rate |
| 217 | + if (androidProfilingOptions.hasKey("profileSessionSampleRate")) { |
| 218 | + final double profileSessionSampleRate = |
| 219 | + androidProfilingOptions.getDouble("profileSessionSampleRate"); |
| 220 | + options.setProfileSessionSampleRate(profileSessionSampleRate); |
| 221 | + logger.log( |
| 222 | + SentryLevel.INFO, |
| 223 | + String.format( |
| 224 | + "Android UI Profiling profileSessionSampleRate set to: %.2f", |
| 225 | + profileSessionSampleRate)); |
| 226 | + } |
| 227 | + |
| 228 | + // Set profiling lifecycle mode |
| 229 | + if (androidProfilingOptions.hasKey("lifecycle")) { |
| 230 | + final String lifecycle = androidProfilingOptions.getString("lifecycle"); |
| 231 | + if ("manual".equalsIgnoreCase(lifecycle)) { |
| 232 | + options.setProfileLifecycle(ProfileLifecycle.MANUAL); |
| 233 | + logger.log(SentryLevel.INFO, "Android UI Profile Lifecycle set to MANUAL"); |
| 234 | + } else if ("trace".equalsIgnoreCase(lifecycle)) { |
| 235 | + options.setProfileLifecycle(ProfileLifecycle.TRACE); |
| 236 | + logger.log(SentryLevel.INFO, "Android UI Profile Lifecycle set to TRACE"); |
| 237 | + } |
| 238 | + } |
| 239 | + |
| 240 | + // Set start on app start |
| 241 | + if (androidProfilingOptions.hasKey("startOnAppStart")) { |
| 242 | + final boolean startOnAppStart = androidProfilingOptions.getBoolean("startOnAppStart"); |
| 243 | + options.setStartProfilerOnAppStart(startOnAppStart); |
| 244 | + logger.log( |
| 245 | + SentryLevel.INFO, |
| 246 | + String.format("Android UI Profiling startOnAppStart set to %b", startOnAppStart)); |
| 247 | + } |
| 248 | + } |
| 249 | + |
195 | 250 | /** |
196 | 251 | * This function updates the options with RNSentry defaults. These default can be overwritten by |
197 | 252 | * users during manual native initialization. |
|
0 commit comments