@@ -27,7 +27,9 @@ import {
2727 ResolveEnvironmentContext ,
2828 SetEnvironmentScope ,
2929} from './api' ;
30+ import { ISSUES_URL } from './common/constants' ;
3031import { CreateEnvironmentNotSupported , RemoveEnvironmentNotSupported } from './common/errors/NotSupportedError' ;
32+ import { traceWarn } from './common/logging' ;
3133import { StopWatch } from './common/stopWatch' ;
3234import { EventNames } from './common/telemetry/constants' ;
3335import { sendTelemetryEvent } from './common/telemetry/sender' ;
@@ -204,26 +206,48 @@ export class InternalEnvironmentManager implements EnvironmentManager {
204206
205207 async refresh ( options : RefreshEnvironmentsScope ) : Promise < void > {
206208 const sw = new StopWatch ( ) ;
209+ const SLOW_DISCOVERY_THRESHOLD_MS = 15000 ;
207210 try {
208211 await this . manager . refresh ( options ) ;
209212 const envs = await this . manager . getEnvironments ( 'all' ) . catch ( ( ) => [ ] ) ;
210- sendTelemetryEvent ( EventNames . ENVIRONMENT_DISCOVERY , sw . elapsedTime , {
213+ const duration = sw . elapsedTime ;
214+ sendTelemetryEvent ( EventNames . ENVIRONMENT_DISCOVERY , duration , {
211215 managerId : this . id ,
212216 result : 'success' ,
213217 envCount : envs . length ,
214218 } ) ;
219+
220+ // Log warning for slow discovery
221+ if ( duration > SLOW_DISCOVERY_THRESHOLD_MS ) {
222+ traceWarn (
223+ `[${ this . displayName } ] Environment discovery took ${ ( duration / 1000 ) . toFixed ( 1 ) } s (found ${ envs . length } environments). ` +
224+ `If this is causing problems, please report it: ${ ISSUES_URL } /new` ,
225+ ) ;
226+ }
215227 } catch ( ex ) {
228+ const duration = sw . elapsedTime ;
216229 const isTimeout = ex instanceof Error && ex . message . includes ( 'timed out' ) ;
230+ const errorType = ex instanceof Error ? ex . name : 'unknown' ;
217231 sendTelemetryEvent (
218232 EventNames . ENVIRONMENT_DISCOVERY ,
219- sw . elapsedTime ,
233+ duration ,
220234 {
221235 managerId : this . id ,
222236 result : isTimeout ? 'timeout' : 'error' ,
223- errorType : ex instanceof Error ? ex . name : 'unknown' ,
237+ errorType,
224238 } ,
225239 ex instanceof Error ? ex : undefined ,
226240 ) ;
241+
242+ // Log verbose failure message to help users report issues
243+ const errorMessage = ex instanceof Error ? ex . message : String ( ex ) ;
244+ traceWarn (
245+ `[${ this . displayName } ] Environment discovery failed after ${ ( duration / 1000 ) . toFixed ( 1 ) } s.\n` +
246+ ` Error: ${ errorType } - ${ errorMessage } \n` +
247+ ` If environments are not being detected correctly, please report this issue:\n` +
248+ ` ${ ISSUES_URL } /new` ,
249+ ) ;
250+
227251 throw ex ;
228252 }
229253 }
0 commit comments