Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node): add Node version to report #537

Merged
merged 6 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## TBD

### Changed

- (node): Added Node version string to report and session payloads (device.runtimeVersions) [#537](https://github.com/bugsnag/bugsnag-js/pull/537)

## 6.2.0 (2019-04-23)

This release adds [`@bugsnag/expo`](http://docs.bugsnag.com/platforms/react-native/expo), a notifier for use on React Native apps that are built using [Expo](https://expo.io/).
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-node-device/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @bugsnag/plugin-browser-node

This plugin adds the device time and hostname to the `device` section of each error report, and the hostname to session payloads. It is included in the node notifier.
This plugin adds the device time, hostname and Node version to the `device` section of each error report. It is included in the node notifier.

## License
MIT
6 changes: 4 additions & 2 deletions packages/plugin-node-device/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ const { isoDate } = require('@bugsnag/core/lib/es-utils')
*/
module.exports = {
init: (client) => {
const device = { hostname: client.config.hostname }
const device = {
hostname: client.config.hostname,
runtimeVersions: { node: process.versions.node }
}

// merge with anything already set on the client
client.device = { ...device, ...client.device }

// add time just as the report is sent
client.config.beforeSend.unshift((report) => {
report.device = { ...report.device, time: isoDate() }
report.updateMetaData('device', { runtimeVersions: process.versions })
})
}
}
19 changes: 3 additions & 16 deletions packages/plugin-node-device/test/device.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ const VALID_NOTIFIER = { name: 't', version: '0', url: 'http://' }
const ISO_8601 = /^\d{4}(-\d\d(-\d\d(T\d\d:\d\d(:\d\d)?(\.\d+)?(([+-]\d\d:\d\d)|Z)?)?)?)?$/i

describe('plugin: node device', () => {
it('should set device = { hostname } and add a beforeSend callback which adds device time', done => {
it('should set device = { hostname, runtimeVersions } add a beforeSend callback which adds device time', done => {
const client = new Client(VALID_NOTIFIER)
client.setOptions({ apiKey: 'API_KEY_YEAH' })
client.configure(schema)
client.use(plugin)

expect(client.config.beforeSend.length).toBe(1)
expect(client.device.hostname).toBe('test-machine.local')
expect(client.device.runtimeVersions).toBeDefined()
expect(client.device.runtimeVersions.node).toEqual(process.versions.node)

client.delivery(client => ({
sendReport: (payload) => {
Expand All @@ -33,19 +35,4 @@ describe('plugin: node device', () => {
}))
client.notify(new Error('noooo'))
})

it('should attach the process.versions hash', done => {
const client = new Client(VALID_NOTIFIER)
client.setOptions({ apiKey: 'API_KEY_YEAH' })
client.configure(schema)
client.use(plugin)

client.delivery(client => ({
sendReport: (payload) => {
expect(payload.events[0].metaData.device.runtimeVersions).toEqual(process.versions)
done()
}
}))
client.notify(new Error('noooo'))
})
})
5 changes: 3 additions & 2 deletions packages/plugin-server-session/test/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,16 @@ describe('plugin: server sessions', () => {
})

// this is normally set by a plugin
c.device = { hostname: 'test-machine.local' }
c.device = { hostname: 'test-machine.local', runtimeVersions: { node: '0.0.1' } }

c.delivery(client => ({
sendReport: () => {},
sendSession: (session, cb = () => {}) => {
expect(session.sessionCounts.length).toBe(1)
expect(session.sessionCounts[0].sessionsStarted).toBe(123)
expect(session.app).toEqual({ version: '1.2.3', releaseStage: 'qa', type: 'server' })
expect(session.device).toEqual({ hostname: 'test-machine.local' })
expect(session.device.hostname).toBe('test-machine.local')
expect(session.device.runtimeVersions.node).toBe('0.0.1')
done()
}
}))
Expand Down