diff --git a/src/entities/MikroLog.ts b/src/entities/MikroLog.ts index c87a625..70f4ca6 100644 --- a/src/entities/MikroLog.ts +++ b/src/entities/MikroLog.ts @@ -41,6 +41,7 @@ export class MikroLog { private static correlationId: string; private static debugSamplingLevel: number; private static isDebugLogSampled: boolean; + private coldStart = true; private constructor() { MikroLog.metadataConfig = {}; @@ -49,8 +50,6 @@ export class MikroLog { MikroLog.correlationId = ''; MikroLog.debugSamplingLevel = this.initDebugSampleLevel(); MikroLog.isDebugLogSampled = true; - - process.env.IS_COLD_START = 'true'; } /** @@ -94,12 +93,13 @@ export class MikroLog { /** * @description Is this a Lambda cold start? - * - * Setting the value in the process environment makes it possible - * to persist the value to subsequent calls, also by other libraries. */ public isColdStart(): boolean { - if (process.env.IS_COLD_START === 'true') return true; + if (this.coldStart) { + this.coldStart = false; + return true; + } + return false; } diff --git a/tests/MikroLog.test.ts b/tests/MikroLog.test.ts index 60dc541..a48fdc8 100644 --- a/tests/MikroLog.test.ts +++ b/tests/MikroLog.test.ts @@ -589,36 +589,3 @@ test.serial('It should be able to merge enrichment even if input is essentially // @ts-ignore t.deepEqual(response, expected); }); - -test.serial( - 'It should retain the cold start status between multiple calls in the same process', - (t) => { - MikroLog.reset(); - - const logger = MikroLog.start({ metadataConfig }); - const response1: any = logger.log(''); - const response2: any = logger.log(''); - - const expected = response1.isColdStart === true && response2.isColdStart === true; - - // @ts-ignore - t.is(expected, true); - } -); - -test.serial( - 'It should not reuse the cold start status between calls when "IS_COLD_START" is not set', - (t) => { - MikroLog.reset(); - - const logger = MikroLog.start({ metadataConfig }); - const response1: any = logger.log(''); - process.env.IS_COLD_START = 'false'; - const response2: any = logger.log(''); - - const expected = response1.isColdStart === true && response2.isColdStart === false; - - // @ts-ignore - t.is(expected, true); - } -);