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' ;
68import { timeout } from '../../../../base/common/async.js' ;
79import { Event } from '../../../../base/common/event.js' ;
810import { Disposable , DisposableStore } from '../../../../base/common/lifecycle.js' ;
911import { basename } from '../../../../base/common/path.js' ;
1012import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js' ;
1113import { 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' ;
1315import type { IWorkbenchContribution } from '../../../common/contributions.js' ;
1416import { 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
1719export 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