-
-
Notifications
You must be signed in to change notification settings - Fork 426
/
SentryAndroidOptions.java
382 lines (324 loc) · 12.7 KB
/
SentryAndroidOptions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
package io.sentry.android.core;
import io.sentry.ISpan;
import io.sentry.Scope;
import io.sentry.Sentry;
import io.sentry.SentryOptions;
import io.sentry.SpanStatus;
import io.sentry.protocol.SdkVersion;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
/** Sentry SDK options for Android */
public final class SentryAndroidOptions extends SentryOptions {
/**
* Enable or disable ANR (Application Not Responding) Default is enabled Used by AnrIntegration
*/
private boolean anrEnabled = true;
/** ANR Timeout interval in Millis Default is 5000 = 5s Used by AnrIntegration */
private long anrTimeoutIntervalMillis = 5000;
/** Enable or disable ANR on Debug mode Default is disabled Used by AnrIntegration */
private boolean anrReportInDebug = false;
/**
* Enable or disable automatic breadcrumbs for Activity lifecycle. Using
* Application.ActivityLifecycleCallbacks
*/
private boolean enableActivityLifecycleBreadcrumbs = true;
/** Enable or disable automatic breadcrumbs for App's lifecycle Using ProcessLifecycleOwner */
private boolean enableAppLifecycleBreadcrumbs = true;
/** Enable or disable automatic breadcrumbs for SystemEvents Registering a BroadcastReceiver */
private boolean enableSystemEventBreadcrumbs = true;
/** Enable or disable automatic breadcrumbs for App Components Using ComponentCallbacks */
private boolean enableAppComponentBreadcrumbs = true;
/**
* Enables the Auto instrumentation for Activity lifecycle tracing.
*
* <ul>
* <li>It also requires setting {@link SentryOptions#getTracesSampleRate()} or {@link
* SentryOptions#getTracesSampler()}.
* </ul>
*
* <ul>
* It starts a transaction before each Activity's onCreate method is called
* (onActivityPreCreated).
* <li>The transaction's name is the Activity's name, e.g. MainActivity.
* <li>The transaction's operation is navigation.
* </ul>
*
* <ul>
* It finishes the transaction after each activity's onResume method is called
* (onActivityPostResumed), this depends on {@link
* SentryAndroidOptions#enableActivityLifecycleTracingAutoFinish}.
* <li>If {@link SentryAndroidOptions#enableActivityLifecycleTracingAutoFinish} is disabled, you
* may finish the transaction manually.
* <li>If the transaction is not finished either automatically or manually, we finish it
* automatically when each Activity's onDestroy method is called (onActivityDestroyed).
* <li>If the previous transaction is not finished when a new Activity is being shown, we finish
* it automatically before the new Activity's onCreate is called (onActivityPreCreated).
* <li>The transaction status will be {@link SpanStatus#OK} if none is set.
* </ul>
*
* The transaction is automatically bound to the {@link Scope}, but only if there's no transaction
* already bound to the Scope.
*/
private boolean enableAutoActivityLifecycleTracing = true;
/**
* Enables the Auto instrumentation for Activity lifecycle tracing, but specifically when to
* finish the transaction, read {@link SentryAndroidOptions#enableAutoActivityLifecycleTracing}.
*
* <p>If you require a specific lifecycle to finish a transaction or even after the Activity is
* fully rendered but still waiting for an IO operation, you could call {@link ISpan#finish()}
* yourself on {@link Sentry#getSpan()}, be sure that you've finished all of your manually created
* Spans.
*/
private boolean enableActivityLifecycleTracingAutoFinish = true;
/**
* Profiling traces rate. 101 hz means 101 traces in 1 second. Defaults to 101 to avoid possible
* lockstep sampling. More on
* https://stackoverflow.com/questions/45470758/what-is-lockstep-sampling
*/
private int profilingTracesHz = 101;
/** Interface that loads the debug images list */
private @NotNull IDebugImagesLoader debugImagesLoader = NoOpDebugImagesLoader.getInstance();
/** Enables or disables the attach screenshot feature when an error happened. */
private boolean attachScreenshot;
/**
* Enables or disables collecting of device information which requires Inter-Process Communication
* (IPC)
*/
private boolean collectAdditionalContext = true;
/**
* Controls how many seconds to wait for sending events in case there were Startup Crashes in the
* previous run. Sentry SDKs normally send events from a background queue, but in the case of
* Startup Crashes, it blocks the execution of the {@link Sentry#init()} function for the amount
* of startupCrashFlushTimeoutMillis to make sure the events make it to Sentry.
*
* <p>When the timeout is reached, the execution will continue on background.
*
* <p>Default is 5000 = 5s.
*/
private long startupCrashFlushTimeoutMillis = 5000; // 5s
/**
* Controls the threshold after the application startup time, within which a crash should happen
* to be considered a Startup Crash.
*
* <p>Startup Crashes are sent on {@link Sentry#init()} in a blocking way, controlled by {@link
* SentryAndroidOptions#startupCrashFlushTimeoutMillis}.
*
* <p>Default is 2000 = 2s.
*/
private final long startupCrashDurationThresholdMillis = 2000; // 2s
private boolean enableFramesTracking = true;
public SentryAndroidOptions() {
setSentryClientName(BuildConfig.SENTRY_ANDROID_SDK_NAME + "/" + BuildConfig.VERSION_NAME);
setSdkVersion(createSdkVersion());
setAttachServerName(false);
// enable scope sync for Android by default
setEnableScopeSync(true);
}
private @NotNull SdkVersion createSdkVersion() {
SdkVersion sdkVersion = getSdkVersion();
final String name = BuildConfig.SENTRY_ANDROID_SDK_NAME;
final String version = BuildConfig.VERSION_NAME;
sdkVersion = SdkVersion.updateSdkVersion(sdkVersion, name, version);
sdkVersion.addPackage("maven:io.sentry:sentry-android-core", version);
return sdkVersion;
}
/**
* Checks if ANR (Application Not Responding) is enabled or disabled Default is enabled
*
* @return true if enabled or false otherwise
*/
public boolean isAnrEnabled() {
return anrEnabled;
}
/**
* Sets ANR (Application Not Responding) to enabled or disabled Default is enabled
*
* @param anrEnabled true for enabled and false for disabled
*/
public void setAnrEnabled(boolean anrEnabled) {
this.anrEnabled = anrEnabled;
}
/**
* Returns the ANR timeout internal in Millis Default is 5000 = 5s
*
* @return the timeout in millis
*/
public long getAnrTimeoutIntervalMillis() {
return anrTimeoutIntervalMillis;
}
/**
* Sets the ANR timeout internal in Millis Default is 5000 = 5s
*
* @param anrTimeoutIntervalMillis the timeout internal in Millis
*/
public void setAnrTimeoutIntervalMillis(long anrTimeoutIntervalMillis) {
this.anrTimeoutIntervalMillis = anrTimeoutIntervalMillis;
}
/**
* Checks if ANR (Application Not Responding) is enabled or disabled on Debug mode Default is
* disabled
*
* @return true if enabled or false otherwise
*/
public boolean isAnrReportInDebug() {
return anrReportInDebug;
}
/**
* Sets ANR (Application Not Responding) to enabled or disabled on Debug mode Default is disabled
*
* @param anrReportInDebug true for enabled and false for disabled
*/
public void setAnrReportInDebug(boolean anrReportInDebug) {
this.anrReportInDebug = anrReportInDebug;
}
public boolean isEnableActivityLifecycleBreadcrumbs() {
return enableActivityLifecycleBreadcrumbs;
}
public void setEnableActivityLifecycleBreadcrumbs(boolean enableActivityLifecycleBreadcrumbs) {
this.enableActivityLifecycleBreadcrumbs = enableActivityLifecycleBreadcrumbs;
}
public boolean isEnableAppLifecycleBreadcrumbs() {
return enableAppLifecycleBreadcrumbs;
}
public void setEnableAppLifecycleBreadcrumbs(boolean enableAppLifecycleBreadcrumbs) {
this.enableAppLifecycleBreadcrumbs = enableAppLifecycleBreadcrumbs;
}
public boolean isEnableSystemEventBreadcrumbs() {
return enableSystemEventBreadcrumbs;
}
public void setEnableSystemEventBreadcrumbs(boolean enableSystemEventBreadcrumbs) {
this.enableSystemEventBreadcrumbs = enableSystemEventBreadcrumbs;
}
public boolean isEnableAppComponentBreadcrumbs() {
return enableAppComponentBreadcrumbs;
}
public void setEnableAppComponentBreadcrumbs(boolean enableAppComponentBreadcrumbs) {
this.enableAppComponentBreadcrumbs = enableAppComponentBreadcrumbs;
}
/**
* Enable or disable all the automatic breadcrumbs
*
* @param enable true if enable or false otherwise
*/
public void enableAllAutoBreadcrumbs(boolean enable) {
enableActivityLifecycleBreadcrumbs = enable;
enableAppComponentBreadcrumbs = enable;
enableSystemEventBreadcrumbs = enable;
enableAppLifecycleBreadcrumbs = enable;
setEnableUserInteractionBreadcrumbs(enable);
}
/**
* Returns the interval for profiling traces in milliseconds.
*
* @return the interval for profiling traces in milliseconds.
* @deprecated has no effect and will be removed in future versions. It now just returns 0.
*/
@Deprecated
@SuppressWarnings("InlineMeSuggester")
public int getProfilingTracesIntervalMillis() {
return 0;
}
/**
* Sets the interval for profiling traces in milliseconds.
*
* @param profilingTracesIntervalMillis - the interval for profiling traces in milliseconds.
* @deprecated has no effect and will be removed in future versions.
*/
@Deprecated
public void setProfilingTracesIntervalMillis(final int profilingTracesIntervalMillis) {}
/**
* Returns the rate the profiler will sample rates at. 100 hz means 100 traces in 1 second.
*
* @return Rate the profiler will sample rates at.
*/
@ApiStatus.Internal
public int getProfilingTracesHz() {
return profilingTracesHz;
}
/** Sets the rate the profiler will sample rates at. 100 hz means 100 traces in 1 second. */
@ApiStatus.Internal
public void setProfilingTracesHz(final int profilingTracesHz) {
this.profilingTracesHz = profilingTracesHz;
}
/**
* Returns the Debug image loader
*
* @return the image loader
*/
public @NotNull IDebugImagesLoader getDebugImagesLoader() {
return debugImagesLoader;
}
/**
* Sets the image loader
*
* @param debugImagesLoader the image loader
*/
public void setDebugImagesLoader(final @NotNull IDebugImagesLoader debugImagesLoader) {
this.debugImagesLoader =
debugImagesLoader != null ? debugImagesLoader : NoOpDebugImagesLoader.getInstance();
}
public boolean isEnableAutoActivityLifecycleTracing() {
return enableAutoActivityLifecycleTracing;
}
public void setEnableAutoActivityLifecycleTracing(boolean enableAutoActivityLifecycleTracing) {
this.enableAutoActivityLifecycleTracing = enableAutoActivityLifecycleTracing;
}
public boolean isEnableActivityLifecycleTracingAutoFinish() {
return enableActivityLifecycleTracingAutoFinish;
}
public void setEnableActivityLifecycleTracingAutoFinish(
boolean enableActivityLifecycleTracingAutoFinish) {
this.enableActivityLifecycleTracingAutoFinish = enableActivityLifecycleTracingAutoFinish;
}
public boolean isAttachScreenshot() {
return attachScreenshot;
}
public void setAttachScreenshot(boolean attachScreenshot) {
this.attachScreenshot = attachScreenshot;
}
public boolean isCollectAdditionalContext() {
return collectAdditionalContext;
}
public void setCollectAdditionalContext(boolean collectAdditionalContext) {
this.collectAdditionalContext = collectAdditionalContext;
}
public boolean isEnableFramesTracking() {
return enableFramesTracking;
}
/**
* Enable or disable Frames Tracking, which is used to report slow and frozen frames.
*
* @param enableFramesTracking true if frames tracking should be enabled, false otherwise.
*/
public void setEnableFramesTracking(boolean enableFramesTracking) {
this.enableFramesTracking = enableFramesTracking;
}
/**
* Returns the Startup Crash flush timeout in Millis
*
* @return the timeout in Millis
*/
@ApiStatus.Internal
long getStartupCrashFlushTimeoutMillis() {
return startupCrashFlushTimeoutMillis;
}
/**
* Sets the Startup Crash flush timeout in Millis
*
* @param startupCrashFlushTimeoutMillis the timeout in Millis
*/
@TestOnly
void setStartupCrashFlushTimeoutMillis(long startupCrashFlushTimeoutMillis) {
this.startupCrashFlushTimeoutMillis = startupCrashFlushTimeoutMillis;
}
/**
* Returns the Startup Crash duration threshold in Millis
*
* @return the threshold in Millis
*/
@ApiStatus.Internal
public long getStartupCrashDurationThresholdMillis() {
return startupCrashDurationThresholdMillis;
}
}