-
-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathMyApplication.java
More file actions
80 lines (67 loc) · 2.86 KB
/
Copy pathMyApplication.java
File metadata and controls
80 lines (67 loc) · 2.86 KB
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
package io.sentry.samples.android;
import android.app.Application;
import android.os.StrictMode;
import io.sentry.ISpan;
import io.sentry.Sentry;
import io.sentry.samples.android.sqlite.SampleDatabases;
/** Apps. main Application. */
public class MyApplication extends Application {
@Override
public void onCreate() {
// Make Session Replay fail fast instead of silently degrading masking when an exception is
// swallowed (e.g. unsupported/obfuscated Compose internals). This way regressions surface as
// crashes in our release/obfuscated builds that run on real devices in CI. Only meant for our
// own sample/UI-test apps, customers should never set this.
System.setProperty("io.sentry.replay.compose.fail-fast", "true");
Sentry.startProfiler();
strictMode();
super.onCreate();
extendAppStartExample();
SampleDatabases.INSTANCE.warmUp(this);
// Example how to initialize the SDK manually which allows access to SentryOptions callbacks.
// Make sure you disable the auto init via manifest meta-data: io.sentry.auto-init=false
// SentryAndroid.init(
// this,
// options -> {
// /*
// use options, for example, to add a beforeSend callback:
//
// options.setBeforeSend((event, hint) -> {
// process event
// });
// */
// });
}
// Example of extending the app start: launch-time work done here (after the SDK auto-inits) is
// included in the app start measurement. Requires standalone app start tracing
// (io.sentry.standalone-app-start-tracing.enable in the manifest). The artificial delays stand in
// for real launch work, e.g. loading remote config or feature flags before the first screen.
private void extendAppStartExample() {
Sentry.extendAppStart();
final ISpan extendedSpan = Sentry.getExtendedAppStartSpan();
final ISpan configSpan = extendedSpan.startChild("remote_config", "Load remote config");
artificialDelay(200);
configSpan.finish();
final ISpan flagsSpan = extendedSpan.startChild("feature_flags", "Fetch feature flags");
artificialDelay(100);
flagsSpan.finish();
Sentry.finishExtendedAppStart();
}
private static void artificialDelay(final long millis) {
try {
Thread.sleep(millis);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
}
private void strictMode() {
// https://developer.android.com/reference/android/os/StrictMode
// StrictMode is a developer tool which detects things you might be doing by accident and
// brings them to your attention so you can fix them.
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(
new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
}
}
}