Skip to content

Commit 5789448

Browse files
authored
Fix browser logging fixes (#296)
* don't depend on process.env * warn level default for browser too * patch version bump * follow pino convention * adjust to pino convention * adjust formatting
1 parent 8824a52 commit 5789448

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk-common",
3-
"version": "4.15.2",
3+
"version": "4.15.3",
44
"description": "Common library for Eppo JavaScript SDKs (web, react native, and node)",
55
"main": "dist/index.js",
66
"files": [

src/application-logger.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@ export const loggerPrefix = '[Eppo SDK]';
44

55
// Create a Pino logger instance
66
export const logger = pino({
7-
// eslint-disable-next-line no-restricted-globals
8-
level: process.env.LOG_LEVEL ?? (process.env.NODE_ENV === 'production' ? 'warn' : 'info'),
9-
// https://getpino.io/#/docs/browser
10-
browser: { disabled: true },
7+
// Use any specified log level, or warn in production/browser, info otherwise
8+
/* eslint-disable no-restricted-globals */
9+
level:
10+
typeof process !== 'undefined' && process.env.LOG_LEVEL
11+
? process.env.LOG_LEVEL
12+
: typeof process === 'undefined' || process.env.NODE_ENV === 'production'
13+
? 'warn'
14+
: 'info',
15+
/* eslint-enable no-restricted-globals */
16+
17+
browser: { disabled: true }, // See https://getpino.io/#/docs/browser
1118
});

src/client/eppo-client.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -756,14 +756,14 @@ export default class EppoClient {
756756

757757
try {
758758
this.logBanditAction(banditEvent);
759-
} catch (err: any) {
760-
logger.error('Error logging bandit event', err);
759+
} catch (err) {
760+
logger.error({ err }, 'Error logging bandit event');
761761
}
762762

763763
evaluationDetails.banditAction = action;
764764
}
765765
} catch (err: any) {
766-
logger.error('Error determining bandit action', err);
766+
logger.error({ err }, 'Error determining bandit action');
767767
if (!this.isGracefulFailureMode) {
768768
throw err;
769769
}
@@ -772,7 +772,7 @@ export default class EppoClient {
772772
// Update the flag evaluation code to indicate that
773773
evaluationDetails.flagEvaluationCode = 'BANDIT_ERROR';
774774
}
775-
evaluationDetails.flagEvaluationDescription = `Error evaluating bandit action: ${err.message}`;
775+
evaluationDetails.flagEvaluationDescription = `Error evaluating bandit action: ${err?.message}`;
776776
}
777777
return { variation, action, evaluationDetails };
778778
}
@@ -877,7 +877,7 @@ export default class EppoClient {
877877
// Record in the assignment cache, if active, to deduplicate subsequent repeat assignments
878878
this.banditAssignmentCache?.set(banditAssignmentCacheProperties);
879879
} catch (err) {
880-
logger.warn('Error encountered logging bandit action', err);
880+
logger.warn({ err }, 'Error encountered logging bandit action');
881881
}
882882
}
883883

src/client/eppo-precomputed-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ export default class EppoPrecomputedClient {
519519
// Record in the assignment cache, if active, to deduplicate subsequent repeat assignments
520520
this.banditAssignmentCache?.set(banditAssignmentCacheProperties);
521521
} catch (err) {
522-
logger.warn('Error encountered logging bandit action', err);
522+
logger.warn({ err }, 'Error encountered logging bandit action');
523523
}
524524
}
525525

src/events/event-delivery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export default class EventDelivery implements IEventDelivery {
3333
} else {
3434
return { failedEvents: batch };
3535
}
36-
} catch (e: any) {
37-
logger.warn(`Failed to upload event batch`, e);
36+
} catch (err) {
37+
logger.warn({ err }, `Failed to upload event batch`);
3838
return { failedEvents: batch };
3939
}
4040
}

0 commit comments

Comments
 (0)