diff --git a/channels/applicationinsights-channel-js/Tests/Unit/src/Sender.tests.ts b/channels/applicationinsights-channel-js/Tests/Unit/src/Sender.tests.ts index 1791cba67..4ebd8e378 100644 --- a/channels/applicationinsights-channel-js/Tests/Unit/src/Sender.tests.ts +++ b/channels/applicationinsights-channel-js/Tests/Unit/src/Sender.tests.ts @@ -167,6 +167,34 @@ export class SenderTests extends AITestClass { } }); + this.testCase({ + name: "Channel Config: Endpoint Url can be set from root dynamically", + useFakeTimers: true, + test: () => { + let core = new AppInsightsCore(); + let id = this._sender.identifier; + let coreConfig = { + instrumentationKey: "abc", + extensionConfig: { + [id]: { + + } + }, + endpointUrl: "test" + } + core.initialize(coreConfig, [this._sender]); + + let senderConfig = this._sender._senderConfig; + QUnit.assert.equal(senderConfig.endpointUrl, "test", "Channel default endpoint url config is set from root"); + + //check dynamic config + core.config.endpointUrl = "test1"; + this.clock.tick(1); + let curSenderConfig = this._sender._senderConfig; + QUnit.assert.equal(curSenderConfig.endpointUrl,"test1", "Channel endpoint config is dynamically changed"); + } + }); + this.testCaseAsync({ name: "Channel Init: init with promise", stepDelay: 100, diff --git a/channels/applicationinsights-channel-js/src/Sender.ts b/channels/applicationinsights-channel-js/src/Sender.ts index 6861c875c..b5086a06f 100644 --- a/channels/applicationinsights-channel-js/src/Sender.ts +++ b/channels/applicationinsights-channel-js/src/Sender.ts @@ -268,9 +268,19 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls { let ctx = createProcessTelemetryContext(null, config, core); // getExtCfg only finds undefined values from core let senderConfig = ctx.getExtCfg(identifier, defaultAppInsightsChannelConfig); - if(isPromiseLike(senderConfig.endpointUrl)) { - // if it is promise, means the endpoint url is from core.endpointurl - senderConfig.endpointUrl = config.endpointUrl as any; + + let curExtUrl = senderConfig.endpointUrl; + // if it is not inital change (_endpointUrl has value) + // if current sender endpoint url is not changed directly + // means ExtCfg is not changed directly + // then we need to monitor endpoint url changes from core + if (_endpointUrl && curExtUrl === _endpointUrl) { + let coreUrl = config.endpointUrl as any; + // if core endpoint url is changed + if (coreUrl && coreUrl !== curExtUrl) { + // and endpoint promise changes is handled by this as well + senderConfig.endpointUrl = coreUrl; + } } if(isPromiseLike(senderConfig.instrumentationKey)) {