@@ -257,50 +257,30 @@ export class CliRepl implements MongoshIOProvider {
257257 ) ;
258258 }
259259
260- /** Setup analytics, logging and telemetry. */
261- private async startLoggingAndTelemetry ( ) {
262- // Read the global config with log settings, e.g. logLocation, disableLogging
263- const disableLogging = this . getConfig ( 'disableLogging' ) ;
264- if ( ! disableLogging ) {
265- await this . logManager . cleanupOldLogFiles ( ) ;
266- markTime ( TimingCategories . Logging , 'cleaned up log files' ) ;
267-
268- const logger = await this . logManager . createLogWriter ( ) ;
269- const { quiet } = CliRepl . getFileAndEvalInfo ( this . cliOptions ) ;
270- if ( ! quiet ) {
271- this . output . write ( `Current Mongosh Log ID:\t${ logger . logId } \n` ) ;
272- }
273-
274- this . logWriter = logger ;
275- setupMongoLogWriter ( logger ) ;
276- markTime ( TimingCategories . Logging , 'instantiated log writer' ) ;
277- this . bus . emit ( 'mongosh:log-initialized' ) ;
278- logger . info ( 'MONGOSH' , mongoLogId ( 1_000_000_000 ) , 'log' , 'Starting log' , {
279- execPath : process . execPath ,
280- envInfo : redactSensitiveData ( this . getLoggedEnvironmentVariables ( ) ) ,
281- ...( await buildInfo ( ) ) ,
282- } ) ;
283-
284- markTime ( TimingCategories . Logging , 'logged initial message' ) ;
285- }
286-
287- markTime ( TimingCategories . Telemetry , 'completed telemetry setup' ) ;
288-
289- // Create analytics instance
290- let analyticsSetupError : Error | null = null ;
291- try {
292- await this . setupAnalytics ( ) ;
293- } catch ( err : unknown ) {
294- // Need to delay emitting the error on the bus so that logging is in place
295- // as well
296- analyticsSetupError = err as Error ;
260+ /** Setup log writer and start logging. */
261+ private async startLogging ( ) {
262+ await this . logManager . cleanupOldLogFiles ( ) ;
263+ markTime ( TimingCategories . Logging , 'cleaned up log files' ) ;
264+ const logger = await this . logManager . createLogWriter ( ) ;
265+ const { quiet } = CliRepl . getFileAndEvalInfo ( this . cliOptions ) ;
266+ if ( ! quiet ) {
267+ this . output . write ( `Current Mongosh Log ID:\t${ logger . logId } \n` ) ;
297268 }
298269
299- markTime ( TimingCategories . Telemetry , 'created analytics instance' ) ;
300-
301- if ( analyticsSetupError ) {
302- this . bus . emit ( 'mongosh:error' , analyticsSetupError , 'analytics' ) ;
303- }
270+ this . logWriter = logger ;
271+ this . logWriter = logger ;
272+ setupMongoLogWriter ( logger ) ;
273+ this . logWriter = logger ;
274+ setupMongoLogWriter ( logger ) ;
275+ markTime ( TimingCategories . Logging , 'instantiated log writer' ) ;
276+ setupMongoLogWriter ( logger ) ;
277+ this . bus . emit ( 'mongosh:log-initialized' ) ;
278+ logger . info ( 'MONGOSH' , mongoLogId ( 1_000_000_000 ) , 'log' , 'Starting log' , {
279+ execPath : process . execPath ,
280+ envInfo : redactSensitiveData ( this . getLoggedEnvironmentVariables ( ) ) ,
281+ ...( await buildInfo ( ) ) ,
282+ } ) ;
283+ markTime ( TimingCategories . Logging , 'logged initial message' ) ;
304284 }
305285
306286 /**
@@ -355,14 +335,20 @@ export class CliRepl implements MongoshIOProvider {
355335 }
356336 markTime ( TimingCategories . REPLInstantiation , 'ensured shell homedir' ) ;
357337
358- // Setup telemetry
338+ let analyticsSetupError : Error | null = null ;
339+ try {
340+ await this . setupAnalytics ( ) ;
341+ } catch ( err : unknown ) {
342+ // Need to delay emitting the error on the bus so that logging is in place
343+ // as well
344+ analyticsSetupError = err as Error ;
345+ }
346+
347+ markTime ( TimingCategories . Telemetry , 'created analytics instance' ) ;
348+
359349 setupLoggerAndTelemetry (
360350 this . bus ,
361351 this . toggleableAnalytics ,
362- {
363- userId : this . getConfig ( 'userId' ) ,
364- telemetryAnonymousId : this . getConfig ( 'telemetryAnonymousId' ) ,
365- } ,
366352 {
367353 platform : process . platform ,
368354 arch : process . arch ,
@@ -371,8 +357,13 @@ export class CliRepl implements MongoshIOProvider {
371357 } ,
372358 version
373359 ) ;
360+ markTime ( TimingCategories . Telemetry , 'completed telemetry setup' ) ;
361+
362+ if ( analyticsSetupError ) {
363+ this . bus . emit ( 'mongosh:error' , analyticsSetupError , 'analytics' ) ;
364+ }
374365
375- // Get configuration
366+ // Read local and global configuration
376367 try {
377368 this . config = await this . configDirectory . generateOrReadConfig (
378369 this . config
@@ -384,7 +375,10 @@ export class CliRepl implements MongoshIOProvider {
384375 this . globalConfig = await this . loadGlobalConfigFile ( ) ;
385376 markTime ( TimingCategories . UserConfigLoading , 'read global config files' ) ;
386377
387- await this . startLoggingAndTelemetry ( ) ;
378+ const disableLogging = this . getConfig ( 'disableLogging' ) ;
379+ if ( disableLogging !== true ) {
380+ await this . startLogging ( ) ;
381+ }
388382
389383 // Needs to happen after loading the mongosh config file(s)
390384 void this . fetchMongoshUpdateUrl ( ) ;
@@ -543,6 +537,7 @@ export class CliRepl implements MongoshIOProvider {
543537 this . bus . emit ( 'mongosh:start-mongosh-repl' , { version } ) ;
544538 markTime ( TimingCategories . REPLInstantiation , 'starting repl' ) ;
545539 await this . mongoshRepl . startRepl ( initialized ) ;
540+
546541 this . bus . emit ( 'mongosh:start-session' , {
547542 isInteractive : true ,
548543 jsContext : this . mongoshRepl . jsContext ( ) ,
@@ -647,7 +642,7 @@ export class CliRepl implements MongoshIOProvider {
647642 files : string [ ] ,
648643 evalScripts : string [ ]
649644 ) : Promise < number > {
650- let lastEvalResult : any ;
645+ let lastEvalResult : unknown ;
651646 let exitCode = 0 ;
652647 try {
653648 markTime ( TimingCategories . Eval , 'start eval scripts' ) ;
@@ -1305,7 +1300,8 @@ export class CliRepl implements MongoshIOProvider {
13051300 }
13061301
13071302 async getMoreRecentMongoshVersion ( ) : Promise < string | null > {
1308- const { version } = require ( '../package.json' ) ;
1303+ // eslint-disable-next-line @typescript-eslint/no-var-requires
1304+ const { version } : { version : string } = require ( '../package.json' ) ;
13091305 return await this . updateNotificationManager . getLatestVersionIfMoreRecent (
13101306 process . env
13111307 . MONGOSH_ASSUME_DIFFERENT_VERSION_FOR_UPDATE_NOTIFICATION_TEST ||
0 commit comments