chore: add more context to honeybadger errors
parent
63b8129188
commit
a05bd3ec39
|
|
@ -2,6 +2,7 @@
|
|||
import {Dispatch} from 'redux'
|
||||
import {ThunkAction} from 'redux-thunk'
|
||||
import {push, RouterAction} from 'react-router-redux'
|
||||
import HoneyBadger from 'honeybadger-js'
|
||||
|
||||
// APIs
|
||||
import {getErrorMessage} from 'src/utils/api'
|
||||
|
|
@ -80,6 +81,9 @@ export interface SetOrg {
|
|||
}
|
||||
|
||||
export const setOrg = (org: Organization): SetOrg => {
|
||||
HoneyBadger.setContext({
|
||||
orgID: org.id,
|
||||
})
|
||||
return {
|
||||
type: ActionTypes.SetOrg,
|
||||
payload: {org},
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {MeState} from 'src/shared/reducers/me'
|
||||
import {client} from 'src/utils/api'
|
||||
import HoneyBadger from 'honeybadger-js'
|
||||
|
||||
export enum ActionTypes {
|
||||
SetMe = 'SET_ME',
|
||||
|
|
@ -25,8 +26,12 @@ export const getMe = () => async dispatch => {
|
|||
try {
|
||||
const user = await client.users.me()
|
||||
|
||||
HoneyBadger.setContext({
|
||||
user_id: user.id,
|
||||
})
|
||||
|
||||
dispatch(setMe(user))
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import {ErrorInfo} from 'react'
|
|||
import HoneyBadger from 'honeybadger-js'
|
||||
import {CLOUD, GIT_SHA} from 'src/shared/constants'
|
||||
|
||||
import {getUserFlags} from 'src/shared/utils/featureFlag'
|
||||
|
||||
if (CLOUD) {
|
||||
HoneyBadger.configure({
|
||||
apiKey: process.env.HONEYBADGER_KEY,
|
||||
|
|
@ -10,18 +12,44 @@ if (CLOUD) {
|
|||
})
|
||||
}
|
||||
|
||||
interface AdditionalOptions {
|
||||
// See https://docs.honeybadger.io/lib/javascript/guides/reporting-errors.html#additional-options
|
||||
interface HoneyBadgerAdditionalOptions {
|
||||
component?: string
|
||||
context?: {[key: string]: any}
|
||||
cookies?: {[key: string]: any}
|
||||
name?: string
|
||||
params?: {[key: string]: any}
|
||||
}
|
||||
|
||||
export const reportError = (
|
||||
error: Error,
|
||||
additionalOptions?: AdditionalOptions
|
||||
additionalOptions?: HoneyBadgerAdditionalOptions
|
||||
): void => {
|
||||
let additionalContext = {}
|
||||
if (additionalOptions && additionalOptions.context) {
|
||||
additionalContext = {...additionalOptions.context}
|
||||
}
|
||||
|
||||
const context = {
|
||||
...additionalContext,
|
||||
...getUserFlags(),
|
||||
}
|
||||
|
||||
let options: HoneyBadgerAdditionalOptions = {}
|
||||
if (additionalOptions) {
|
||||
options = {...additionalOptions}
|
||||
|
||||
delete options.context // already included in the above context object
|
||||
}
|
||||
|
||||
if (CLOUD) {
|
||||
HoneyBadger.notify(error, additionalOptions)
|
||||
HoneyBadger.notify(error, {context, ...options})
|
||||
} else {
|
||||
const honeyBadgerContext = (HoneyBadger as any).context
|
||||
/* eslint-disable no-console */
|
||||
console.log('Context that would have been sent to HoneyBadger:')
|
||||
console.table({...honeyBadgerContext, ...context, ...options})
|
||||
/* eslint-enable no-console */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue