Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use loggerPrefix #201

Merged
merged 2 commits into from
Jan 16, 2025
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
18 changes: 9 additions & 9 deletions src/client/eppo-client.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}`);
}
});
}
Expand Down Expand Up @@ -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}`);
}
}

Expand Down
26 changes: 13 additions & 13 deletions src/client/eppo-precomputed-client.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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`,
);
}
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -232,15 +232,15 @@ 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 {
return result.variation?.value !== undefined
? valueTransformer(result.variation.value)
: defaultValue;
} catch (error) {
logger.error(`[Eppo SDK] Error transforming value: ${error}`);
logger.error(`${loggerPrefix} Error transforming value: ${error}`);
return defaultValue;
}
}
Expand Down Expand Up @@ -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 };
}

Expand All @@ -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 };
Expand Down Expand Up @@ -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}`);
}
});
}
Expand Down Expand Up @@ -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}`);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -66,6 +66,7 @@ import {
import * as validation from './validation';

export {
loggerPrefix,
applicationLogger,
AbstractAssignmentCache,
IAssignmentDetails,
Expand Down
Loading