Skip to content

Commit

Permalink
fix(): revert to previous cold start check as the env var was always …
Browse files Browse the repository at this point in the history
…seen as true
  • Loading branch information
mikaelvesavuori committed Nov 14, 2022
1 parent e5f5953 commit 4ff0208
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 39 deletions.
12 changes: 6 additions & 6 deletions src/entities/MikroLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand All @@ -49,8 +50,6 @@ export class MikroLog {
MikroLog.correlationId = '';
MikroLog.debugSamplingLevel = this.initDebugSampleLevel();
MikroLog.isDebugLogSampled = true;

process.env.IS_COLD_START = 'true';
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down
33 changes: 0 additions & 33 deletions tests/MikroLog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
);

0 comments on commit 4ff0208

Please sign in to comment.