Skip to content

Commit

Permalink
update sender url changes (#2437)
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlie-777 authored Oct 22, 2024
1 parent afb1db7 commit d9c6f89
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
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

0 comments on commit d9c6f89

Please sign in to comment.