3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
+ import { getWindowById } from '../../../../base/browser/dom.js' ;
7
+ import { isAuxiliaryWindow } from '../../../../base/browser/window.js' ;
6
8
import { timeout } from '../../../../base/common/async.js' ;
7
9
import { Event } from '../../../../base/common/event.js' ;
8
10
import { Disposable , DisposableStore } from '../../../../base/common/lifecycle.js' ;
9
11
import { basename } from '../../../../base/common/path.js' ;
10
12
import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js' ;
11
13
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' ;
13
15
import type { IWorkbenchContribution } from '../../../common/contributions.js' ;
14
16
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' ;
16
18
17
19
export class TerminalTelemetryContribution extends Disposable implements IWorkbenchContribution {
18
20
static ID = 'terminalTelemetry' ;
19
21
20
22
constructor (
21
23
@ILifecycleService lifecycleService : ILifecycleService ,
22
24
@ITerminalService terminalService : ITerminalService ,
25
+ @ITerminalEditorService terminalEditorService : ITerminalEditorService ,
23
26
@ITelemetryService private readonly _telemetryService : ITelemetryService ,
24
27
) {
25
28
super ( ) ;
@@ -28,6 +31,7 @@ export class TerminalTelemetryContribution extends Disposable implements IWorkbe
28
31
const store = new DisposableStore ( ) ;
29
32
this . _store . add ( store ) ;
30
33
34
+
31
35
await Promise . race ( [
32
36
// Wait for process ready so the shell launch config is fully resolved, then
33
37
// allow another 10 seconds for the shell integration to be fully initialized
@@ -40,16 +44,28 @@ export class TerminalTelemetryContribution extends Disposable implements IWorkbe
40
44
Event . toPromise ( lifecycleService . onWillShutdown , store ) ,
41
45
] ) ;
42
46
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 ) ;
44
58
this . _store . delete ( store ) ;
45
59
} ) ) ;
46
60
}
47
61
48
- private _logCreateInstance ( instance : ITerminalInstance ) : void {
62
+ private _logCreateInstance ( instance : ITerminalInstance , isInAuxWindow : boolean ) : void {
49
63
const slc = instance . shellLaunchConfig ;
50
64
const commandDetection = instance . capabilities . get ( TerminalCapability . CommandDetection ) ;
51
65
52
66
type TerminalCreationTelemetryData = {
67
+ location : string ;
68
+
53
69
shellType : string ;
54
70
promptType : string | undefined ;
55
71
@@ -68,6 +84,8 @@ export class TerminalTelemetryContribution extends Disposable implements IWorkbe
68
84
owner : 'tyriar' ;
69
85
comment : 'Track details about terminal creation, such as the shell type' ;
70
86
87
+ location : { classification : 'SystemMetaData' ; purpose : 'FeatureInsight' ; comment : 'The location of the terminal.' } ;
88
+
71
89
shellType : { classification : 'SystemMetaData' ; purpose : 'FeatureInsight' ; comment : 'The detected shell type for the terminal.' } ;
72
90
promptType : { classification : 'SystemMetaData' ; purpose : 'FeatureInsight' ; comment : 'The detected prompt type for the terminal.' } ;
73
91
@@ -83,6 +101,12 @@ export class TerminalTelemetryContribution extends Disposable implements IWorkbe
83
101
terminalSessionId : { classification : 'SystemMetaData' ; purpose : 'FeatureInsight' ; comment : 'The session ID of the terminal instance.' } ;
84
102
} ;
85
103
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
+
86
110
shellType : getSanitizedShellType ( slc ) ,
87
111
promptType : commandDetection ?. promptType ,
88
112
0 commit comments