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

V7: Rename autoCaptureSessions -> autoTrackSessions and simplify validation logic #647

Merged
merged 2 commits into from
Nov 15, 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
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)

## 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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default value has not been updated in this PR, this comment was out of date.

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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config schema now validates that endpoints.sessions must now be defined so this branch of code is obsolete.

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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, commenting here too for an equivalent change… the config schema now validates that endpoints.sessions must now be defined so this branch of code is obsolete.

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' },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loads of the end-to-end tests that relied on being allowed to not set a custom session endpoint now need some value to satisfy the config validation, but all of these tests only make assertions about errors.

I've set it to this value here (and many other places), which hopefully which suggests it's not used at all to appease the config validation.

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 (report) {
report.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 (report) {
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 (report) {
report.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