Migration page from sentry-android 1.x to sentry-android 2.x.
Old:
Sentry.init("___PUBLIC_DSN___", new AndroidSentryClientFactory(context));
New:
The SDK is able to initialize automatically. The only thing required is to make the DSN available.
sentry.properties
has been discontinued and configurations on this SDK version is over AndroidManifest.xml
or code.
<meta-data android:name="io.sentry.dsn" android:value="___PUBLIC_DSN___" />
Or:
If you want to call SentryAndroid.init(...)
by yourself, first of all you need to disable the auto-init
feature.
<meta-data android:name="io.sentry.auto-init" android:value="false" />
SentryAndroid.init(context, options -> {
options.setDsn("___PUBLIC_DSN___");
});
Old:
Sentry.getContext().addTag("tagName", "tagValue");
New:
Sentry.setTag("tagName", "tagValue");
Old:
try {
int x = 1 / 0;
} catch (Exception e) {
Sentry.capture(e);
}
New:
try {
int x = 1 / 0;
} catch (Exception e) {
Sentry.captureException(e);
}
Old:
Exception exception = new Exception("custom error");
EventBuilder eventBuilder = new EventBuilder()
.withLevel(Event.Level.ERROR)
.withSentryInterface(new ExceptionInterface(exception));
Sentry.capture(eventBuilder);
New:
Exception exception = new Exception("custom error");
SentryEvent event = new SentryEvent(exception);
event.setLevel(SentryLevel.ERROR);
Sentry.captureEvent(event);
Old:
Sentry.capture("This is a test");
New:
Sentry.captureMessage("This is a test"); // SentryLevel.INFO by default
Sentry.captureMessage("This is a test", SentryLevel.WARNING); // or specific level
Old:
Sentry.getContext().recordBreadcrumb(
new BreadcrumbBuilder().setMessage("User made an action").build()
);
New:
Sentry.addBreadcrumb("User made an action");
Old:
Sentry.getContext().setUser(
new UserBuilder().setEmail("[email protected]").build()
);
New:
User user = new User();
user.setEmail("[email protected]");
Sentry.setUser(user);
Old:
Sentry.getContext().addExtra("extra", "thing");
New:
Sentry.setExtra("extra", "thing");