@@ -17,7 +17,7 @@ import { InMemoryCache } from '../../common/utils/cacheUtils';
1717import { OSType } from '../../common/utils/platform' ;
1818import { IEnvironmentVariablesProvider } from '../../common/variables/types' ;
1919import { EnvironmentType , PythonEnvironment } from '../../pythonEnvironments/info' ;
20- import { captureTelemetry , sendTelemetryEvent } from '../../telemetry' ;
20+ import { sendTelemetryEvent } from '../../telemetry' ;
2121import { EventName } from '../../telemetry/constants' ;
2222import { IInterpreterService } from '../contracts' ;
2323import { IEnvironmentActivationService } from './types' ;
@@ -31,6 +31,7 @@ import {
3131 traceWarn ,
3232} from '../../logging' ;
3333import { Conda } from '../../pythonEnvironments/common/environmentManagers/conda' ;
34+ import { StopWatch } from '../../common/utils/stopWatch' ;
3435
3536const ENVIRONMENT_PREFIX = 'e8b39361-0157-4923-80e1-22d70d46dee6' ;
3637const CACHE_DURATION = 10 * 60 * 1000 ;
@@ -128,14 +129,15 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
128129 this . disposables . forEach ( ( d ) => d . dispose ( ) ) ;
129130 }
130131 @traceDecoratorVerbose ( 'getActivatedEnvironmentVariables' , TraceOptions . Arguments )
131- @captureTelemetry ( EventName . PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES , { failed : false } , true )
132132 public async getActivatedEnvironmentVariables (
133133 resource : Resource ,
134134 interpreter ?: PythonEnvironment ,
135135 allowExceptions ?: boolean ,
136136 ) : Promise < NodeJS . ProcessEnv | undefined > {
137+ const stopWatch = new StopWatch ( ) ;
137138 // Cache key = resource + interpreter.
138139 const workspaceKey = this . workspace . getWorkspaceFolderIdentifier ( resource ) ;
140+ interpreter = interpreter ?? ( await this . interpreterService . getActiveInterpreter ( resource ) ) ;
139141 const interpreterPath = this . platform . isWindows ? interpreter ?. path . toLowerCase ( ) : interpreter ?. path ;
140142 const cacheKey = `${ workspaceKey } _${ interpreterPath } ` ;
141143
@@ -145,11 +147,30 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
145147
146148 // Cache only if successful, else keep trying & failing if necessary.
147149 const cache = new InMemoryCache < NodeJS . ProcessEnv | undefined > ( CACHE_DURATION ) ;
148- return this . getActivatedEnvironmentVariablesImpl ( resource , interpreter , allowExceptions ) . then ( ( vars ) => {
149- cache . data = vars ;
150- this . activatedEnvVariablesCache . set ( cacheKey , cache ) ;
151- return vars ;
152- } ) ;
150+ return this . getActivatedEnvironmentVariablesImpl ( resource , interpreter , allowExceptions )
151+ . then ( ( vars ) => {
152+ cache . data = vars ;
153+ this . activatedEnvVariablesCache . set ( cacheKey , cache ) ;
154+ sendTelemetryEvent (
155+ EventName . PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES ,
156+ stopWatch . elapsedTime ,
157+ { failed : false } ,
158+ ) ;
159+ return vars ;
160+ } )
161+ . catch ( ( ex ) => {
162+ let excString = ( ex as Error ) . toString ( ) ;
163+ if ( interpreter ?. envName ) {
164+ excString = excString . replaceAll ( interpreter . envName , '<env name>' ) ;
165+ }
166+ sendTelemetryEvent (
167+ EventName . PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES ,
168+ stopWatch . elapsedTime ,
169+ { failed : true } ,
170+ new Error ( excString ) ,
171+ ) ;
172+ throw ex ;
173+ } ) ;
153174 }
154175 public async getEnvironmentActivationShellCommands (
155176 resource : Resource ,
@@ -176,7 +197,6 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
176197 args . forEach ( ( arg , i ) => {
177198 args [ i ] = arg . toCommandArgumentForPythonExt ( ) ;
178199 } ) ;
179- interpreter = interpreter ?? ( await this . interpreterService . getActiveInterpreter ( resource ) ) ;
180200 if ( interpreter ?. envType === EnvironmentType . Conda ) {
181201 const conda = await Conda . getConda ( ) ;
182202 const pythonArgv = await conda ?. getRunPythonArgs ( {
0 commit comments