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 { ...@@ -100,7 +100,7 @@ export abstract class BatchSubmitter {
}) })
if (num < this.minBalanceEther) { 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, current: num,
safeBalance: this.minBalanceEther, safeBalance: this.minBalanceEther,
}) })
......
...@@ -21,8 +21,6 @@ const log = new Logger({ ...@@ -21,8 +21,6 @@ const log = new Logger({
name, name,
sentryOptions: { sentryOptions: {
release: `batch-submitter@${process.env.npm_package_version}`, release: `batch-submitter@${process.env.npm_package_version}`,
// @ts-ignore stackAttributeKey belongs to PinoSentryOptions, not exported
stackAttributeKey: 'err',
dsn: process.env.SENTRY_DSN, dsn: process.env.SENTRY_DSN,
tracesSampleRate: 0.05, tracesSampleRate: 0.05,
}, },
......
...@@ -35,7 +35,10 @@ export class Logger { ...@@ -35,7 +35,10 @@ export class Logger {
if (options.sentryOptions) { if (options.sentryOptions) {
loggerStreams.push({ loggerStreams.push({
level: 'error', level: 'error',
stream: createWriteStream(options.sentryOptions), stream: createWriteStream({
...options.sentryOptions,
stackAttributeKey: 'err',
}),
}) })
} }
if (options.streams) loggerStreams = loggerStreams.concat(options.streams) if (options.streams) loggerStreams = loggerStreams.concat(options.streams)
...@@ -92,7 +95,11 @@ export class Logger { ...@@ -92,7 +95,11 @@ export class Logger {
error(msg: string, o?: object, ...args: any[]): void { error(msg: string, o?: object, ...args: any[]): void {
if (o) { if (o) {
this.inner.error(o, msg, ...args) // Formatting error log for Sentry
const context = {
extra: { ...o },
}
this.inner.error(context, msg, ...args)
} else { } else {
this.inner.error(msg, ...args) this.inner.error(msg, ...args)
} }
...@@ -100,23 +107,10 @@ export class Logger { ...@@ -100,23 +107,10 @@ export class Logger {
fatal(msg: string, o?: object, ...args: any[]): void { fatal(msg: string, o?: object, ...args: any[]): void {
if (o) { if (o) {
this.inner.fatal(o, msg, ...args) const context = {
} else { extra: { ...o },
this.inner.fatal(msg, ...args) }
} this.inner.fatal(context, msg, ...args)
}
crit(msg: string, o?: object, ...args: any[]): void {
if (o) {
this.inner.fatal(o, msg, ...args)
} else {
this.inner.fatal(msg, ...args)
}
}
critical(msg: string, o?: object, ...args: any[]): void {
if (o) {
this.inner.fatal(o, msg, ...args)
} else { } else {
this.inner.fatal(msg, ...args) 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