Skip to content

Commit

Permalink
[BUG] Behavior difference for an empty endpointUrl when upgrading fro…
Browse files Browse the repository at this point in the history
…m v1 to v2 #1890
  • Loading branch information
MSNev committed Aug 25, 2022
1 parent 652c693 commit fe43659
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AITestClass } from "@microsoft/ai-test-framework";
import { Sender } from "../../../src/Sender";
import { createOfflineListener, IOfflineListener } from '../../../src/Offline';
import { EnvelopeCreator } from '../../../src/EnvelopeCreator';
import { Exception, CtxTagKeys, Util } from "@microsoft/applicationinsights-common";
import { Exception, CtxTagKeys, Util, DEFAULT_BREEZE_ENDPOINT, DEFAULT_BREEZE_PATH } from "@microsoft/applicationinsights-common";
import { ITelemetryItem, AppInsightsCore, ITelemetryPlugin, DiagnosticLogger, NotificationManager, SendRequestReason, _InternalMessageId, LoggingSeverity, getGlobalInst, getGlobal } from "@microsoft/applicationinsights-core-js";

export class SenderTests extends AITestClass {
Expand Down Expand Up @@ -55,6 +55,31 @@ export class SenderTests extends AITestClass {
}
});

this.testCase({
name: "Channel Config: Validate empty endpointURL falls back to the default",
test: () => {
this._sender.initialize(
{
instrumentationKey: 'abc',
maxBatchInterval: 123,
endpointUrl: '',
maxBatchSizeInBytes: 654,
extensionConfig: {
[this._sender.identifier]: {
maxBatchSizeInBytes: 456
}
}

}, new AppInsightsCore(), []
);

QUnit.assert.equal(123, this._sender._senderConfig.maxBatchInterval(), 'Channel config can be set from root config (maxBatchInterval)');
QUnit.assert.equal(DEFAULT_BREEZE_ENDPOINT + DEFAULT_BREEZE_PATH, this._sender._senderConfig.endpointUrl(), 'Channel config can be set from root config (endpointUrl)');
QUnit.assert.notEqual(654, this._sender._senderConfig.maxBatchSizeInBytes(), 'Channel config does not equal root config option if extensionConfig field is also set');
QUnit.assert.equal(456, this._sender._senderConfig.maxBatchSizeInBytes(), 'Channel config prioritizes extensionConfig over root config');
}
});

this.testCase({
name: "processTelemetry can be called with optional fields undefined",
useFakeTimers: true,
Expand Down
10 changes: 9 additions & 1 deletion channels/applicationinsights-channel-js/src/Sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,17 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControlsAI {
_evtNamespace = mergeEvtNamespace(createUniqueNamespace("Sender"), core.evtNamespace && core.evtNamespace());
_offlineListener = createOfflineListener(_evtNamespace);

// TODO v3.x: Change the ISenderConfig to not be function calls
const defaultConfig = _getDefaultAppInsightsChannelConfig();
objForEachKey(defaultConfig, (field, value) => {
_self._senderConfig[field] = () => ctx.getConfig(identifier, field, value());
_self._senderConfig[field] = () => {
let theValue = ctx.getConfig(identifier, field, value())
if (!theValue && field === "endpointUrl") {
// Use the default value (handles empty string in the configuration)
theValue = value();
}
return theValue;
}
});

_self._buffer = (_self._senderConfig.enableSessionStorageBuffer() && utlCanUseSessionStorage())
Expand Down
Loading

0 comments on commit fe43659

Please sign in to comment.