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
1 change: 1 addition & 0 deletions extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"aspire-vscode.strings.invalidTokenLength": "Invalid token length in Authorization header.",
"aspire-vscode.strings.authorizationHeaderMustStartWithBearer": "Authorization header must start with 'Bearer '.",
"aspire-vscode.strings.authorizationAndDcpHeadersRequired": "Authorization and Microsoft-Developer-DCP-Instance-ID headers are required.",
"aspire-vscode.strings.authorizationHeaderRequired": "Authorization header is required.",
"aspire-vscode.strings.buildFailedForProjectWithError": "Build failed for project {0} with error: {1}.",
"aspire-vscode.strings.failedToInspectRuntimeConfig": "Failed to inspect runtimeconfig for {0}: {1}",
"aspire-vscode.strings.dotNetRunFallbackDisablesDebugger": "Project output {0} is not directly runnable; launching {1} with dotnet run without debugger attach. Breakpoints will not be hit for this resource.",
Expand Down
2 changes: 1 addition & 1 deletion extension/src/commands/do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { enterPipelineStep } from '../loc/strings';
export async function doCommand(terminalProvider: AspireTerminalProvider, editorCommandProvider: AspireEditorCommandProvider) {
const step = await resolveStep(terminalProvider);
if (step === undefined) {
return;
throw new vscode.CancellationError();
}
await editorCommandProvider.tryExecuteDoAppHost(false, step ?? undefined);
}
Expand Down
379 changes: 355 additions & 24 deletions extension/src/dcp/AspireDcpServer.ts

Large diffs are not rendered by default.

1,099 changes: 1,099 additions & 0 deletions extension/src/dcp/DashboardTelemetryPassthrough.ts

Large diffs are not rendered by default.

80 changes: 79 additions & 1 deletion extension/src/debugger/AspireDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { ICliRpcClient } from "../server/rpcClient";
import path from "path";
import os from "os";
import { EnvironmentVariables } from "../utils/environment";
import { sendTelemetryEvent } from "../utils/telemetry";
import { classifyAppHostPath, classifyAppHostDirectory } from "../utils/appHostLanguage";

export type DashboardBrowserType = 'openExternalBrowser' | 'integratedBrowser' | 'debugChrome' | 'debugEdge' | 'debugFirefox';

