question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No way to tell when `Sentry.init()` is complete

See original GitHub issue

Reading the docs, and some of the code, I cant see a way to tell when Sentry.init() is complete.

This is making it difficult to capture application errors that occur before Sentry is setup. From what I understand, Sentry will:

only monitor global errors and unhandled promise for you until the SDK is fully loaded

But, what if I want to wait until Sentry is loaded before I bootstrap my application? That way I can be confident that the errors are captured.

Right now, I’m loading Sentry after my app is ready. But app errors are ignored as Sentry isnt ready until after init.

// ... my app init is before this
Sentry.init({
    dsn: sentryDsn,
    environment: environment,
    debug: environment === 'local'
});
// these undefined errors are never captured
var a = b + c;

What I am wondering is how I can make sure Sentry “is done and ready” so that I can boot up my app and make sure app-level errors are captured?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kamilogorekcommented, Oct 25, 2018

@egor-sorokin can you take a look at our old plugin code and try to “port” it to your project? https://github.com/getsentry/sentry-javascript/blob/master/packages/raven-js/plugins/angular.js#L12-L49

It should be rather straightforward. We don’t document Angular 1.x anymore, as there are not many reports of people using it. We may need to do it though, if there are issues like the one mentioned above.

1reaction
egor-sorokincommented, Oct 22, 2018

I recently faced the same problem: @sentry/browser: v 4.1.1 I have an angularjs app and I initialised Sentry before the main app (and I tried to initialise it in angular.run()), like so:

import * as Sentry from '@sentry/browser';

Sentry.init({
    dsn: myDsn,
    beforeBreadcrumb: function(breadcrumb, hint) {
        return null;
    },
    beforeSend: function(event) {
        console.log(event);
        return event;
    }
})

Then I put errors in controllers & factories but none of them was caught. After that I added a timeout with 0ms and it started work. Code snippet from angularjs controller:

var d = new Date();
setTimeout(function() {
      // sentry tracks the error below
      throw new Error('timeout' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds());
}, 0);

// sentry doesn't track the error below
throw new Error('no timeout' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds());

@james2doyle example doesn’t work for me at all

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting for JavaScript - Sentry Documentation
You can view the JSON payload of an event to see how Sentry stores additional data in the event. The shape of the...
Read more >
Errors logged before Sentry.init() in the browser
We're loading the Sentry Browser SDK from the CDN and calling Sentry.init() to configure it. We would like for errors to not be...
Read more >
Basic Options for JavaScript | Sentry Documentation
Options are passed to the init() function as object: ... Learn more about how to send release data so Sentry can tell you...
Read more >
Tips and Tricks | Sentry Documentation
These are some general recommendations and tips for how to get the most out of Raven.js and Sentry. Decluttering Sentry The first thing...
Read more >
JavaScript | Sentry Documentation
Head over to sentry.io , then return to this page. ... If you're updating your Sentry SDK to the latest version, check out...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found