Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Behavior difference for an empty endpointUrl when upgrading from v1 to v2 #1890 #1891

Merged
merged 1 commit into from
Aug 25, 2022
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 @@ -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