Skip to content

Commit d13669a

Browse files
committed
Report location of created terminals
Fixes microsoft#259589
1 parent 59c3f0b commit d13669a

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/vs/workbench/contrib/terminal/browser/terminal.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import type { IXtermCore } from './xterm-private.js';
3232
import type { IMenu } from '../../../../platform/actions/common/actions.js';
3333
import type { Barrier } from '../../../../base/common/async.js';
3434
import type { IProgressState } from '@xterm/addon-progress';
35+
import type { TerminalEditorInput } from './terminalEditorInput.js';
3536

3637
export const ITerminalService = createDecorator<ITerminalService>('terminalService');
3738
export const ITerminalConfigurationService = createDecorator<ITerminalConfigurationService>('terminalConfigurationService');
@@ -84,7 +85,7 @@ export interface ITerminalInstanceService {
8485
* @param launchConfig The shell launch config.
8586
* @param target The target of the terminal.
8687
*/
87-
createInstance(launchConfig: IShellLaunchConfig, target: TerminalLocation): ITerminalInstance;
88+
createInstance(launchConfig: IShellLaunchConfig, target: TerminalLocation, editorOptions?: TerminalEditorLocation): ITerminalInstance;
8889

8990
/**
9091
* Gets the registered backend for a remote authority (undefined = local). This is a convenience
@@ -409,7 +410,7 @@ export interface ITerminalEditorService extends ITerminalInstanceHost {
409410
revealActiveEditor(preserveFocus?: boolean): Promise<void>;
410411
resolveResource(instance: ITerminalInstance): URI;
411412
reviveInput(deserializedInput: IDeserializedTerminalEditorInput): EditorInput;
412-
getInputFromResource(resource: URI): EditorInput;
413+
getInputFromResource(resource: URI): TerminalEditorInput;
413414
}
414415

415416
export const terminalEditorId = 'terminalEditor';

src/vs/workbench/contrib/terminal/browser/terminalTelemetry.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { getWindowById } from '../../../../base/browser/dom.js';
7+
import { isAuxiliaryWindow } from '../../../../base/browser/window.js';
68
import { timeout } from '../../../../base/common/async.js';
79
import { Event } from '../../../../base/common/event.js';
810
import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';
911
import { basename } from '../../../../base/common/path.js';
1012
import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js';
1113
import { TerminalCapability } from '../../../../platform/terminal/common/capabilities/capabilities.js';
12-
import type { IShellLaunchConfig, ShellIntegrationInjectionFailureReason } from '../../../../platform/terminal/common/terminal.js';
14+
import { TerminalLocation, type IShellLaunchConfig, type ShellIntegrationInjectionFailureReason } from '../../../../platform/terminal/common/terminal.js';
1315
import type { IWorkbenchContribution } from '../../../common/contributions.js';
1416
import { ILifecycleService } from '../../../services/lifecycle/common/lifecycle.js';
15-
import { ITerminalService, type ITerminalInstance } from './terminal.js';
17+
import { ITerminalEditorService, ITerminalService, type ITerminalInstance } from './terminal.js';
1618

1719
export class TerminalTelemetryContribution extends Disposable implements IWorkbenchContribution {
1820
static ID = 'terminalTelemetry';
1921

2022
constructor(
2123
@ILifecycleService lifecycleService: ILifecycleService,
2224
@ITerminalService terminalService: ITerminalService,
25+
@ITerminalEditorService terminalEditorService: ITerminalEditorService,
2326
@ITelemetryService private readonly _telemetryService: ITelemetryService,
2427
) {
2528
super();
@@ -28,6 +31,7 @@ export class TerminalTelemetryContribution extends Disposable implements IWorkbe
2831
const store = new DisposableStore();
2932
this._store.add(store);
3033

34+
3135
await Promise.race([
3236
// Wait for process ready so the shell launch config is fully resolved, then
3337
// allow another 10 seconds for the shell integration to be fully initialized
@@ -40,16 +44,28 @@ export class TerminalTelemetryContribution extends Disposable implements IWorkbe
4044
Event.toPromise(lifecycleService.onWillShutdown, store),
4145
]);
4246

43-
this._logCreateInstance(instance);
47+
// Determine window status, this is done some time after the process is ready and could
48+
// reflect the terminal being moved.
49+
let isInAuxWindow = false;
50+
try {
51+
const input = terminalEditorService.getInputFromResource(instance.resource);
52+
const windowId = input.group?.windowId;
53+
isInAuxWindow = !!(windowId && isAuxiliaryWindow(getWindowById(windowId, true).window));
54+
} catch {
55+
}
56+
57+
this._logCreateInstance(instance, isInAuxWindow);
4458
this._store.delete(store);
4559
}));
4660
}
4761

48-
private _logCreateInstance(instance: ITerminalInstance): void {
62+
private _logCreateInstance(instance: ITerminalInstance, isInAuxWindow: boolean): void {
4963
const slc = instance.shellLaunchConfig;
5064
const commandDetection = instance.capabilities.get(TerminalCapability.CommandDetection);
5165

5266
type TerminalCreationTelemetryData = {
67+
location: string;
68+
5369
shellType: string;
5470
promptType: string | undefined;
5571

@@ -68,6 +84,8 @@ export class TerminalTelemetryContribution extends Disposable implements IWorkbe
6884
owner: 'tyriar';
6985
comment: 'Track details about terminal creation, such as the shell type';
7086

87+
location: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The location of the terminal.' };
88+
7189
shellType: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The detected shell type for the terminal.' };
7290
promptType: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The detected prompt type for the terminal.' };
7391

@@ -83,6 +101,12 @@ export class TerminalTelemetryContribution extends Disposable implements IWorkbe
83101
terminalSessionId: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'The session ID of the terminal instance.' };
84102
};
85103
this._telemetryService.publicLog2<TerminalCreationTelemetryData, TerminalCreationTelemetryClassification>('terminal/createInstance', {
104+
location: (instance.target === TerminalLocation.Panel
105+
? 'view'
106+
: instance.target === TerminalLocation.Editor
107+
? (isInAuxWindow ? 'editor-auxwindow' : 'editor')
108+
: 'unknown'),
109+
86110
shellType: getSanitizedShellType(slc),
87111
promptType: commandDetection?.promptType,
88112

0 commit comments

Comments
 (0)