diff --git a/lib/client_factory.ts b/lib/client_factory.ts index 6601a5739..747992d91 100644 --- a/lib/client_factory.ts +++ b/lib/client_factory.ts @@ -1,5 +1,5 @@ /** - * Copyright 2025, Optimizely + * Copyright 2025-2026, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import { extractOdpManager } from "./odp/odp_manager_factory"; import { extractVuidManager } from "./vuid/vuid_manager_factory"; import { RequestHandler } from "./utils/http_request_handler/http"; import { CLIENT_VERSION, DEFAULT_CMAB_BACKOFF_MS, DEFAULT_CMAB_CACHE_SIZE, DEFAULT_CMAB_CACHE_TIMEOUT_MS, DEFAULT_CMAB_RETRIES, JAVASCRIPT_CLIENT_ENGINE } from "./utils/enums"; -import Optimizely from "./optimizely"; +import Optimizely, { OptimizelyOptions } from "./optimizely"; import { DefaultCmabClient } from "./core/decision_service/cmab/cmab_client"; import { CmabCacheValue, DefaultCmabService } from "./core/decision_service/cmab/cmab_service"; import { InMemoryLruCache } from "./utils/cache/in_memory_lru_cache"; @@ -76,7 +76,7 @@ export const getOptimizelyInstance = (config: OptimizelyFactoryConfig): Optimize logger: logger?.child() }); - const optimizelyOptions = { + const optimizelyOptions: OptimizelyOptions = { cmabService, clientEngine: clientEngine || JAVASCRIPT_CLIENT_ENGINE, clientVersion: clientVersion || CLIENT_VERSION, @@ -91,6 +91,9 @@ export const getOptimizelyInstance = (config: OptimizelyFactoryConfig): Optimize eventProcessor, odpManager, vuidManager, + // UNSTABLE_conditionEvaluators is not exposed in the public types, but we want to pass it through + // for internal use cases. + UNSTABLE_conditionEvaluators: (config as any).UNSTABLE_conditionEvaluators, }; return new Optimizely(optimizelyOptions); diff --git a/lib/core/decision_service/index.tests.js b/lib/core/decision_service/index.tests.js index 346814857..84c4f8c5f 100644 --- a/lib/core/decision_service/index.tests.js +++ b/lib/core/decision_service/index.tests.js @@ -77,6 +77,7 @@ var createLogger = () => ({ warn: () => {}, error: () => {}, child: () => createLogger(), + setName: () => {}, }) describe('lib/core/decision_service', function() { diff --git a/lib/core/decision_service/index.ts b/lib/core/decision_service/index.ts index 452f74bce..217550f17 100644 --- a/lib/core/decision_service/index.ts +++ b/lib/core/decision_service/index.ts @@ -1,5 +1,5 @@ /** - * Copyright 2017-2022, 2024-2025, Optimizely + * Copyright 2017-2022, 2024-2026, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -158,6 +158,8 @@ export type DecideOptionsMap = Partial>; export const CMAB_DUMMY_ENTITY_ID= '$' +export const LOGGER_NAME = 'DecisionService'; + /** * Optimizely's decision service that determines which variation of an experiment the user will be allocated to. * @@ -183,6 +185,7 @@ export class DecisionService { constructor(options: DecisionServiceOptions) { this.logger = options.logger; + this.logger?.setName(LOGGER_NAME); this.audienceEvaluator = createAudienceEvaluator(options.UNSTABLE_conditionEvaluators, this.logger); this.forcedVariationMap = {}; this.userProfileService = options.userProfileService; diff --git a/lib/optimizely/index.tests.js b/lib/optimizely/index.tests.js index 4cb9bb7da..437749cfb 100644 --- a/lib/optimizely/index.tests.js +++ b/lib/optimizely/index.tests.js @@ -98,6 +98,7 @@ var createLogger = () => ({ warn: () => {}, error: () => {}, child: () => createLogger(), + setName: () => {}, }) const getOptlyInstance = ({ datafileObj, defaultDecideOptions }) => { @@ -240,7 +241,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith(decisionService.createDecisionService, { userProfileService: userProfileServiceInstance, userProfileServiceAsync: undefined, - logger: createdLogger, + logger: sinon.match.any, cmabService, UNSTABLE_conditionEvaluators: undefined, }); @@ -272,7 +273,7 @@ describe('lib/optimizely', function() { sinon.assert.calledWith(decisionService.createDecisionService, { userProfileService: undefined, userProfileServiceAsync: undefined, - logger: createdLogger, + logger: sinon.match.any, UNSTABLE_conditionEvaluators: undefined, cmabService, }); diff --git a/lib/optimizely/index.ts b/lib/optimizely/index.ts index c9a82b551..251c08b0e 100644 --- a/lib/optimizely/index.ts +++ b/lib/optimizely/index.ts @@ -1,5 +1,5 @@ /** - * Copyright 2020-2025, Optimizely + * Copyright 2020-2026, Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -242,7 +242,7 @@ export default class Optimizely extends BaseService implements Client { userProfileService: userProfileService, userProfileServiceAsync: config.userProfileServiceAsync || undefined, cmabService: config.cmabService, - logger: this.logger, + logger: this.logger?.child(), UNSTABLE_conditionEvaluators: config.UNSTABLE_conditionEvaluators, }); diff --git a/lib/optimizely_user_context/index.tests.js b/lib/optimizely_user_context/index.tests.js index 9f3597187..6eed2437e 100644 --- a/lib/optimizely_user_context/index.tests.js +++ b/lib/optimizely_user_context/index.tests.js @@ -48,6 +48,7 @@ var createLogger = () => ({ warn: () => {}, error: () => {}, child: () => createLogger(), + setName: () => {}, }); const getOptlyInstance = ({ datafileObj, defaultDecideOptions }) => {