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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 13 additions & 3 deletions channels/applicationinsights-channel-js/src/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down