Expand All @@ -39,6 +41,16 @@ export class AspireDebugSession implements vscode.DebugAdapter {
private _dashboardDebugSession: vscode.DebugSession | null = null;
private readonly _disposables: vscode.Disposable[] = [];
private _disposed = false;
// Timestamp for the `debug/appHost/end` duration measurement. Captured the first
// time we observe a `launch` request so it covers the actual user-visible session
// lifetime, not the moment the AspireDebugSession object was constructed.
private _appHostStartTimeMs: number | undefined = undefined;
// Tracks the AppHost-language classification of the launched program so it can
// be repeated on the matching end event without re-deriving from `configuration`.
private _appHostLanguageAtLaunch: 'csharp' | 'typescript' | 'unknown' = 'unknown';
// Mode the AppHost was launched with (`run` | `debug`) — captured for the
// matching end event.
private _appHostModeAtLaunch: 'run' | 'debug' = 'run';

public readonly onDidSendMessage = this._onDidSendMessage.event;
public readonly debugSessionId: string;
Expand Down Expand Up @@ -90,6 +102,30 @@ export class AspireDebugSession implements vscode.DebugAdapter {
const appHostIsDirectory = isDirectory(appHostPath);
const extensionArgs: string[] = [];

// Telemetry: emit `debug/appHost/start` once per AppHost launch. We do it
// here (rather than in the constructor) because the constructor runs
// before VS Code's debug-launch UX completes; this branch is the single
// entry point that triggers an actual CLI spawn. The matching end event
// is emitted from dispose().
this._appHostStartTimeMs = Date.now();
this._appHostLanguageAtLaunch = appHostIsDirectory
? classifyAppHostDirectory(appHostPath)
: classifyAppHostPath(appHostPath);
this._appHostModeAtLaunch = noDebug ? 'run' : 'debug';
// `command` originates in the user's launch.json and is typed in the
// contributing extension surface as AspireCommandType ('run'|'deploy'|
// 'publish'|'do'), but launch.json is freeform JSON — a typo or custom
// value would otherwise leak verbatim into telemetry. Clamp to the known
// set so the dimension stays bounded.
const knownCommands: ReadonlySet<string> = new Set(['run', 'deploy', 'publish', 'do']);
const commandForTelemetry = knownCommands.has(command) ? command : 'other';
sendTelemetryEvent('debug/appHost/start', {
mode: this._appHostModeAtLaunch,
apphost_language: this._appHostLanguageAtLaunch,
apphost_is_directory: appHostIsDirectory ? 'true' : 'false',
command: commandForTelemetry,
});

// For 'do' with an explicit step (old CLI fallback), pass it as a positional argument
const step = this.configuration.step;
if (command === 'do' && step && commandArgs.length === 0) {
Expand Down Expand Up @@ -219,6 +255,7 @@ export class AspireDebugSession implements vscode.DebugAdapter {
vscode.window.showErrorMessage(processExceptionOccurred(error.message, commandLabel));
},
exitCallback: (code) => {
this._dcpServer.recordAppHostProcessExit(this.debugSessionId, code);
// Flush any partial line left in either buffer so trailing output isn't lost.
if (stdoutBuffer.length > 0) {
flushBuffer(stdoutBuffer, 'stdout');
Expand Down Expand Up @@ -510,9 +547,50 @@ export class AspireDebugSession implements vscode.DebugAdapter {
}
this._disposed = true;
extensionLogOutputChannel.info('Stopping the Aspire debug session');
vscode.debug.stopDebugging(this._session);

// Snapshot start-event metadata before we run disposables so the deferred
// `debug/appHost/end` callback has a stable view even if instance state
// mutates further (or the instance is reaped by VS Code before the timer
// fires).
const startMs = this._appHostStartTimeMs;
const mode = this._appHostModeAtLaunch;
const language = this._appHostLanguageAtLaunch;
const debugSessionId = this.debugSessionId;
const dcpServer = this._dcpServer;

// Stop child debug sessions first so their `sessionTerminated`
// notifications can flow back through `AspireDcpServer.sendNotification`
// and update the aggregate stats BEFORE we snapshot them for
// `debug/appHost/end`. Without this ordering, late nonzero exits (notably
// Windows' SIGTERM → 143 exit code which is not normalized to 0) would
// be missed and the summary would under-report failures.
this._disposables.forEach(disposable => disposable.dispose());
this._trackedDebugAdapters = [];
vscode.debug.stopDebugging(this._session);

// Telemetry: emit `debug/appHost/end` after a short grace window so any
// pending `sessionTerminated` notifications kicked off by the child-stop
// disposables above have time to flow through the adapterTracker → DCP
// notification pipeline and update `anyNonZeroExit`. 500ms is enough for
// the common case under normal load while keeping the bound short enough
// to survive most extension teardown scenarios. We only fire the event if
// `launch` ever ran — otherwise we'd be reporting a phantom session for
// AppHosts that aborted before reaching the CLI spawn.
if (startMs !== undefined) {
setTimeout(() => {
const aggregate = dcpServer.takeDebugSessionAggregateStats(debugSessionId);
sendTelemetryEvent('debug/appHost/end', {
mode,
apphost_language: language,
ended_with_error: aggregate?.anyNonZeroExit ? 'true' : 'false',
distinct_resource_types: aggregate ? aggregate.distinctResourceTypes.join(',') : '',
}, {
duration_ms: Date.now() - startMs,
total_child_sessions: aggregate?.totalChildSessions ?? 0,
distinct_resource_type_count: aggregate?.distinctResourceTypes.length ?? 0,
});
}, 500);
}
}

/**
Expand Down
Loading
Loading