Commit d64b66db authored by Annie Ke's avatar Annie Ke Committed by GitHub

feat: add sentry error context (#612)

* feat: add sentry error context

* remove white space and changeset

* add back stackAttributeKey and remove unused logger functions
parent ea4041ba
---
"@eth-optimism/batch-submitter": patch
"@eth-optimism/core-utils": patch
---
reformat error context for Sentry
......@@ -100,7 +100,7 @@ export abstract class BatchSubmitter {
})
if (num < this.minBalanceEther) {
this.log.warn('Current balance lower than min safe balance', {
this.log.fatal('Current balance lower than min safe balance', {
current: num,
safeBalance: this.minBalanceEther,
})
......
......@@ -21,8 +21,6 @@ const log = new Logger({
name,
sentryOptions: {
release: `batch-submitter@${process.env.npm_package_version}`,
// @ts-ignore stackAttributeKey belongs to PinoSentryOptions, not exported
stackAttributeKey: 'err',
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 0.05,
},
......
......@@ -35,7 +35,10 @@ export class Logger {
if (options.sentryOptions) {
loggerStreams.push({
level: 'error',
stream: createWriteStream(options.sentryOptions),
stream: createWriteStream({
...options.sentryOptions,
stackAttributeKey: 'err',
}),
})
}
if (options.streams) loggerStreams = loggerStreams.concat(options.streams)
......@@ -92,7 +95,11 @@ export class Logger {
error(msg: string, o?: object, ...args: any[]): void {
if (o) {
this.inner.error(o, msg, ...args)
// Formatting error log for Sentry
const context = {
extra: { ...o },
}
this.inner.error(context, msg, ...args)
} else {
this.inner.error(msg, ...args)
}
......@@ -100,23 +107,10 @@ export class Logger {
fatal(msg: string, o?: object, ...args: any[]): void {
if (o) {
this.inner.fatal(o, msg, ...args)
} else {
this.inner.fatal(msg, ...args)
}
}
crit(msg: string, o?: object, ...args: any[]): void {
if (o) {
this.inner.fatal(o, msg, ...args)
} else {
this.inner.fatal(msg, ...args)
const context = {
extra: { ...o },
}
}
critical(msg: string, o?: object, ...args: any[]): void {
if (o) {
this.inner.fatal(o, msg, ...args)
this.inner.fatal(context, msg, ...args)
} else {
this.inner.fatal(msg, ...args)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment