diff --git a/jest.config.js b/jest.config.js index 6e1149e6f2..b2466ce54d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -30,6 +30,7 @@ module.exports = { displayName: 'node plugins', testEnvironment: 'node', testMatch: [ + testsForPackage('plugin-node-app'), testsForPackage('plugin-server-*') ] } diff --git a/packages/node/package.json b/packages/node/package.json index 448f04803d..2a5bc580de 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -28,6 +28,7 @@ "@bugsnag/delivery-node": "^7.1.1", "@bugsnag/plugin-contextualize": "^7.1.1", "@bugsnag/plugin-intercept": "^7.1.1", + "@bugsnag/plugin-node-app": "^7.1.1", "@bugsnag/plugin-node-device": "^7.1.1", "@bugsnag/plugin-node-in-project": "^7.1.1", "@bugsnag/plugin-node-surrounding-code": "^7.1.1", diff --git a/packages/node/src/notifier.js b/packages/node/src/notifier.js index 59f96d056b..11c4602edd 100644 --- a/packages/node/src/notifier.js +++ b/packages/node/src/notifier.js @@ -15,6 +15,7 @@ const schema = { ...require('@bugsnag/core/config').schema, ...require('./config // remove enabledBreadcrumbTypes from the config schema delete schema.enabledBreadcrumbTypes +const pluginApp = require('@bugsnag/plugin-node-app') const pluginSurroundingCode = require('@bugsnag/plugin-node-surrounding-code') const pluginInProject = require('@bugsnag/plugin-node-in-project') const pluginStripProjectRoot = require('@bugsnag/plugin-strip-project-root') @@ -26,6 +27,7 @@ const pluginIntercept = require('@bugsnag/plugin-intercept') const pluginContextualize = require('@bugsnag/plugin-contextualize') const internalPlugins = [ + pluginApp, pluginSurroundingCode, pluginInProject, pluginStripProjectRoot, diff --git a/packages/plugin-node-app/LICENSE.txt b/packages/plugin-node-app/LICENSE.txt new file mode 100644 index 0000000000..ddc0631e24 --- /dev/null +++ b/packages/plugin-node-app/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (c) Bugsnag, https://www.bugsnag.com/ + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/plugin-node-app/README.md b/packages/plugin-node-app/README.md new file mode 100644 index 0000000000..87b708eb05 --- /dev/null +++ b/packages/plugin-node-app/README.md @@ -0,0 +1,6 @@ +# @bugsnag/plugin-node-app + +This plugin adds the duration an application has been running for to the `app` section of each event. It is included in the node notifier. + +## License +MIT diff --git a/packages/plugin-node-app/app.js b/packages/plugin-node-app/app.js new file mode 100644 index 0000000000..f987caef79 --- /dev/null +++ b/packages/plugin-node-app/app.js @@ -0,0 +1,11 @@ +const appStart = new Date() + +module.exports = { + load: client => { + client.addOnError(event => { + const now = new Date() + + event.app.duration = now - appStart + }, true) + } +} diff --git a/packages/plugin-node-app/package.json b/packages/plugin-node-app/package.json new file mode 100644 index 0000000000..dcaf8f366f --- /dev/null +++ b/packages/plugin-node-app/package.json @@ -0,0 +1,22 @@ +{ + "name": "@bugsnag/plugin-node-app", + "version": "7.1.1", + "main": "app.js", + "description": "@bugsnag/js plugin to set app info in node", + "homepage": "https://www.bugsnag.com/", + "repository": { + "type": "git", + "url": "git@github.com:bugsnag/bugsnag-js.git" + }, + "publishConfig": { + "access": "public" + }, + "files": [ + "*.js" + ], + "author": "Bugsnag", + "license": "MIT", + "devDependencies": { + "@bugsnag/core": "^7.1.1" + } +} diff --git a/packages/plugin-node-app/test/app.test.ts b/packages/plugin-node-app/test/app.test.ts new file mode 100644 index 0000000000..e1fc60c941 --- /dev/null +++ b/packages/plugin-node-app/test/app.test.ts @@ -0,0 +1,23 @@ +import plugin from '../app' +import Client from '@bugsnag/core/client' + +describe('plugin-node-app', () => { + it('includes duration in event.app', done => { + const client = new Client({ apiKey: 'api_key', plugins: [plugin] }) + + client._setDelivery(client => ({ + sendEvent: payload => { + // The maximum number of milliseconds 'duration' should be + const maximum = 1000 + + expect(payload.events[0].app.duration).toBeGreaterThanOrEqual(0) + expect(payload.events[0].app.duration).toBeLessThanOrEqual(maximum) + + done() + }, + sendSession: () => {} + })) + + client.notify(new Error('acbd')) + }) +}) diff --git a/tsconfig.json b/tsconfig.json index 5463af889f..da028c7ab8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -64,6 +64,7 @@ "packages/plugin-browser-app", "packages/plugin-browser-context", "packages/plugin-browser-device", + "packages/plugin-node-app", "packages/plugin-react-native-app-state-breadcrumbs", "packages/plugin-react-native-unhandled-rejection", "packages/plugin-server-session",