Logger improvements (#7729)

* Remove enablement

* Refactor context and filtering

* Fix imports, simplify transports config

* Migrate usages of debug context

* Re-org, add colors and grouping to console logging

* Remove temp default context

* Remove manual prefix

* Move colorizing out of console transport body

* Reduce reuse

* Pass through context

* Ensure bitdrift is enabled in dev

* Enable Sentry on web only

* Clean up types

* Docs

* Format

* Update tests

* Clean up tests

* No positional args

* Revert Sentry changes

* Clean up context, use it, pass metadata through to Bitdrift

* Fix up debugging

* Clean up metadata before passing to Bitdrift

* Correct transports

* Reserve context prop on metadata and include in transports

* Update tests
This commit is contained in:
Eric Bailey
2025-02-28 12:09:36 -06:00
committed by GitHub
parent 9e9ffd5c6e
commit 7c36ea1158
27 changed files with 577 additions and 508 deletions
+14 -18
View File
@@ -3,7 +3,7 @@ import EventEmitter from 'eventemitter3'
import {nanoid} from 'nanoid/non-secure'
import {networkRetry} from '#/lib/async/retry'
import {logger} from '#/logger'
import {Logger} from '#/logger'
import {
BACKGROUND_POLL_INTERVAL,
DEFAULT_POLL_INTERVAL,
@@ -19,6 +19,7 @@ import {
import {DM_SERVICE_HEADERS} from '#/state/queries/messages/const'
const LOGGER_CONTEXT = 'MessagesEventBus'
const logger = Logger.create(Logger.Context.DMsAgent)
export class MessagesEventBus {
private id: string
@@ -90,17 +91,17 @@ export class MessagesEventBus {
}
background() {
logger.debug(`${LOGGER_CONTEXT}: background`, {}, logger.DebugContext.convo)
logger.debug(`${LOGGER_CONTEXT}: background`, {})
this.dispatch({event: MessagesEventBusDispatchEvent.Background})
}
suspend() {
logger.debug(`${LOGGER_CONTEXT}: suspend`, {}, logger.DebugContext.convo)
logger.debug(`${LOGGER_CONTEXT}: suspend`, {})
this.dispatch({event: MessagesEventBusDispatchEvent.Suspend})
}
resume() {
logger.debug(`${LOGGER_CONTEXT}: resume`, {}, logger.DebugContext.convo)
logger.debug(`${LOGGER_CONTEXT}: resume`, {})
this.dispatch({event: MessagesEventBusDispatchEvent.Resume})
}
@@ -222,19 +223,15 @@ export class MessagesEventBus {
break
}
logger.debug(
`${LOGGER_CONTEXT}: dispatch '${action.event}'`,
{
id: this.id,
prev: prevStatus,
next: this.status,
},
logger.DebugContext.convo,
)
logger.debug(`${LOGGER_CONTEXT}: dispatch '${action.event}'`, {
id: this.id,
prev: prevStatus,
next: this.status,
})
}
private async init() {
logger.debug(`${LOGGER_CONTEXT}: init`, {}, logger.DebugContext.convo)
logger.debug(`${LOGGER_CONTEXT}: init`, {})
try {
const response = await networkRetry(2, () => {
@@ -258,7 +255,7 @@ export class MessagesEventBus {
this.dispatch({event: MessagesEventBusDispatchEvent.Ready})
} catch (e: any) {
logger.error(e, {
context: `${LOGGER_CONTEXT}: init failed`,
message: `${LOGGER_CONTEXT}: init failed`,
})
this.dispatch({
@@ -327,7 +324,6 @@ export class MessagesEventBus {
// this.requestedPollIntervals.values(),
// ),
// },
// logger.DebugContext.convo,
// )
try {
@@ -372,12 +368,12 @@ export class MessagesEventBus {
this.emitter.emit('event', {type: 'logs', logs: batch})
} catch (e: any) {
logger.error(e, {
context: `${LOGGER_CONTEXT}: process latest events`,
message: `${LOGGER_CONTEXT}: process latest events`,
})
}
}
} catch (e: any) {
logger.error(e, {context: `${LOGGER_CONTEXT}: poll events failed`})
logger.error(e, {message: `${LOGGER_CONTEXT}: poll events failed`})
this.dispatch({
event: MessagesEventBusDispatchEvent.Error,