Skip to content

Commit b413437

Browse files
feat: Crash Monitoring
Signed-off-by: nkomonen-amazon <[email protected]> redid the constructors + extracted state Signed-off-by: nkomonen-amazon <[email protected]>
1 parent 5487b57 commit b413437

File tree

17 files changed

+926
-16
lines changed

17 files changed

+926
-16
lines changed

packages/amazonq/src/extensionNode.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as vscode from 'vscode'
77
import { activateAmazonQCommon, amazonQContextPrefix, deactivateCommon } from './extension'
88
import { DefaultAmazonQAppInitContext } from 'aws-core-vscode/amazonq'
99
import { activate as activateQGumby } from 'aws-core-vscode/amazonqGumby'
10-
import { ExtContext, globals } from 'aws-core-vscode/shared'
10+
import { ExtContext, globals, CrashMonitoring } from 'aws-core-vscode/shared'
1111
import { filetypes, SchemaService } from 'aws-core-vscode/sharedNode'
1212
import { updateDevMode } from 'aws-core-vscode/dev'
1313
import { CommonAuthViewProvider } from 'aws-core-vscode/login'
@@ -32,6 +32,8 @@ export async function activate(context: vscode.ExtensionContext) {
3232
* the code compatible with web and move it to {@link activateAmazonQCommon}.
3333
*/
3434
async function activateAmazonQNode(context: vscode.ExtensionContext) {
35+
await (await CrashMonitoring.instance()).start()
36+
3537
const extContext = {
3638
extensionContext: context,
3739
}
@@ -93,5 +95,6 @@ async function setupDevMode(context: vscode.ExtensionContext) {
9395
}
9496

9597
export async function deactivate() {
96-
await deactivateCommon()
98+
// Run concurrently to speed up execution. stop() does not throw so it is safe
99+
await Promise.all([(await CrashMonitoring.instance()).stop(), deactivateCommon()])
97100
}

packages/core/src/dev/activation.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { entries } from '../shared/utilities/tsUtils'
2424
import { getEnvironmentSpecificMemento } from '../shared/utilities/mementos'
2525
import { setContext } from '../shared'
2626
import { telemetry } from '../shared/telemetry'
27+
import { getSessionId } from '../shared/telemetry/util'
2728

2829
interface MenuOption {
2930
readonly label: string
@@ -108,7 +109,7 @@ const menuOptions: Record<DevFunction, MenuOption> = {
108109
},
109110
forceIdeCrash: {
110111
label: 'Crash: Force IDE ExtHost Crash',
111-
detail: `Will SIGKILL ExtHost with pid, ${process.pid}, but IDE will not crash itself.`,
112+
detail: `Will SIGKILL ExtHost, { pid: ${process.pid}, sessionId: '${getSessionId().slice(0, 8)}-...' }, but the IDE itself will not crash.`,
112113
executor: forceQuitIde,
113114
},
114115
}
@@ -222,6 +223,7 @@ function isSecrets(obj: vscode.Memento | vscode.SecretStorage): obj is vscode.Se
222223

223224
class VirtualObjectFile implements FileProvider {
224225
private mTime = 0
226+
private size = 0
225227
private readonly onDidChangeEmitter = new vscode.EventEmitter<void>()
226228
public readonly onDidChange = this.onDidChangeEmitter.event
227229

@@ -233,22 +235,24 @@ class VirtualObjectFile implements FileProvider {
233235
/** Emits an event indicating this file's content has changed */
234236
public refresh() {
235237
/**
236-
* Per {@link vscode.FileSystemProvider.onDidChangeFile}, if the mTime does not change, new file content may
237-
* not be retrieved. Without this, when we emit a change the text editor did not update.
238+
* Per {@link vscode.FileSystemProvider.onDidChangeFile}, if the mTime and/or size does not change, new file content may
239+
* not be retrieved due to optimizations. Without this, when we emit a change the text editor did not update.
238240
*/
239241
this.mTime++
240242
this.onDidChangeEmitter.fire()
241243
}
242244

243245
public stat(): { ctime: number; mtime: number; size: number } {
244246
// This would need to be filled out to track conflicts
245-
return { ctime: 0, mtime: this.mTime, size: 0 }
247+
return { ctime: 0, mtime: this.mTime, size: this.size }
246248
}
247249

248250
public async read(): Promise<Uint8Array> {
249251
const encoder = new TextEncoder()
250252

251-
return encoder.encode(await this.readStore(this.key))
253+
const data = encoder.encode(await this.readStore(this.key))
254+
this.size = data.length
255+
return data
252256
}
253257

254258
public async write(content: Uint8Array): Promise<void> {

packages/core/src/extensionNode.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import { ExtensionUse } from './auth/utils'
5959
import { ExtStartUpSources } from './shared/telemetry'
6060
import { activate as activateThreatComposerEditor } from './threatComposer/activation'
6161
import { isSsoConnection, hasScopes } from './auth/connection'
62-
import { setContext } from './shared'
62+
import { CrashMonitoring, setContext } from './shared'
6363

6464
let localize: nls.LocalizeFunc
6565

@@ -78,6 +78,8 @@ export async function activate(context: vscode.ExtensionContext) {
7878
// IMPORTANT: If you are doing setup that should also work in web mode (browser), it should be done in the function below
7979
const extContext = await activateCommon(context, contextPrefix, false)
8080

81+
await (await CrashMonitoring.instance()).start()
82+
8183
initializeCredentialsProviderManager()
8284

8385
const toolkitEnvDetails = getExtEnvironmentDetails()
@@ -251,7 +253,8 @@ export async function activate(context: vscode.ExtensionContext) {
251253
}
252254

253255
export async function deactivate() {
254-
await deactivateCommon()
256+
// Run concurrently to speed up execution. stop() does not throw so it is safe
257+
await Promise.all([await (await CrashMonitoring.instance()).stop(), deactivateCommon()])
255258
await globals.resourceManager.dispose()
256259
}
257260

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
// Needed here due to circular dependency issues
7+
export const rootDir = 'crashMonitoring'
8+
export const runningExtDir = 'runningExts'
9+
export const shutdownExtDir = 'shutdownExts'

0 commit comments

Comments
 (0)