Install as a standard Ember Addon:
ember install ember-cli-rollbar2
In your config/environment.js
file:
let ENV = {
rollbar: {
// Rollbar configuration goes here
accessToken: 'POST_CLIENT_ITEM_ACCESS_TOKEN'
},
'ember-cli-rollbar': {
// Addon configuration goes here
}
};
The Rollbar Configuration is specified
in the rollbar
key in the environment. See the Rollbar documentation for available options.
If enabled
is not set, this addon will automatically enable Rollbar if the Ember environment is production
.
captureEmberErrors
: Defaults totrue
. The addon can setEmber.onerror
to capture errors sent by Ember.outputEmberErrorsToConsole
: Defaults totrue
. When catching Ember errors, it also writes these errors to the console. If you prefer to not have your errors logged to the console, set this tofalse
.
This adds a rollbar
service to your app which exposes the Rollbar client library to your application.
You can use this service to log messages explicitly in outside of exceptions or Ember.Logger
overrides:
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
export default Controller.extend({
rollbar: service(),
actions: {
doSomething() {
try {
somethingThatMightFail();
} catch (err) {
this.get('rollbar').error('Caught an exception', err);
}
}
}
});
The service directly exposes the methods log
, debug
, info
, warn
, warning
, error
, critical
, and setPerson
.
The Rollbar client instance itself can be accessed via the instance
property.
The setPerson
method configures Rollbar for Person tracking and should be called with a hash (or id) that represents the current user.
FastBoot support is mostly automatic, however there some changes you will need to make to your project:
- In
package.json
, move therollbar
package fromdevDependencies
todependencies
. - Also in
package.json
, addrollbar
to yourfastbootDependencies
:
"fastbootDependencies": [
"rollbar"
]
In addition, when in FastBoot mode, the Rollbar Node library cannot use the Rollbar client token, it must use a server token to access its API.
There are two ways to provide this token, in the section below.
You may choose to set Rollbar's POST_SERVER_ITEM_ACCESS_TOKEN
directly in the addon configuration:
let ENV = {
'ember-cli-rollbar': {
serverToken: 'POST_SERVER_ITEM_ACCESS_TOKEN'
}
};
The downside of using serverToken
is that the server token is then leaked into the client configuration
and visible in the browser. If you don't want that, you can add it to a process environment variable which
the addon will read:
let ENV = {
'ember-cli-rollbar': {
serverTokenEnv: 'MY_TOKEN_ENV_VAR'
}
};
In this case, the addon will use value of the MY_TOKEN_ENV_VAR
environment variable in the FastBoot process
as the server token. In addition, in order to use this you will need to add process
to your list
of fastbootDependencies
:
"fastbootDependencies": [
"process",
"rollbar"
]
git clone https://github.com/paulcwatts/ember-cli-rollbar.git
cd ember-cli-rollbar
npm install
npm run lint:js
npm run lint:js -- --fix
ember test
– Runs the test suite on the current Ember versionember test --server
– Runs the test suite in "watch mode"ember try:each
– Runs the test suite against multiple Ember versions
ember serve
- Visit the dummy application at http://localhost:4200.
For more information on using ember-cli, visit https://ember-cli.com/.
ember-cli-rollbar2 is tested with:
- Ember versions 2.12, 2.16 and 2.18 and 3.1+
- Rollbar versions 2.3+
- Node versions 4+