-
-
Notifications
You must be signed in to change notification settings - Fork 427
/
SentryAndroidOptions.java
286 lines (238 loc) · 9.77 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
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.NotNull;
/** 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;
/** Enable or disable automatic breadcrumbs for User interactions Using Window.Callback */
private boolean enableUserInteractionBreadcrumbs = 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;
/** Interval for profiling traces in milliseconds. Defaults to 100 times per second */
private int profilingTracesIntervalMillis = 1_000 / 100;
/** 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;
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;
}
public boolean isEnableUserInteractionBreadcrumbs() {
return enableUserInteractionBreadcrumbs;
}
public void setEnableUserInteractionBreadcrumbs(boolean enableUserInteractionBreadcrumbs) {
this.enableUserInteractionBreadcrumbs = enableUserInteractionBreadcrumbs;
}
/**
* 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;
enableUserInteractionBreadcrumbs = enable;
}
/**
* Returns the interval for profiling traces in milliseconds.
*
* @return the interval for profiling traces in milliseconds.
*/
public int getProfilingTracesIntervalMillis() {
return profilingTracesIntervalMillis;
}
/**
* Sets the interval for profiling traces in milliseconds.
*
* @param profilingTracesIntervalMillis - the interval for profiling traces in milliseconds.
*/
public void setProfilingTracesIntervalMillis(final int profilingTracesIntervalMillis) {
this.profilingTracesIntervalMillis = profilingTracesIntervalMillis;
}
/**
* 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;
}
}