Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eppo/js-client-sdk-common",
"version": "4.15.2",
"version": "4.15.3",
"description": "Common library for Eppo JavaScript SDKs (web, react native, and node)",
"main": "dist/index.js",
"files": [
Expand Down
15 changes: 11 additions & 4 deletions src/application-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ export const loggerPrefix = '[Eppo SDK]';

// Create a Pino logger instance
export const logger = pino({
// eslint-disable-next-line no-restricted-globals
level: process.env.LOG_LEVEL ?? (process.env.NODE_ENV === 'production' ? 'warn' : 'info'),
// https://getpino.io/#/docs/browser
browser: { disabled: true },
// Use any specified log level, or warn in production/browser, info otherwise
/* eslint-disable no-restricted-globals */
level:
typeof process !== 'undefined' && process.env.LOG_LEVEL
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 The fix: we now check that process is defined before accessing

? process.env.LOG_LEVEL
: typeof process === 'undefined' || process.env.NODE_ENV === 'production'
? 'warn'
: 'info',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://getpino.io/#/docs/api?id=level-string

Looks like it defaults to 'info' anyway, but I like that it's explicit here

/* eslint-enable no-restricted-globals */

browser: { disabled: true }, // See https://getpino.io/#/docs/browser
});
10 changes: 5 additions & 5 deletions src/client/eppo-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -756,14 +756,14 @@ export default class EppoClient {

try {
this.logBanditAction(banditEvent);
} catch (err: any) {
logger.error('Error logging bandit event', err);
} catch (err) {
logger.error({ err }, 'Error logging bandit event');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pino's API (link) is to have context first, then the log message.

}

evaluationDetails.banditAction = action;
}
} catch (err: any) {
logger.error('Error determining bandit action', err);
logger.error({ err }, 'Error determining bandit action');
if (!this.isGracefulFailureMode) {
throw err;
}
Expand All @@ -772,7 +772,7 @@ export default class EppoClient {
// Update the flag evaluation code to indicate that
evaluationDetails.flagEvaluationCode = 'BANDIT_ERROR';
}
evaluationDetails.flagEvaluationDescription = `Error evaluating bandit action: ${err.message}`;
evaluationDetails.flagEvaluationDescription = `Error evaluating bandit action: ${err?.message}`;
}
return { variation, action, evaluationDetails };
}
Expand Down Expand Up @@ -877,7 +877,7 @@ export default class EppoClient {
// Record in the assignment cache, if active, to deduplicate subsequent repeat assignments
this.banditAssignmentCache?.set(banditAssignmentCacheProperties);
} catch (err) {
logger.warn('Error encountered logging bandit action', err);
logger.warn({ err }, 'Error encountered logging bandit action');
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/eppo-precomputed-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ export default class EppoPrecomputedClient {
// Record in the assignment cache, if active, to deduplicate subsequent repeat assignments
this.banditAssignmentCache?.set(banditAssignmentCacheProperties);
} catch (err) {
logger.warn('Error encountered logging bandit action', err);
logger.warn({ err }, 'Error encountered logging bandit action');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/events/event-delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export default class EventDelivery implements IEventDelivery {
} else {
return { failedEvents: batch };
}
} catch (e: any) {
logger.warn(`Failed to upload event batch`, e);
} catch (err) {
logger.warn({ err }, `Failed to upload event batch`);
return { failedEvents: batch };
}
}
Expand Down
Loading