Skip to content

Commit 72bd7f5

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 5a5b0b4 commit 72bd7f5

File tree

14 files changed

+925
-17
lines changed

14 files changed

+925
-17
lines changed

packages/amazonq/src/extensionNode.ts

Lines changed: 8 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, env, 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,11 @@ 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+
// Do not run in tests since this corrupts the telemetry we try and assert
36+
if (!env.isAutomation()) {
37+
await (await CrashMonitoring.instance()).start()
38+
}
39+
3540
const extContext = {
3641
extensionContext: context,
3742
}
@@ -93,5 +98,6 @@ async function setupDevMode(context: vscode.ExtensionContext) {
9398
}
9499

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

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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { SchemaService } from './shared/schemas'
4646
import { AwsResourceManager } from './dynamicResources/awsResourceManager'
4747
import globals from './shared/extensionGlobals'
4848
import { Experiments, Settings, showSettingsFailedMsg } from './shared/settings'
49-
import { isReleaseVersion } from './shared/vscode/env'
49+
import { isAutomation, isReleaseVersion } from './shared/vscode/env'
5050
import { telemetry } from './shared/telemetry/telemetry'
5151
import { Auth, SessionSeparationPrompt } from './auth/auth'
5252
import { registerSubmitFeedback } from './feedback/vue/submitFeedback'
@@ -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,11 @@ 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+
// Do not run in tests since this corrupts the telemetry we try and assert
82+
if (!isAutomation()) {
83+
await (await CrashMonitoring.instance()).start()
84+
}
85+
8186
initializeCredentialsProviderManager()
8287

8388
const toolkitEnvDetails = getExtEnvironmentDetails()
@@ -251,7 +256,8 @@ export async function activate(context: vscode.ExtensionContext) {
251256
}
252257

253258
export async function deactivate() {
254-
await deactivateCommon()
259+
// Run concurrently to speed up execution. stop() does not throw so it is safe
260+
await Promise.all([await (await CrashMonitoring.instance()).stop(), deactivateCommon()])
255261
await globals.resourceManager.dispose()
256262
}
257263

0 commit comments

Comments
 (0)