Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions packages/core/src/shared/crashMonitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import { truncateUuid } from './crypto'

const className = 'CrashMonitoring'

const logger = getLogger('crashMonitoring')

/**
* Handles crash reporting for the extension.
*
Expand Down Expand Up @@ -97,7 +99,7 @@ export class CrashMonitoring {
try {
this.#didTryCreate = true
const isDevMode = getIsDevMode()
const devModeLogger: Logger | undefined = isDevMode ? getLogger() : undefined
const devModeLogger: Logger | undefined = isDevMode ? logger : undefined
const state = await crashMonitoringStateFactory() // can throw
return (this.#instance ??= new CrashMonitoring(
state,
Expand Down Expand Up @@ -238,7 +240,7 @@ class CrashChecker {

public async start() {
{
this.devLogger?.debug(`crashMonitoring: checkInterval ${this.checkInterval}`)
this.devLogger?.debug(`checkInterval ${this.checkInterval}`)

// do an initial check
await withFailCtx('initialCrashCheck', () =>
Expand All @@ -253,7 +255,7 @@ class CrashChecker {
// Due to sleep+wake the heartbeat has not been sent consistently. Skip 1 crash check interval
// to allow for a new heartbeat to be sent
if (this.timeLag.didLag()) {
this.devLogger?.warn('crashMonitoring: LAG detected time lag and skipped a crash check')
this.devLogger?.warn('LAG detected time lag and skipped a crash check')
telemetry.function_call.emit({
className: className,
functionName: 'timeLag',
Expand Down Expand Up @@ -301,7 +303,7 @@ class CrashChecker {
// Example is if I hit the red square in the debug menu, it is a non-graceful shutdown. But the regular
// 'x' button in the Debug IDE instance is a graceful shutdown.
if (ext.isDebug) {
devLogger?.debug(`crashMonitoring: DEBUG instance crashed: %O`, ext)
devLogger?.debug(`DEBUG instance crashed: %O`, ext)
return
}

Expand All @@ -322,7 +324,7 @@ class CrashChecker {
// Sanity check: ENSURE THAT AFTER === ACTUAL or this implies that our data is out of sync
const afterActual = (await state.getAllExts()).map((i) => truncateUuid(i.sessionId))
devLogger?.debug(
`crashMonitoring: CHECKED: Result of cleaning up crashed instances\nBEFORE: %O \nAFTER: %O \nACTUAL: %O`,
`CHECKED: Result of cleaning up crashed instances\nBEFORE: %O \nAFTER: %O \nACTUAL: %O`,
before,
after,
afterActual
Expand Down Expand Up @@ -408,7 +410,7 @@ function getDefaultDependencies(): MementoStateDependencies {
isStateStale: () => isNewOsSession(),
sessionId: _getSessionId(),
isDevMode: getIsDevMode(),
devLogger: getIsDevMode() ? getLogger() : undefined,
devLogger: getIsDevMode() ? logger : undefined,
}
}
/**
Expand Down Expand Up @@ -437,8 +439,8 @@ export class FileSystemState {
constructor(protected readonly deps: MementoStateDependencies) {
this.stateDirPath = path.join(this.deps.workDirPath, crashMonitoringDirName)

this.deps.devLogger?.debug(`crashMonitoring: sessionId: ${this.deps.sessionId.slice(0, 8)}-...`)
this.deps.devLogger?.debug(`crashMonitoring: dir: ${this.stateDirPath}`)
this.deps.devLogger?.debug(`sessionId: ${this.deps.sessionId.slice(0, 8)}-...`)
this.deps.devLogger?.debug(`dir: ${this.stateDirPath}`)
}

/**
Expand Down Expand Up @@ -484,7 +486,7 @@ export class FileSystemState {
throw new CrashMonitoringError('Heartbeat write validation failed', { code: className })
}

this.deps.devLogger?.debug(`crashMonitoring: HEARTBEAT sent for ${truncateUuid(this.ext.sessionId)}`)
this.deps.devLogger?.debug(`HEARTBEAT sent for ${truncateUuid(this.ext.sessionId)}`)
}
const funcWithCtx = () => withFailCtx('sendHeartbeatState', func)
const funcWithRetries = withRetries(funcWithCtx, { maxRetries: 6, delay: 100, backoff: 2 })
Expand Down Expand Up @@ -571,10 +573,10 @@ export class FileSystemState {
return path.join(this.stateDirPath, extId + `.${this.fileSuffix}`)
}
public async clearState(): Promise<void> {
this.deps.devLogger?.debug('crashMonitoring: CLEAR_STATE: Started')
this.deps.devLogger?.debug('CLEAR_STATE: Started')
await withFailCtx('clearState', async () => {
await nodeFs.rm(this.stateDirPath, { force: true, recursive: true })
this.deps.devLogger?.debug('crashMonitoring: CLEAR_STATE: Succeeded')
this.deps.devLogger?.debug('CLEAR_STATE: Succeeded')
})
}
public async getAllExts(): Promise<ExtInstanceHeartbeat[]> {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as vscode from 'vscode'

export type LogTopic = 'crashReport' | 'dev/beta' | 'notifications' | 'test' | 'unknown'
export type LogTopic = 'crashMonitoring' | 'dev/beta' | 'notifications' | 'test' | 'unknown'

class ErrorLog {
constructor(
Expand Down
Loading