diff --git a/README.md b/README.md index c5fd8e3e4..66956217d 100644 --- a/README.md +++ b/README.md @@ -310,7 +310,7 @@ Most configuration fields are named such that they can be defaulted to falsey. A | disableExceptionTracking | boolean || false | If true, exceptions are not autocollected. Default is false. | | disableTelemetry | boolean | false | If true, telemetry is not collected or sent. Default is false. | | enableDebug | boolean | false | If true, **internal** debugging data is thrown as an exception **instead** of being logged, regardless of SDK logging settings. Default is false.
***Note:*** Enabling this setting will result in dropped telemetry whenever an internal error occurs. This can be useful for quickly identifying issues with your configuration or usage of the SDK. If you do not want to lose telemetry while debugging, consider using `loggingLevelConsole` or `loggingLevelTelemetry` instead of `enableDebug`. -| enableDebugExceptions | boolean | false | Prior to v2.8.12 this was the only supported value and the documented `enableDebug` was incorrect, since v2.8.12 both `enableDebug` and `enableDebugExceptions` is supported. However, this configuration has been removed from v3.x +| enableDebugExceptions | boolean | false | Removed from v3.x, Prior to v2.8.12 this was the only supported value and the documented `enableDebug` was incorrect, since v2.8.12 both `enableDebug` and `enableDebugExceptions` is supported. | loggingLevelConsole | numeric | 0 | Logs **internal** Application Insights errors to console.
0: off,
1: Critical errors only,
2: Everything (errors & warnings) | | loggingLevelTelemetry | numeric | 1 | Sends **internal** Application Insights errors as telemetry.
0: off,
1: Critical errors only,
2: Everything (errors & warnings) | | diagnosticLogInterval | numeric | 10000 | (internal) Polling interval (in ms) for internal logging queue | 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 4ccf87d61..1fb91c588 100644 --- a/channels/applicationinsights-channel-js/Tests/Unit/src/Sender.tests.ts +++ b/channels/applicationinsights-channel-js/Tests/Unit/src/Sender.tests.ts @@ -657,6 +657,92 @@ export class SenderTests extends AITestClass { } }); + this.testCase({ + name: "Channel Config: Session storage can be enabled", + test: () => { + let setItemSpy = this.sandbox.spy(window.sessionStorage, "setItem"); + let getItemSpy = this.sandbox.spy(window.sessionStorage, "getItem"); + + this._sender.initialize( + { + enableSessionStorageBuffer: true + }, new AppInsightsCore(), [] + ); + + const telemetryItem: ITelemetryItem = { + name: 'fake item', + iKey: 'iKey', + baseType: 'some type', + baseData: {} + }; + this._sender.processTelemetry(telemetryItem, null); + + QUnit.assert.true(this._sender._buffer instanceof SessionStorageSendBuffer, 'Channel config can be set from root config (enableSessionStorageBuffer)'); + QUnit.assert.equal(false, setItemSpy.calledOnce, "The setItem has not yet been triggered"); + QUnit.assert.equal(false, getItemSpy.calledOnce, "The getItemSpy has not yet been triggered"); + } + }); + + this.testCase({ + name: "Channel Config: Session storage with buffer override is used", + test: () => { + let setItemSpy = this.sandbox.stub(); + let getItemSpy = this.sandbox.stub(); + + this._sender.initialize( + { + enableSessionStorageBuffer: true, + bufferOverride: { + getItem: getItemSpy, + setItem: setItemSpy + } + }, new AppInsightsCore(), [] + ); + + const telemetryItem: ITelemetryItem = { + name: 'fake item', + iKey: 'iKey', + baseType: 'some type', + baseData: {} + }; + this._sender.processTelemetry(telemetryItem, null); + + QUnit.assert.true(this._sender._buffer instanceof SessionStorageSendBuffer, 'Channel config can be set from root config (enableSessionStorageBuffer)'); + QUnit.assert.equal(false, setItemSpy.calledOnce, "The setItem has not yet been triggered"); + QUnit.assert.equal(false, getItemSpy.calledOnce, "The getItemSpy has not yet been triggered"); + } + }); + + this.testCase({ + name: "Channel Config: Session storage can be disabled", + test: () => { + this._sender.initialize( + { + enableSessionStorageBuffer: false + }, new AppInsightsCore(), [] + ); + + QUnit.assert.true(this._sender._buffer instanceof ArraySendBuffer, 'Channel config can be set from root config (enableSessionStorageBuffer)'); + } + }); + + this.testCase({ + name: "Channel Config: Session storage ignores buffer override when disabled", + test: () => { + this._sender.initialize( + { + enableSessionStorageBuffer: false, + bufferOverride: { + getItem: this.sandbox.stub(), + setItem: this.sandbox.stub() + } + }, new AppInsightsCore(), [] + ); + + QUnit.assert.true(this._sender._buffer instanceof ArraySendBuffer, 'Channel config can be set from root config (enableSessionStorageBuffer)'); + } + }); + this.testCase({ name: "processTelemetry can be called with optional fields undefined", useFakeTimers: true, diff --git a/channels/applicationinsights-channel-js/src/Interfaces.ts b/channels/applicationinsights-channel-js/src/Interfaces.ts index 8f16015c4..00d5fdc56 100644 --- a/channels/applicationinsights-channel-js/src/Interfaces.ts +++ b/channels/applicationinsights-channel-js/src/Interfaces.ts @@ -1,3 +1,5 @@ +import { IStorageBuffer } from "@microsoft/applicationinsights-common"; + export interface ISenderConfig { /** * The url to which payloads will be sent @@ -29,6 +31,11 @@ export interface ISenderConfig { */ enableSessionStorageBuffer: boolean; + /** + * Specify the storage buffer type implementation. + */ + bufferOverride: IStorageBuffer | false; + /** * Is retry handler disabled. * If enabled, retry on 206 (partial success), 408 (timeout), 429 (too many requests), 500 (internal server error) and 503 (service unavailable). diff --git a/channels/applicationinsights-channel-js/src/SendBuffer.ts b/channels/applicationinsights-channel-js/src/SendBuffer.ts index ab09db5f1..9080f604d 100644 --- a/channels/applicationinsights-channel-js/src/SendBuffer.ts +++ b/channels/applicationinsights-channel-js/src/SendBuffer.ts @@ -224,6 +224,7 @@ export class SessionStorageSendBuffer extends BaseSendBuffer implements ISendBuf let _bufferFullMessageSent = false; //Note: should not use config.namePrefix directly, because it will always refers to the latest namePrefix let _namePrefix = config?.namePrefix; + const { getItem, setItem } = config.bufferOverride || { getItem: utlGetSessionStorage, setItem: utlSetSessionStorage }; dynamicProto(SessionStorageSendBuffer, this, (_self, _base) => { const bufferItems = _getBuffer(SessionStorageSendBuffer.BUFFER_KEY); @@ -331,7 +332,7 @@ export class SessionStorageSendBuffer extends BaseSendBuffer implements ISendBuf let prefixedKey = key; try { prefixedKey = _namePrefix ? _namePrefix + "_" + prefixedKey : prefixedKey; - const bufferJson = utlGetSessionStorage(logger, prefixedKey); + const bufferJson = getItem(logger, prefixedKey); if (bufferJson) { let buffer: string[] = getJSON().parse(bufferJson); if (isString(buffer)) { @@ -358,11 +359,11 @@ export class SessionStorageSendBuffer extends BaseSendBuffer implements ISendBuf try { prefixedKey = _namePrefix ? _namePrefix + "_" + prefixedKey : prefixedKey; const bufferJson = JSON.stringify(buffer); - utlSetSessionStorage(logger, prefixedKey, bufferJson); + setItem(logger, prefixedKey, bufferJson); } catch (e) { // if there was an error, clear the buffer // telemetry is stored in the _buffer array so we won't loose any items - utlSetSessionStorage(logger, prefixedKey, JSON.stringify([])); + setItem(logger, prefixedKey, JSON.stringify([])); _throwInternal(logger, eLoggingSeverity.WARNING, _eInternalMessageId.FailedToSetStorageBuffer, diff --git a/channels/applicationinsights-channel-js/src/Sender.ts b/channels/applicationinsights-channel-js/src/Sender.ts index 83ece5390..868b1b590 100644 --- a/channels/applicationinsights-channel-js/src/Sender.ts +++ b/channels/applicationinsights-channel-js/src/Sender.ts @@ -1,8 +1,8 @@ import dynamicProto from "@microsoft/dynamicproto-js"; import { BreezeChannelIdentifier, DEFAULT_BREEZE_ENDPOINT, DEFAULT_BREEZE_PATH, DisabledPropertyName, Event, Exception, IConfig, IEnvelope, - ISample, Metric, PageView, PageViewPerformance, ProcessLegacy, RemoteDependencyData, RequestHeaders, SampleRate, Trace, eRequestHeaders, - isInternalApplicationInsightsEndpoint, utlCanUseSessionStorage + ISample, IStorageBuffer, Metric, PageView, PageViewPerformance, ProcessLegacy, RemoteDependencyData, RequestHeaders, SampleRate, Trace, + eRequestHeaders, isInternalApplicationInsightsEndpoint, utlCanUseSessionStorage } from "@microsoft/applicationinsights-common"; import { BaseTelemetryPlugin, IAppInsightsCore, IChannelControls, IConfigDefaults, IConfiguration, IDiagnosticLogger, INotificationManager, @@ -62,7 +62,8 @@ const defaultAppInsightsChannelConfig: IConfigDefaults = objDeepF samplingPercentage: cfgDfValidate(_chkSampling, 100), customHeaders: UNDEFINED_VALUE, convertUndefined: UNDEFINED_VALUE, - eventsLimitInMem: 10000 + eventsLimitInMem: 10000, + bufferOverride: false }); function _chkSampling(value: number) { @@ -153,6 +154,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls { let _isRetryDisabled: boolean; let _maxBatchInterval: number; let _sessionStorageUsed: boolean; + let _bufferOverrideUsed: IStorageBuffer | false; let _namePrefix: string; dynamicProto(Sender, this, (_self, _base) => { @@ -260,13 +262,16 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls { _maxBatchSizeInBytes = senderConfig.maxBatchSizeInBytes; _beaconSupported = (senderConfig.onunloadDisableBeacon === false || senderConfig.isBeaconApiDisabled === false) && isBeaconsSupported(); - let canUseSessionStorage = !!senderConfig.enableSessionStorageBuffer && utlCanUseSessionStorage(); + let bufferOverride = senderConfig.bufferOverride; + let canUseSessionStorage = !!senderConfig.enableSessionStorageBuffer && + (!!bufferOverride || utlCanUseSessionStorage()); let namePrefix = senderConfig.namePrefix; //Note: emitLineDelimitedJson and eventsLimitInMem is directly accessed via config in senderBuffer //Therefore, if canUseSessionStorage is not changed, we do not need to re initialize a new one let shouldUpdate = (canUseSessionStorage !== _sessionStorageUsed) - || (canUseSessionStorage && (_namePrefix !== namePrefix)); // prefixName is only used in session storage + || (canUseSessionStorage && (_namePrefix !== namePrefix)) // prefixName is only used in session storage + || (canUseSessionStorage && (_bufferOverrideUsed !== bufferOverride)); if (_self._buffer) { // case1 (Pre and Now enableSessionStorageBuffer settings are same) @@ -296,6 +301,7 @@ export class Sender extends BaseTelemetryPlugin implements IChannelControls { _namePrefix = namePrefix; _sessionStorageUsed = canUseSessionStorage; + _bufferOverrideUsed = bufferOverride; _self._sample = new Sample(senderConfig.samplingPercentage, diagLog); diff --git a/common/config/rush/npm-shrinkwrap.json b/common/config/rush/npm-shrinkwrap.json index 6ef8eef69..85261b345 100644 --- a/common/config/rush/npm-shrinkwrap.json +++ b/common/config/rush/npm-shrinkwrap.json @@ -9,6 +9,7 @@ "version": "0.0.0", "dependencies": { "@microsoft/api-extractor": "^7.18.1", + "@microsoft/applicationinsights-web-snippet": "1.0.1", "@microsoft/dynamicproto-js": "^2.0.2", "@nevware21/grunt-eslint-ts": "^0.2.2", "@nevware21/grunt-ts-plugin": "^0.4.3", @@ -309,6 +310,11 @@ "node": ">=4.2.0" } }, + "node_modules/@microsoft/applicationinsights-web-snippet": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@microsoft/applicationinsights-web-snippet/-/applicationinsights-web-snippet-1.0.1.tgz", + "integrity": "sha512-2IHAOaLauc8qaAitvWS+U931T+ze+7MNWrDHY47IENP5y2UA0vqJDu67kWZDdpCN1fFC77sfgfB+HV7SrKshnQ==" + }, "node_modules/@microsoft/dynamicproto-js": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@microsoft/dynamicproto-js/-/dynamicproto-js-2.0.2.tgz", @@ -428,9 +434,9 @@ } }, "node_modules/@rollup/plugin-commonjs": { - "version": "24.0.1", - "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-24.0.1.tgz", - "integrity": "sha512-15LsiWRZk4eOGqvrJyu3z3DaBu5BhXIMeWnijSRvd8irrrg9SHpQ1pH+BUK4H6Z9wL9yOxZJMTLU+Au86XHxow==", + "version": "24.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-24.1.0.tgz", + "integrity": "sha512-eSL45hjhCWI0jCCXcNtLVqM5N1JlBGvlFfY0m6oOYnLCJ6N0qEXoZql4sY2MOUArzhH4SA/qBpTxvvZp2Sc+DQ==", "dependencies": { "@rollup/pluginutils": "^5.0.1", "commondir": "^1.0.1", @@ -816,8 +822,9 @@ "node_modules/@rush-temp/applicationinsights-example-shared-worker": { "version": "0.0.0", "resolved": "file:projects/applicationinsights-example-shared-worker.tgz", - "integrity": "sha512-6dGmSv/kg14qc9YkNpYJuhI6N9cwK6lgf3bQpU2i3u7/8Tscqi1xW1AlmXyoN+cRzh9oS03GGE+l15KJAX40TA==", + "integrity": "sha512-GXbGNgwY7ojpnPdm7jXmgGE9vuHqMeIBhS8cHz0JqczLC3BttA+XHzEB+Bl+A6cAbQXne8441GoZVJs8LajJ3Q==", "dependencies": { + "@microsoft/applicationinsights-web-snippet": "1.0.1", "@microsoft/dynamicproto-js": "^2.0.2", "@nevware21/grunt-eslint-ts": "^0.2.2", "@nevware21/grunt-ts-plugin": "^0.4.3", @@ -1053,13 +1060,14 @@ "node_modules/@rush-temp/applicationinsights-web-snippet": { "version": "0.0.0", "resolved": "file:projects/applicationinsights-web-snippet.tgz", - "integrity": "sha512-t77sTGc3OSHGq0Mhkl8oVH5spqLJGHi2OC2Q4TR5VF7N2Y3hvYLJdraWLXw+2vMoV6rb3kBGvPiakbuGBIL9fg==", + "integrity": "sha512-2s12tbK20KMtuADM+qypCGGuKqpYvDnnRBeQlcRrkZyi83swryRqcA55hg2SVOJA0nn1EBQs/EtzMwsd0ss0iA==", "dependencies": { "@nevware21/grunt-eslint-ts": "^0.2.2", "@nevware21/grunt-ts-plugin": "^0.4.3", "@rollup/plugin-commonjs": "^24.0.0", "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-replace": "^5.0.2", + "@types/qunit": "^2.19.3", "grunt": "^1.5.3", "grunt-cli": "^1.4.3", "grunt-contrib-qunit": "^6.2.1", @@ -2283,9 +2291,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/electron-to-chromium": { - "version": "1.4.356", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.356.tgz", - "integrity": "sha512-nEftV1dRX3omlxAj42FwqRZT0i4xd2dIg39sog/CnCJeCcL1TRd2Uh0i9Oebgv8Ou0vzTPw++xc+Z20jzS2B6A==" + "version": "1.4.358", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.358.tgz", + "integrity": "sha512-dbqpWy662dGVwq27q8i6+t5FPcQiFPs/VExXJ+/T9Xp9KUV0b5bvG+B/i07FNNr7PgcN3GhZQCZoYJ9EUfnIOg==" }, "node_modules/encodeurl": { "version": "1.0.2", @@ -2884,19 +2892,6 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -5886,6 +5881,11 @@ "@rushstack/node-core-library": "3.55.2" } }, + "@microsoft/applicationinsights-web-snippet": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@microsoft/applicationinsights-web-snippet/-/applicationinsights-web-snippet-1.0.1.tgz", + "integrity": "sha512-2IHAOaLauc8qaAitvWS+U931T+ze+7MNWrDHY47IENP5y2UA0vqJDu67kWZDdpCN1fFC77sfgfB+HV7SrKshnQ==" + }, "@microsoft/dynamicproto-js": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@microsoft/dynamicproto-js/-/dynamicproto-js-2.0.2.tgz", @@ -5973,9 +5973,9 @@ } }, "@rollup/plugin-commonjs": { - "version": "24.0.1", - "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-24.0.1.tgz", - "integrity": "sha512-15LsiWRZk4eOGqvrJyu3z3DaBu5BhXIMeWnijSRvd8irrrg9SHpQ1pH+BUK4H6Z9wL9yOxZJMTLU+Au86XHxow==", + "version": "24.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-24.1.0.tgz", + "integrity": "sha512-eSL45hjhCWI0jCCXcNtLVqM5N1JlBGvlFfY0m6oOYnLCJ6N0qEXoZql4sY2MOUArzhH4SA/qBpTxvvZp2Sc+DQ==", "requires": { "@rollup/pluginutils": "^5.0.1", "commondir": "^1.0.1", @@ -6303,8 +6303,9 @@ }, "@rush-temp/applicationinsights-example-shared-worker": { "version": "file:projects\\applicationinsights-example-shared-worker.tgz", - "integrity": "sha512-6dGmSv/kg14qc9YkNpYJuhI6N9cwK6lgf3bQpU2i3u7/8Tscqi1xW1AlmXyoN+cRzh9oS03GGE+l15KJAX40TA==", + "integrity": "sha512-GXbGNgwY7ojpnPdm7jXmgGE9vuHqMeIBhS8cHz0JqczLC3BttA+XHzEB+Bl+A6cAbQXne8441GoZVJs8LajJ3Q==", "requires": { + "@microsoft/applicationinsights-web-snippet": "1.0.1", "@microsoft/dynamicproto-js": "^2.0.2", "@nevware21/grunt-eslint-ts": "^0.2.2", "@nevware21/grunt-ts-plugin": "^0.4.3", @@ -6529,13 +6530,14 @@ }, "@rush-temp/applicationinsights-web-snippet": { "version": "file:projects\\applicationinsights-web-snippet.tgz", - "integrity": "sha512-t77sTGc3OSHGq0Mhkl8oVH5spqLJGHi2OC2Q4TR5VF7N2Y3hvYLJdraWLXw+2vMoV6rb3kBGvPiakbuGBIL9fg==", + "integrity": "sha512-2s12tbK20KMtuADM+qypCGGuKqpYvDnnRBeQlcRrkZyi83swryRqcA55hg2SVOJA0nn1EBQs/EtzMwsd0ss0iA==", "requires": { "@nevware21/grunt-eslint-ts": "^0.2.2", "@nevware21/grunt-ts-plugin": "^0.4.3", "@rollup/plugin-commonjs": "^24.0.0", "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-replace": "^5.0.2", + "@types/qunit": "^2.19.3", "grunt": "^1.5.3", "grunt-cli": "^1.4.3", "grunt-contrib-qunit": "^6.2.1", @@ -7433,9 +7435,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "electron-to-chromium": { - "version": "1.4.356", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.356.tgz", - "integrity": "sha512-nEftV1dRX3omlxAj42FwqRZT0i4xd2dIg39sog/CnCJeCcL1TRd2Uh0i9Oebgv8Ou0vzTPw++xc+Z20jzS2B6A==" + "version": "1.4.358", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.358.tgz", + "integrity": "sha512-dbqpWy662dGVwq27q8i6+t5FPcQiFPs/VExXJ+/T9Xp9KUV0b5bvG+B/i07FNNr7PgcN3GhZQCZoYJ9EUfnIOg==" }, "encodeurl": { "version": "1.0.2", @@ -7909,12 +7911,6 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, - "fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", - "optional": true - }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", diff --git a/gruntfile.js b/gruntfile.js index 8e7e8ee44..211c182f6 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -508,7 +508,7 @@ module.exports = function (grunt) { path: "./tools/applicationinsights-web-snippet", cfg: { src: [ - "./tools/applicationinsights-web-snippet/dest/*.ts" + "./tools/applicationinsights-web-snippet/build/*.ts" ] } }, diff --git a/shared/AppInsightsCommon/src/Interfaces/IConfig.ts b/shared/AppInsightsCommon/src/Interfaces/IConfig.ts index 4c64aba5b..f030c7ca6 100644 --- a/shared/AppInsightsCommon/src/Interfaces/IConfig.ts +++ b/shared/AppInsightsCommon/src/Interfaces/IConfig.ts @@ -3,6 +3,7 @@ import { IConfiguration, ICustomProperties, isNullOrUndefined } from "@microsoft/applicationinsights-core-js"; import { DistributedTracingModes } from "../Enums"; import { IRequestContext } from "./IRequestContext"; +import { IStorageBuffer } from "./IStorageBuffer"; /** * Configuration settings for how telemetry is sent @@ -170,6 +171,11 @@ export interface IConfig { */ enableSessionStorageBuffer?: boolean; + /** + * If specified, overrides the storage & retrieval mechanism that is used to manage unsent telemetry. + */ + bufferOverride?: IStorageBuffer; + /** * @deprecated Use either disableCookiesUsage or specify a cookieCfg with the enabled value set. * If true, the SDK will not store or read any data from cookies. Default is false. As this field is being deprecated, when both diff --git a/shared/AppInsightsCommon/src/Interfaces/IStorageBuffer.ts b/shared/AppInsightsCommon/src/Interfaces/IStorageBuffer.ts new file mode 100644 index 000000000..99a04f4e7 --- /dev/null +++ b/shared/AppInsightsCommon/src/Interfaces/IStorageBuffer.ts @@ -0,0 +1,13 @@ +import { IDiagnosticLogger } from "@microsoft/applicationinsights-core-js"; + +export interface IStorageBuffer { + /** + * Retrieves the stored value for a given key + */ + getItem(logger: IDiagnosticLogger, name: string): string; + + /** + * Sets the stored value for a given key + */ + setItem(logger: IDiagnosticLogger, name: string, data: string): boolean; +} \ No newline at end of file diff --git a/shared/AppInsightsCommon/src/applicationinsights-common.ts b/shared/AppInsightsCommon/src/applicationinsights-common.ts index cabdb8de4..275767821 100644 --- a/shared/AppInsightsCommon/src/applicationinsights-common.ts +++ b/shared/AppInsightsCommon/src/applicationinsights-common.ts @@ -33,6 +33,7 @@ export { PageViewPerformance } from "./Telemetry/PageViewPerformance"; export { Data } from "./Telemetry/Common/Data"; export { eSeverityLevel, SeverityLevel } from "./Interfaces/Contracts/SeverityLevel"; export { IConfig, ConfigurationManager } from "./Interfaces/IConfig"; +export { IStorageBuffer } from "./Interfaces/IStorageBuffer"; export { IContextTagKeys, ContextTagKeys } from "./Interfaces/Contracts/ContextTagKeys"; export { DataSanitizerValues,