Ember integration guide

Add Bugsnag to your Ember projects to automatically capture and report errors in production.

Installation

The best way to install Bugsnag is to get the @bugsnag/js npm package from the npm registry using npm or yarn:

npm install --save @bugsnag/js
# or
yarn add @bugsnag/js

CDN

Alternatively, if you only want to use Bugsnag in the browser, for the most simple installation you can load it from our CDN:

<script src="//d2wy8f7a9ursnm.cloudfront.net/v5/bugsnag.min.js"></script>
<script>window.bugsnagClient = bugsnag('API_KEY')</script>

See the CDN guide for more information.

Basic configuration

Depending on which module system you are using, you’ll need to include Bugsnag in one of the following ways:

// commonjs/node-style require
var bugsnag = require('@bugsnag/js')

// ES module-style import
import bugsnag from '@bugsnag/js'

Note: if you are using the CDN, bugsnag will be defined as a global variable and you don’t need to import or require it.

The simplest way to configure the client is to provide your API key as a string:

var bugsnagClient = bugsnag('YOUR_API_KEY')

Then hook up Bugsnag with the Ember error handler:

Ember.onerror = function (error) {
  bugsnagClient.notify(error)
}

To specify any additional configuration options, supply an object instead:

var bugsnagClient = bugsnag({
  apiKey: 'YOUR_API_KEY',
  otherOptions: value
})

For information on values that can be set in the configuration object, see configuration options.

TypeScript support

Type definitions are bundled with each of the top-level @bugsnag packages. After installing @bugsnag/js or any of the framework integrating plugins, TypeScript compilation should “just work”.

Reporting unhandled errors

After completing installation and basic configuration, unhandled exceptions and unhandled promise rejections will be automatically reported.

Reporting handled errors

Sometimes it is useful to manually notify Bugsnag of a problem. To do this, call bugsnagClient.notify(). For example:

try {
  something.risky()
} catch (e) {
  bugsnagClient.notify(e)
}

When reporting handled errors, it’s often helpful to send custom diagnostic data or to adjust the severity of particular errors. For more information, see reporting handled errors.

Sending diagnostic data

Automatically captured diagnostics

Bugsnag will automatically capture the following data for every exception:

Browser

  • The current URL
  • Script content (if the error originated in an inline <script/> tag)
  • Browser name, version, user agent, locale and time
  • Operating system
  • Release stage (production, beta, staging, etc)

Node.js

  • Request info (if relevant and available)
  • Device time
  • Hostname
  • Release stage (production, beta, staging, etc)

Custom diagnostics

Error reports have a metaData property where arbitrary data can be attached.

Top-level properties of metaData will render as tabs in the Bugsnag dashboard. Custom metaData can be supplied globally:

bugsnagClient.metaData = {
  company: {
    name: "Acme Co.",
    country: "uk"
  }
}

For additional options on attaching custom metaData, see customizing error reports.

Leaving breadcrumbs

Breadcrumbs allow you to see a log of actions that led up to an error. Error reports automatically include breadcrumbs for the last 20 events which occurred.

Automatically captured breadcrumbs

By default, Bugsnag captures the following events as breadcrumbs.

Browser

  • Clicks
  • Errors
  • Console logs, warnings, and errors
  • Page load, hide, and show
  • DOMContentLoaded events
  • Pop state
  • History push state and replace state
  • Hash change
  • HTTP requests

For more information or to disable particular classes of automatic breadcrumb generation see configuration options.

Node.js

Breadcrumbs are not yet supported on Node.

Identifying users

In order to correlate errors with customer reports, or to see a list of users who experienced each error, it is helpful to capture and display user information on your Bugsnag dashboard.

You can provide or modify the user information of an error report by supplying the user option to a notify call, or using a beforeSend callback to modify report.user. For information on doing so, see customizing error reports.

Setting a user on the client

In the browser, or in other environments where your process will only be serving a single user (such as a CLI app in Node.js), you can attach user info directly on the bugsnagClient instance. This will then be sent along with all subsequent errors.

// Attach to the client object
bugsnagClient.user = {
  id: '3',
  name: 'Bugs Nag',
  email: 'bugs.nag@bugsnag.com'
}

Tracking releases

Configure your app version to see the release that each error was introduced in.

bugsnag({ appVersion: '4.10.0' })

Then set up a build tool integration to enable linking to code in your source control provider from the releases dashboard, timeline annotations, and stack traces.

Session tracking

Bugsnag tracks the number of “sessions” that happen within your application. This allows you to compare stability scores between releases and helps you to understand the quality of your releases.

Sessions are captured and reported by default. This behaviour can be disabled using the autoCaptureSessions configuration option.

Browser

In the browser, Bugsnag will automatically report a session each time:

  • The page loads
  • The URL changes via history.pushState() or history.replaceState()

If you want control over what is deemed a session, you can switch off automatic session tracking with the autoCaptureSessions option, and call bugsnagClient.startSession() when appropriate for your application.

Node.js

By default, sessions are only reported in Node.js if you are using one of the server integrations:

  • @bugsnag/plugin-express
  • @bugsnag/plugin-restify
  • @bugsnag/plugin-koa

When using one of these integrations, Bugsnag will record a session every time a request is served. A summary of sessions recorded will periodically sent to Bugsnag.

If you are working with different kind of application or not using one of the server integrations above, you should call bugsnagClient.startSession() to indicate each time a session has started.

Next steps

  • View @bugsnag/js, the library powering Bugsnag’s JavaScript error reporting, on GitHub
  • Get support for your questions and feature requests