1- import { ExtensionContext , commands , env } from 'vscode' ;
1+ import { ExtensionContext , env } from 'vscode' ;
22import { TelemetryReporter } from '@vscode/extension-telemetry' ;
33import { Commands } from '../constants' ;
44
@@ -68,7 +68,7 @@ export const TELEMETRY_EVENTS = {
6868export class TelemetryService {
6969 private static instance : TelemetryService ;
7070 public reporter : TelemetryReporter | undefined ;
71- private static isInternalCall : boolean = false ;
71+ private static activeExecutions : Set < string > = new Set ( ) ;
7272
7373 private constructor ( ) { }
7474
@@ -119,7 +119,10 @@ export class TelemetryService {
119119 return async ( ...args : any [ ] ) => {
120120 const telemetryService = TelemetryService . getInstance ( ) ;
121121
122- if ( telemetryService . reporter && ! TelemetryService . isInternalCall ) {
122+ // consider this an internal call if there are ANY active executions
123+ const isInternalCall = TelemetryService . activeExecutions . size > 0 ;
124+
125+ if ( telemetryService . reporter && ! isInternalCall ) {
123126 const telemetryProperties : Record < string , string > = { ...properties } ;
124127
125128 // additional properties for npm scripts
@@ -133,12 +136,14 @@ export class TelemetryService {
133136 telemetryService . sendEvent ( eventName , telemetryProperties , measurements ) ;
134137 }
135138
136- // to avoid twice tracking triggered by clean, build, bundle, etc. which internally calls executeTerminalCommand
137- TelemetryService . isInternalCall = true ;
139+ // Track this execution
140+ const executionId = Math . random ( ) . toString ( 36 ) . substring ( 7 ) ;
141+ TelemetryService . activeExecutions . add ( executionId ) ;
142+
138143 try {
139144 return await originalCommand ( ...args ) ;
140145 } finally {
141- TelemetryService . isInternalCall = false ;
146+ TelemetryService . activeExecutions . delete ( executionId ) ;
142147 }
143148 } ;
144149 }
0 commit comments