Switching to Sentry-Javascript


#1

If you want to move to the new sentry-javascript SDK we provided a short guide here of the most common patterns:

Migration

Here are some examples of how the new SDKs work. Please note that the API for all JavaScript SDKs is the same.

Installation

Old :

Raven.config('___PUBLIC_DSN___', { release: '1.3.0', }).install();

New :

Sentry.init({ dsn: '___PUBLIC_DSN___', release: '1.3.0', });

Set a global tag

Old :

Raven.setTagsContext({ key: 'value' });

New :

Sentry.configureScope(scope => scope.setTag('key', 'value'));

Capture custom exception

Old

try {
  throwingFunction();
} catch (e) {
  Raven.captureException(e, {
    extra: {
      debug: false
    }
  });
}

New :

try {
  throwingFunction();
} catch (e) {
  Sentry.withScope(scope => {
    scope.setExtra('debug', false);
    Sentry.captureException(e);
  });
}

Capture a message

Old :

Raven.captureMessage('test', 'info', {
  extra: {
    debug: false
  }
});

New :

Sentry.withScope(scope => {
  scope.setExtra('debug', false);
  Sentry.captureMessage('test', 'info');
});

Breadcrumbs

Old :

Raven.captureBreadcrumb({
  message: 'Item added to shopping cart',
  category: 'action',
  data: {
    isbn: '978-1617290541',
    cartSize: '3'
  }
});

New :

Sentry.addBreadcrumb({
  message: 'Item added to shopping cart',
  category: 'action',
  data: {
    isbn: '978-1617290541',
    cartSize: '3'
  }
});

#2

Thanks. Is there a timeline to sunset Raven?


#3

Unofficial plan is 1 year+ while we probably will maintain it until browser no longer are able to run it.
We will make bugfix releases for raven-js if needed but no more new features.


#4

What’s the migration pattern for using Raven’s ignoreErrors? Do we need to implement that ourselves with beforeSend?


#5

ignoreErrors should work the same way it did before, see: https://github.com/kamilogorek/sentry-browser-sdk-demo/blob/master/app.js#L23
for a detailed example.


#6

We were previously setting captureUnhandledRejections to false in raven. For sentry-browser, the config options don’t include anything like this, is there a way to get parity?

UPDATE: On further review, it looks like providing custom options to the GlobalHandlers integration is the new place to pass this (setting onunhandledrejection to false). Going to test that out, but wanted others to know because it isn’t easy to find in the docs.


#7

With raven-js I was using the ravenSuccess event to get informed of the latest report:

document.addEventListener('ravenSuccess', event => {
  console.log(event.data.event_id);
}, true);

How does that work with @sentry/browser?