From ebee345f6d62e42f4a9c27681dc0312d1d8f7654 Mon Sep 17 00:00:00 2001 From: Sameeran Kunche Date: Wed, 15 Jan 2025 16:42:24 -0800 Subject: [PATCH 1/2] chore: use loggerPrefix --- src/client/eppo-client.ts | 18 +++++++++--------- src/client/eppo-precomputed-client.ts | 26 +++++++++++++------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/client/eppo-client.ts b/src/client/eppo-client.ts index f59a749..67e43c7 100644 --- a/src/client/eppo-client.ts +++ b/src/client/eppo-client.ts @@ -1,7 +1,7 @@ import { v4 as randomUUID } from 'uuid'; import ApiEndpoints from '../api-endpoints'; -import { logger } from '../application-logger'; +import { logger, loggerPrefix } from '../application-logger'; import { IAssignmentEvent, IAssignmentLogger } from '../assignment-logger'; import { ensureActionsWithContextualAttributes, @@ -809,7 +809,7 @@ export default class EppoClient { private rethrowIfNotGraceful(err: Error, defaultValue?: EppoValue): EppoValue { if (this.isGracefulFailureMode) { - logger.error(`[Eppo SDK] Error getting assignment: ${err.message}`); + logger.error(`${loggerPrefix} Error getting assignment: ${err.message}`); return defaultValue ?? EppoValue.Null(); } throw err; @@ -827,7 +827,7 @@ export default class EppoClient { flagKeys.forEach((flagKey) => { const flag = this.getFlag(flagKey); if (!flag) { - logger.debug(`[Eppo SDK] No assigned variation. Flag does not exist.`); + logger.debug(`${loggerPrefix} No assigned variation. Flag does not exist.`); return; } @@ -842,7 +842,7 @@ export default class EppoClient { // allocationKey is set along with variation when there is a result. this check appeases typescript below if (!evaluation.variation || !evaluation.allocationKey) { - logger.debug(`[Eppo SDK] No assigned variation: ${flagKey}`); + logger.debug(`${loggerPrefix} No assigned variation: ${flagKey}`); return; } @@ -927,7 +927,7 @@ export default class EppoClient { const flag = this.getFlag(flagKey); if (flag === null) { - logger.warn(`[Eppo SDK] No assigned variation. Flag not found: ${flagKey}`); + logger.warn(`${loggerPrefix} No assigned variation. Flag not found: ${flagKey}`); // note: this is different from the Python SDK, which returns None instead const flagEvaluationDetails = flagEvaluationDetailsBuilder.buildForNoneResult( 'FLAG_UNRECOGNIZED_OR_DISABLED', @@ -961,7 +961,7 @@ export default class EppoClient { } if (!flag.enabled) { - logger.info(`[Eppo SDK] No assigned variation. Flag is disabled: ${flagKey}`); + logger.info(`${loggerPrefix} No assigned variation. Flag is disabled: ${flagKey}`); // note: this is different from the Python SDK, which returns None instead const flagEvaluationDetails = flagEvaluationDetailsBuilder.buildForNoneResult( 'FLAG_UNRECOGNIZED_OR_DISABLED', @@ -994,7 +994,7 @@ export default class EppoClient { this.maybeLogAssignment(result); } } catch (error) { - logger.error(`[Eppo SDK] Error logging assignment event: ${error}`); + logger.error(`${loggerPrefix} Error logging assignment event: ${error}`); } return result; @@ -1147,7 +1147,7 @@ export default class EppoClient { try { logFunction(event); } catch (error: any) { - logger.error(`[Eppo SDK] Error flushing event to logger: ${error.message}`); + logger.error(`${loggerPrefix} Error flushing event to logger: ${error.message}`); } }); } @@ -1196,7 +1196,7 @@ export default class EppoClient { variationKey: variation?.key ?? '__eppo_no_variation', }); } catch (error: any) { - logger.error(`[Eppo SDK] Error logging assignment event: ${error.message}`); + logger.error(`${loggerPrefix} Error logging assignment event: ${error.message}`); } } diff --git a/src/client/eppo-precomputed-client.ts b/src/client/eppo-precomputed-client.ts index 8267b2f..b2e19ff 100644 --- a/src/client/eppo-precomputed-client.ts +++ b/src/client/eppo-precomputed-client.ts @@ -1,5 +1,5 @@ import ApiEndpoints from '../api-endpoints'; -import { logger } from '../application-logger'; +import { logger, loggerPrefix } from '../application-logger'; import { IAssignmentEvent, IAssignmentLogger } from '../assignment-logger'; import { ensureContextualSubjectAttributes, @@ -100,25 +100,25 @@ export default class EppoPrecomputedClient { // Offline mode depends on pre-populated IConfigurationStores (flags and bandits) to source configuration. if (!this.precomputedFlagStore.isInitialized()) { logger.error( - '[Eppo SDK] EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided', + `${loggerPrefix} EppoPrecomputedClient requires an initialized precomputedFlagStore if requestParameters are not provided`, ); } if (this.precomputedBanditStore && !this.precomputedBanditStore.isInitialized()) { logger.error( - '[Eppo SDK] Passing banditOptions without requestParameters requires an initialized precomputedBanditStore', + `${loggerPrefix} Passing banditOptions without requestParameters requires an initialized precomputedBanditStore`, ); } if (!this.precomputedFlagStore.salt) { logger.error( - '[Eppo SDK] EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided', + `${loggerPrefix} EppoPrecomputedClient requires a precomputedFlagStore with a salt if requestParameters are not provided`, ); } if (this.precomputedBanditStore && !this.precomputedBanditStore.salt) { logger.warn( - '[Eppo SDK] EppoPrecomputedClient missing or empty salt for precomputedBanditStore', + `${loggerPrefix} EppoPrecomputedClient missing or empty salt for precomputedBanditStore`, ); } } @@ -202,13 +202,13 @@ export default class EppoPrecomputedClient { const precomputedFlag = this.getPrecomputedFlag(flagKey); if (precomputedFlag == null) { - logger.warn(`[Eppo SDK] No assigned variation. Flag not found: ${flagKey}`); + logger.warn(`${loggerPrefix} No assigned variation. Flag not found: ${flagKey}`); return defaultValue; } // Add type checking before proceeding if (!checkTypeMatch(expectedType, precomputedFlag.variationType)) { - const errorMessage = `[Eppo SDK] Type mismatch: expected ${expectedType} but flag ${flagKey} has type ${precomputedFlag.variationType}`; + const errorMessage = `${loggerPrefix} Type mismatch: expected ${expectedType} but flag ${flagKey} has type ${precomputedFlag.variationType}`; logger.error(errorMessage); return defaultValue; } @@ -232,7 +232,7 @@ export default class EppoPrecomputedClient { this.logAssignment(result); } } catch (error) { - logger.error(`[Eppo SDK] Error logging assignment event: ${error}`); + logger.error(`${loggerPrefix} Error logging assignment event: ${error}`); } try { @@ -240,7 +240,7 @@ export default class EppoPrecomputedClient { ? valueTransformer(result.variation.value) : defaultValue; } catch (error) { - logger.error(`[Eppo SDK] Error transforming value: ${error}`); + logger.error(`${loggerPrefix} Error transforming value: ${error}`); return defaultValue; } } @@ -314,7 +314,7 @@ export default class EppoPrecomputedClient { const banditEvaluation = this.getPrecomputedBandit(flagKey); if (banditEvaluation == null) { - logger.warn(`[Eppo SDK] No assigned variation. Bandit not found: ${flagKey}`); + logger.warn(`${loggerPrefix} No assigned variation. Bandit not found: ${flagKey}`); return { variation: defaultValue, action: null }; } @@ -338,7 +338,7 @@ export default class EppoPrecomputedClient { try { this.logBanditAction(banditEvent); } catch (error) { - logger.error(`[Eppo SDK] Error logging bandit action: ${error}`); + logger.error(`${loggerPrefix} Error logging bandit action: ${error}`); } return { variation: defaultValue, action: banditEvent.action }; @@ -415,7 +415,7 @@ export default class EppoPrecomputedClient { logFunction(event); // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { - logger.error(`[Eppo SDK] Error flushing event to logger: ${error.message}`); + logger.error(`${loggerPrefix} Error flushing event to logger: ${error.message}`); } }); } @@ -464,7 +464,7 @@ export default class EppoPrecomputedClient { }); // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) { - logger.error(`[Eppo SDK] Error logging assignment event: ${error.message}`); + logger.error(`${loggerPrefix} Error logging assignment event: ${error.message}`); } } From 1a282b39459095db3438c1c408770346cd3e553a Mon Sep 17 00:00:00 2001 From: Sameeran Kunche Date: Wed, 15 Jan 2025 16:44:31 -0800 Subject: [PATCH 2/2] chore: export loggerPrefix to use in dependent sdks --- src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index fcbbd95..1326638 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import ApiEndpoints from './api-endpoints'; -import { logger as applicationLogger } from './application-logger'; +import { logger as applicationLogger, loggerPrefix } from './application-logger'; import { IAssignmentHooks } from './assignment-hooks'; import { IAssignmentLogger, IAssignmentEvent } from './assignment-logger'; import { IBanditLogger, IBanditEvent } from './bandit-logger'; @@ -66,6 +66,7 @@ import { import * as validation from './validation'; export { + loggerPrefix, applicationLogger, AbstractAssignmentCache, IAssignmentDetails,