Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
feat(config): Support configuration of appType
Browse files Browse the repository at this point in the history
The error reporting payload supports app.type but this notifier didn't provide a way to set it. This
change allows the app type setting to be set with the config option "appType".

Fixes #126.
  • Loading branch information
bengourley committed Mar 15, 2018
1 parent ac3b195 commit c50d28e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var Configuration = {
apiKey: process.env.BUGSNAG_API_KEY,
releaseStage: process.env.NODE_ENV || "production",
appVersion: null,
appType: null,
metaData: {},
logger: new Logger(),
sendCode: true,
Expand Down Expand Up @@ -56,6 +57,7 @@ var Configuration = {
}
Configuration.releaseStage = options.releaseStage || Configuration.releaseStage;
Configuration.appVersion = options.appVersion || Configuration.appVersion;
Configuration.appType = options.appType || Configuration.appType;
Configuration.autoNotifyUncaught = options.autoNotify != null ? options.autoNotify : Configuration.autoNotifyUncaught;
Configuration.autoNotifyUnhandledRejection = options.autoNotifyUnhandledRejection === false ? false : (options.autoNotify != null ? options.autoNotify : Configuration.autoNotifyUnhandledRejection);
Configuration.useSSL = options.useSSL != null ? options.useSSL : Configuration.useSSL;
Expand Down
5 changes: 5 additions & 0 deletions lib/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ function Notification(bugsnagErrors, options, handledState) {
event.app.version = Configuration.appVersion;
}

if (Configuration.appType) {
if (!event.app) event.app = {};
event.app.type = Configuration.appType;
}

if (Configuration.releaseStage) {
if (!event.app) event.app = {};
event.app.releaseStage = Configuration.releaseStage;
Expand Down
12 changes: 12 additions & 0 deletions scratch/express.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var bugsnag = require('../').register('ababababababa')
var app = require('express')()

app.use(bugsnag.requestHandler)
app.get('/', () => {
setTimeout(() => { throw new Error('flop') }, 0)
})
app.use(bugsnag.errorHandler)
app.use((err, req, res, next) => {
})

app.listen(3010)
7 changes: 7 additions & 0 deletions scratch/sig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var bugsnag = require('../').register('ababababababa', {
notifyReleaseStages: ['1'],
releaseStage: 'prod'
})

//process.on('SIGKILL', function () { console.log('SIGKILL') })
throw new Error('flop')
10 changes: 10 additions & 0 deletions test/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ describe("Notification", function() {
});
});

describe("appType", function() {
it("should send an appType when configured on Bugsnag", function() {
Bugsnag.configure({
appType: "worker"
});
Bugsnag.notify("This is the message");
deliverStub.firstCall.thisValue.events[0].app.type.should.equal("worker");
});
});

describe("releaseStage", function() {
it("shouldnt send a notification when releaseStage isnt configured in notifyReleaseStages", function() {
Bugsnag.configure({
Expand Down

0 comments on commit c50d28e

Please sign in to comment.