Skip to content

Commit

Permalink
Merge branch 'v7' into v7-rename-report-event
Browse files Browse the repository at this point in the history
  • Loading branch information
bengourley committed Nov 15, 2019
2 parents 9b1873f + 775576a commit 5aa3bf2
Show file tree
Hide file tree
Showing 72 changed files with 99 additions and 120 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## TBD

- Migrate lint tooling to ESLint for both .js and .ts source files [#644](https://github.com/bugsnag/bugsnag-js/pull/644)
- Rename `autoCaptureSessions` -> `autoTrackSessions` and simplify validation logic [#647](https://github.com/bugsnag/bugsnag-js/pull/647)
- Rename `report` to `event` [#646](https://github.com/bugsnag/bugsnag-js/pull/646)

## 6.4.3 (2019-10-21)
Expand Down
4 changes: 2 additions & 2 deletions examples/browser-cdn/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ var bugsnagClient = bugsnag({
appVersion: '1.2.3',

// Bugsnag can track the number of “sessions” that happen in your application,
// and calculate a crash rate for each release. This defaults to false.
autoCaptureSessions: true,
// and calculate a crash rate for each release. This defaults to true.
autoTrackSessions: true,

// defines the release stage for all events that occur in this app.
releaseStage: 'development',
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = (opts) => {

bugsnag._logger.debug('Loaded!')

return bugsnag.config.autoCaptureSessions
return bugsnag.config.autoTrackSessions
? bugsnag.startSession()
: bugsnag
}
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/types/bugsnag.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare module "@bugsnag/core" {
appVersion?: string;
appType?: string;
endpoints?: { notify: string; sessions?: string };
autoCaptureSessions?: boolean;
autoTrackSessions?: boolean;
notifyReleaseStages?: string[];
releaseStage?: string;
maxBreadcrumbs?: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/types/test/fixtures/all-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ bugsnag({
autoNotify: true,
beforeSend: [],
endpoints: {"notify":"https://notify.bugsnag.com","sessions":"https://sessions.bugsnag.com"},
autoCaptureSessions: true,
autoTrackSessions: true,
notifyReleaseStages: [],
releaseStage: "production",
maxBreadcrumbs: 20,
Expand Down
14 changes: 6 additions & 8 deletions packages/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,19 @@ module.exports.schema = {
notify: 'https://notify.bugsnag.com',
sessions: 'https://sessions.bugsnag.com'
}),
message: 'should be an object containing endpoint URLs { notify, sessions }. sessions is optional if autoCaptureSessions=false',
validate: (val, obj) =>
message: 'should be an object containing endpoint URLs { notify, sessions }',
validate: val =>
// first, ensure it's an object
(val && typeof val === 'object') &&
(
// endpoints.notify must always be set
stringWithLength(val.notify) &&
// endpoints.sessions must be set unless session tracking is explicitly off
(obj.autoCaptureSessions === false || stringWithLength(val.sessions))
// notify and sessions must always be set
stringWithLength(val.notify) && stringWithLength(val.sessions)
) &&
// ensure no keys other than notify/session are set on endpoints object
filter(keys(val), k => !includes(['notify', 'sessions'], k)).length === 0
},
autoCaptureSessions: {
defaultValue: (val, opts) => opts.endpoints === undefined || (!!opts.endpoints && !!opts.endpoints.sessions),
autoTrackSessions: {
defaultValue: val => true,
message: 'should be true|false',
validate: val => val === true || val === false
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/types/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export interface Config {
autoNotify?: boolean;
appVersion?: string;
appType?: string;
endpoints?: { notify: string; sessions?: string };
autoCaptureSessions?: boolean;
endpoints?: { notify: string; sessions: string };
autoTrackSessions?: boolean;
notifyReleaseStages?: string[];
releaseStage?: string;
maxBreadcrumbs?: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/src/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = (opts) => {

bugsnag._logger.debug('Loaded!')

return bugsnag.config.autoCaptureSessions
return bugsnag.config.autoTrackSessions
? bugsnag.startSession()
: bugsnag
}
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/types/bugsnag.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare module "@bugsnag/core" {
appVersion?: string;
appType?: string;
endpoints?: { notify: string; sessions?: string };
autoCaptureSessions?: boolean;
autoTrackSessions?: boolean;
notifyReleaseStages?: string[];
releaseStage?: string;
maxBreadcrumbs?: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/expo/types/test/fixtures/all-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ bugsnag({
autoNotify: true,
beforeSend: [],
endpoints: {"notify":"https://notify.bugsnag.com","sessions":"https://sessions.bugsnag.com"},
autoCaptureSessions: true,
autoTrackSessions: true,
notifyReleaseStages: [],
releaseStage: "production",
maxBreadcrumbs: 20,
Expand Down
2 changes: 1 addition & 1 deletion packages/node/types/bugsnag.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ declare module "@bugsnag/core" {
appVersion?: string;
appType?: string;
endpoints?: { notify: string; sessions?: string };
autoCaptureSessions?: boolean;
autoTrackSessions?: boolean;
notifyReleaseStages?: string[];
releaseStage?: string;
maxBreadcrumbs?: number;
Expand Down
5 changes: 0 additions & 5 deletions packages/plugin-browser-session/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ const sessionDelegate = {
return sessionClient
}

if (!sessionClient.config.endpoints.sessions) {
sessionClient._logger.warn('Session not sent due to missing endpoints.sessions configuration')
return sessionClient
}

sessionClient._delivery.sendSession({
notifier: sessionClient.notifier,
device: sessionClient.device,
Expand Down
21 changes: 5 additions & 16 deletions packages/plugin-browser-session/test/session.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,16 @@ describe('plugin: sessions', () => {
setTimeout(done, 150)
})

it('logs a warning when no session endpoint is set', (done) => {
it('rejects config when session endpoint is not set', () => {
const c = new Client(VALID_NOTIFIER)
c.setOptions({
apiKey: 'API_KEY',
releaseStage: 'foo',
endpoints: { notify: '/foo' },
autoCaptureSessions: false
autoTrackSessions: false
})
c.configure()
c.use(plugin)
c.logger({
warn: msg => {
expect(msg).toMatch(/session not sent/i)
done()
}
})
c.delivery(client => ({
sendSession: (session, cb) => {
expect(true).toBe(false)
}
}))
c.startSession()
expect(() => c.configure()).toThrowError(
/"endpoints" should be an object containing endpoint URLs { notify, sessions }/
)
})
})
2 changes: 1 addition & 1 deletion packages/plugin-express/src/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {

// Get a client to be scoped to this request. If sessions are enabled, use the
// startSession() call to get a session client, otherwise, clone the existing client.
const requestClient = client.config.autoCaptureSessions ? client.startSession() : clone(client)
const requestClient = client.config.autoTrackSessions ? client.startSession() : clone(client)

// attach it to the request
req.bugsnag = requestClient
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-koa/src/koa.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
const requestHandler = async (ctx, next) => {
// Get a client to be scoped to this request. If sessions are enabled, use the
// startSession() call to get a session client, otherwise, clone the existing client.
const requestClient = client.config.autoCaptureSessions ? client.startSession() : clone(client)
const requestClient = client.config.autoTrackSessions ? client.startSession() : clone(client)

ctx.bugsnag = requestClient

Expand Down Expand Up @@ -46,7 +46,7 @@ module.exports = {
requestHandler.v1 = function * (next) {
// Get a client to be scoped to this request. If sessions are enabled, use the
// startSession() call to get a session client, otherwise, clone the existing client.
const requestClient = client.config.autoCaptureSessions ? client.startSession() : clone(client)
const requestClient = client.config.autoTrackSessions ? client.startSession() : clone(client)

this.bugsnag = requestClient

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const wrapHistoryFn = (client, target, fn, win) => {
// if throttle plugin is in use, refresh the event sent count
if (typeof client.refresh === 'function') client.refresh()
// if the client is operating in auto session-mode, a new route should trigger a new session
if (client.config.autoCaptureSessions) client.startSession()
if (client.config.autoTrackSessions) client.startSession()
// Internet Explorer will convert `undefined` to a string when passed, causing an unintended redirect
// to '/undefined'. therefore we only pass the url if it's not undefined.
orig.apply(target, [state, title].concat(url !== undefined ? url : []))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('plugin: navigation breadcrumbs', () => {
expect(c.breadcrumbs.length).toBe(0)
})

it('should start a new session if autoCaptureSessions=true', (done) => {
it('should start a new session if autoTrackSessions=true', (done) => {
const c = new Client(VALID_NOTIFIER)
c.setOptions({ apiKey: 'aaaa-aaaa-aaaa-aaaa' })
c.configure()
Expand All @@ -63,9 +63,9 @@ describe('plugin: navigation breadcrumbs', () => {
window.history.replaceState({}, 'bar', 'network-breadcrumb-test.html')
})

it('should not a new session if autoCaptureSessions=false', (done) => {
it('should not a new session if autoTrackSessions=false', (done) => {
const c = new Client(VALID_NOTIFIER)
c.setOptions({ apiKey: 'aaaa-aaaa-aaaa-aaaa', autoCaptureSessions: false })
c.setOptions({ apiKey: 'aaaa-aaaa-aaaa-aaaa', autoTrackSessions: false })
c.configure()
c.sessionDelegate({
startSession: client => {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-restify/src/restify.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {

// Get a client to be scoped to this request. If sessions are enabled, use the
// startSession() call to get a session client, otherwise, clone the existing client.
const requestClient = client.config.autoCaptureSessions ? client.startSession() : clone(client)
const requestClient = client.config.autoTrackSessions ? client.startSession() : clone(client)

// attach it to the request
req.bugsnag = requestClient
Expand Down
5 changes: 0 additions & 5 deletions packages/plugin-server-session/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ const sendSessionSummary = client => sessionCounts => {
return
}

if (!client.config.endpoints.sessions) {
client._logger.warn('Session not sent due to missing endpoints.sessions configuration')
return
}

if (!sessionCounts.length) return

const backoff = new Backoff({ min: 1000, max: 10000 })
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/auto_notify/script/a.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT },
endpoints: { notify: ENDPOINT, sessions: '/noop' },
autoNotify: false
})
</script>
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/before_send/script/a.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT },
endpoints: { notify: ENDPOINT, sessions: '/noop' },
beforeSend: function (event) {
event.updateMetaData('before_send', 'global', 'works')
}
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/before_send/script/b.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT },
endpoints: { notify: ENDPOINT, sessions: '/noop' },
beforeSend: function (event) {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/before_send/script/c.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT },
endpoints: { notify: ENDPOINT, sessions: '/noop' },
beforeSend: function (event) {
event.ignore()
}
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/before_send/script/d.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT }
endpoints: { notify: ENDPOINT, sessions: '/noop' }
})
</script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/before_send/script/e.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT }
endpoints: { notify: ENDPOINT, sessions: '/noop' }
})
</script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/before_send/script/f.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT }
endpoints: { notify: ENDPOINT, sessions: '/noop' }
})
</script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/filters/script/a.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT },
endpoints: { notify: ENDPOINT, sessions: '/noop' },
})
</script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/filters/script/b.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT },
endpoints: { notify: ENDPOINT, sessions: '/noop' },
filters: [ 'api_key', 'secret' ]
})
</script>
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/filters/script/c.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT },
endpoints: { notify: ENDPOINT, sessions: '/noop' },
filters: [ 'stacktrace', 'secret' ]
})
</script>
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/filters/script/d.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT },
endpoints: { notify: ENDPOINT, sessions: '/noop' },
filters: [ /details\d/ ]
})
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ var ENDPOINT = decodeURIComponent(window.location.search.match(/ENDPOINT=([^&]+)
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])

exports.apiKey = API_KEY
exports.endpoints = { notify: ENDPOINT }
exports.endpoints = { notify: ENDPOINT, sessions: '/noop' }
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ var ENDPOINT = decodeURIComponent(window.location.search.match(/ENDPOINT=([^&]+)
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])

exports.apiKey = API_KEY
exports.endpoints = { notify: ENDPOINT }
exports.endpoints = { notify: ENDPOINT, sessions: '/noop' }
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/handled/script/a.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT }
endpoints: { notify: ENDPOINT, sessions: '/noop' }
})
</script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/handled/script/b.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT }
endpoints: { notify: ENDPOINT, sessions: '/noop' }
})
</script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/handled/script/c.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT }
endpoints: { notify: ENDPOINT, sessions: '/noop' }
})
</script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/handled/script/d.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT }
endpoints: { notify: ENDPOINT, sessions: '/noop' }
})
</script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion test/browser/features/fixtures/handled/script/e.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
var bugsnagClient = bugsnag({
apiKey: API_KEY,
endpoints: { notify: ENDPOINT }
endpoints: { notify: ENDPOINT, sessions: '/noop' }
})
</script>
</head>
Expand Down
Loading

0 comments on commit 5aa3bf2

Please sign in to comment.