Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
155 lines (109 loc) · 2.45 KB

File metadata and controls

155 lines (109 loc) · 2.45 KB
Copy raw file
Download raw file
Outline
Edit and raw actions

Migrating from sentry-java to sentry-android

Docs

Migration page from sentry-android 1.x to sentry-android 2.x.

Installation

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___");    
});

Set tag

Old:

Sentry.getContext().addTag("tagName", "tagValue");

New:

Sentry.setTag("tagName", "tagValue");

Capture custom exception

Old:

try {
  int x = 1 / 0;
} catch (Exception e) {
  Sentry.capture(e);
}

New:

try {
  int x = 1 / 0;
} catch (Exception e) {
  Sentry.captureException(e);
}

Capture a custom event

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);

Capture a message

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

Breadcrumbs

Old:

Sentry.getContext().recordBreadcrumb(
  new BreadcrumbBuilder().setMessage("User made an action").build()
);

New:

Sentry.addBreadcrumb("User made an action");

User

Old:

Sentry.getContext().setUser(
  new UserBuilder().setEmail("hello@sentry.io").build()
);

New:

User user = new User();
user.setEmail("hello@sentry.io");
Sentry.setUser(user);

Set extra

Old:

Sentry.getContext().addExtra("extra", "thing");

New:

Sentry.setExtra("extra", "thing");
Morty Proxy This is a proxified and sanitized view of the page, visit original site.