What is @bugsnag/js?
@bugsnag/js is a JavaScript error monitoring and reporting tool that helps developers detect, diagnose, and resolve errors in their applications. It provides real-time error tracking, detailed error reports, and integrations with various platforms and frameworks.
What are @bugsnag/js's main functionalities?
Error Reporting
This feature allows you to report errors to Bugsnag. The code sample initializes Bugsnag with an API key and reports a test error.
const Bugsnag = require('@bugsnag/js');
Bugsnag.start({ apiKey: 'YOUR_API_KEY' });
try {
throw new Error('Test error');
} catch (e) {
Bugsnag.notify(e);
}
Breadcrumbs
Breadcrumbs are logs of user actions or application events that lead up to an error. This code sample shows how to leave a breadcrumb when a user clicks a button.
const Bugsnag = require('@bugsnag/js');
Bugsnag.start({ apiKey: 'YOUR_API_KEY' });
Bugsnag.leaveBreadcrumb('User clicked button', { buttonId: 'submit' });
Custom Metadata
You can add custom metadata to error reports for more context. This code sample demonstrates adding account information to an error report.
const Bugsnag = require('@bugsnag/js');
Bugsnag.start({ apiKey: 'YOUR_API_KEY' });
Bugsnag.notify(new Error('Test error'), event => {
event.addMetadata('account', {
id: 123,
name: 'Acme Co'
});
});
Session Tracking
Session tracking helps you understand the stability of your application by tracking user sessions. This code sample shows how to start a session.
const Bugsnag = require('@bugsnag/js');
Bugsnag.start({ apiKey: 'YOUR_API_KEY' });
Bugsnag.startSession();
Other packages similar to @bugsnag/js
sentry
Sentry is a popular error tracking and performance monitoring tool. It provides similar functionalities to Bugsnag, such as real-time error reporting, breadcrumbs, and custom metadata. Sentry also offers performance monitoring features that help track application performance issues.
rollbar
Rollbar is another error monitoring service that provides real-time error tracking, detailed error reports, and integrations with various platforms. It offers features like error grouping, custom metadata, and breadcrumbs, similar to Bugsnag.
airbrake-js
Airbrake is an error monitoring tool that provides real-time error tracking and detailed error reports. It offers features like error grouping, custom metadata, and breadcrumbs, similar to Bugsnag. Airbrake also integrates with various development tools and platforms.
@bugsnag/js
Universal JavaScript notifier.
This package contains both @bugsnag/browser
and @bugsnag/node
and the appropriate one will be included in your application.
Node.js
In Node, importing '@bugsnag/js'
will provide the @bugsnag/node
module.
Browser
In various bundlers, importing '@bugsnag/js'
will provide the @bugsnag/browser
module.
Bundler | Support |
---|
Browserify | Supports the package.json "browser" field by default |
Webpack | Supports the package.json "browser" field by default |
Rollup | Set browser: true in the node-resolve plugin |
Note: by using this browser-specific entrypoint, none of the node-specific code will be included in your bundle.
License
This package is free software released under the MIT License. See LICENSE.txt for details.