Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.init = (client) => {
const isDev = /^dev(elopment)?$/.test(client.config.releaseStage)
const explicitlyDisabled = client.config.consoleBreadcrumbsEnabled === false
const implicitlyDisabled = (client.config.autoBreadcrumbs === false || isDev) && client.config.consoleBreadcrumbsEnabled !== true
if (explicitlyDisabled || implicitlyDisabled) return
map(CONSOLE_LOG_METHODS, method => {
const original = console[method]
console[method] = (...args) => {
client.leaveBreadcrumb('Console output', reduce(args, (accum, arg, i) => {
// do the best/simplest stringification of each argument
let stringified = '[Unknown value]'
// this may fail if the input is:
// - an object whose [[Prototype]] is null (no toString)
// - an object with a broken toString or @@toPrimitive implementation
try { stringified = String(arg) } catch (e) {}
// if it stringifies to [object Object] attempt to JSON stringify
if (stringified === '[object Object]') {
// catch stringify errors and fallback to [object Object]
try { stringified = JSON.stringify(arg) } catch (e) {}
}
accum[`[${i}]`] = stringified
return accum
init: client => client.config.beforeSend.push(report => {
if (!client.config.projectRoot) return
const projectRoot = normalizePath(client.config.projectRoot)
report.stacktrace = map(report.stacktrace, stackframe => {
stackframe.inProject = typeof stackframe.file === 'string' &&
stackframe.file.indexOf(projectRoot) === 0 &&
!/\/node_modules\//.test(stackframe.file)
return stackframe
})
})
}
init: client => client.config.beforeSend.push(report => {
if (!client.config.projectRoot) return
const projectRoot = normalizePath(client.config.projectRoot)
report.stacktrace = map(report.stacktrace, stackframe => {
if (typeof stackframe.file === 'string' && stackframe.file.indexOf(projectRoot) === 0) {
stackframe.file = stackframe.file.replace(projectRoot, '')
}
return stackframe
})
})
}
client.config.beforeSend.push(report => {
report.stacktrace = map(report.stacktrace, frame => ({ ...frame, file: strip(frame.file) }))
})
}