diff --git a/AISKULight/Tests/Unit/src/AISKULightSize.Tests.ts b/AISKULight/Tests/Unit/src/AISKULightSize.Tests.ts index ee2bb26cb..cdb8a9baf 100644 --- a/AISKULight/Tests/Unit/src/AISKULightSize.Tests.ts +++ b/AISKULight/Tests/Unit/src/AISKULightSize.Tests.ts @@ -2,8 +2,8 @@ import { AITestClass, Assert } from "@microsoft/ai-test-framework"; import * as pako from "pako"; export class AISKULightSizeCheck extends AITestClass { - private readonly MAX_RAW_SIZE = 89; - private readonly MAX_BUNDLE_SIZE = 89; + private readonly MAX_RAW_SIZE = 90; + private readonly MAX_BUNDLE_SIZE = 90; private readonly MAX_RAW_DEFLATE_SIZE = 37; private readonly MAX_BUNDLE_DEFLATE_SIZE = 37; private readonly rawFilePath = "../dist/es5/applicationinsights-web-basic.min.js"; diff --git a/AISKULight/Tests/Unit/src/config.tests.ts b/AISKULight/Tests/Unit/src/config.tests.ts index 97926a608..e234d8ff1 100644 --- a/AISKULight/Tests/Unit/src/config.tests.ts +++ b/AISKULight/Tests/Unit/src/config.tests.ts @@ -1,7 +1,7 @@ -import { AITestClass, Assert } from "@microsoft/ai-test-framework"; -import { newId } from "@microsoft/applicationinsights-core-js"; +import { AITestClass, Assert, PollingAssert } from "@microsoft/ai-test-framework"; +import { ITelemetryItem, newId } from "@microsoft/applicationinsights-core-js"; import { ApplicationInsights} from "../../../src/index"; -import { BreezeChannelIdentifier, utlRemoveSessionStorage } from "@microsoft/applicationinsights-common"; +import { BreezeChannelIdentifier, ContextTagKeys, utlRemoveSessionStorage } from "@microsoft/applicationinsights-common"; import { Sender } from "@microsoft/applicationinsights-channel-js"; export class ApplicationInsightsConfigTests extends AITestClass { @@ -11,6 +11,20 @@ export class ApplicationInsightsConfigTests extends AITestClass { private readonly _iKey = "testKey"; private _sessionPrefix: string = newId(); static registerTests: any; + private static readonly _expectedTrackMethods = [ + "flush", + "pollInternalLogs", + "stopPollingInternalLogs", + "unload", + "getPlugin", + "addPlugin", + "evtNamespace", + "addUnloadCb", + "onCfgChange", + "getTraceCtx", + "updateCfg", + "addTelemetryInitializer" + ]; constructor(testName?: string) { super(testName || "ApplicationInsightsAISKULightTests"); @@ -186,6 +200,23 @@ export class ApplicationInsightsConfigTests extends AITestClass { } }); + + this.testCase({ + name: 'Proxy function exist', + test: () => { + this.onDone(() =>{ + ai.unload(false); + }); + let _config = this._getTestConfig(this._sessionPrefix, true, false); + let ai = new ApplicationInsights(_config); + ApplicationInsightsConfigTests._expectedTrackMethods.forEach(method => { + Assert.ok(ai[method], `${method} exists`); + Assert.equal('function', typeof ai[method], `${method} is a function`); + }); + } + }); + + this.testCase({ name: "TrackTests: BaseData and baseType should exist", test: () => { @@ -231,6 +262,44 @@ export class ApplicationInsightsConfigTests extends AITestClass { } }); + + this.testCase({ + name: 'Proxy function exist', + test: () => { + this.onDone(() =>{ + ai.unload(false); + }); + let _config = this._getTestConfig(this._sessionPrefix, true, false); + let ai = new ApplicationInsights(_config); + ApplicationInsightsConfigTests._expectedTrackMethods.forEach(method => { + Assert.ok(ai[method], `${method} exists`); + Assert.equal('function', typeof ai[method], `${method} is a function`); + }); + } + }); + + this.testCase({ + name: 'test proxy function (telemetry initializer) works', + useFakeTimers: true, + test: () => { + this.onDone(() =>{ + ai.unload(false); + }); + let _config = this._getTestConfig(this._sessionPrefix, true, false); + let ai = new ApplicationInsights(_config); + const telemetryInitializer = { + initializer: (envelope) => { } + } + const spy = this.sandbox.spy(telemetryInitializer, "initializer"); + // act + ai.addTelemetryInitializer(telemetryInitializer.initializer); + ai.track({name: 'test event'}); + this.clock.tick(1); + + // verify + Assert.ok(spy.calledOnce, 'telemetryInitializer was called'); + } + }); } } \ No newline at end of file diff --git a/AISKULight/src/index.ts b/AISKULight/src/index.ts index 7e237dccb..2a39b3e04 100644 --- a/AISKULight/src/index.ts +++ b/AISKULight/src/index.ts @@ -5,8 +5,9 @@ import dynamicProto from "@microsoft/dynamicproto-js"; import { Sender } from "@microsoft/applicationinsights-channel-js"; import { DEFAULT_BREEZE_PATH, IConfig, parseConnectionString } from "@microsoft/applicationinsights-common"; import { - AppInsightsCore, IConfigDefaults, IConfiguration, IDynamicConfigHandler, ILoadedPlugin, IPlugin, ITelemetryItem, ITelemetryPlugin, - ITelemetryUnloadState, IUnloadHook, UnloadHandler, WatcherFunction, cfgDfValidate, createDynamicConfig, onConfigChange, proxyFunctions + AppInsightsCore, IConfigDefaults, IConfiguration, IDistributedTraceContext, IDynamicConfigHandler, ILoadedPlugin, IPlugin, + ITelemetryInitializerHandler, ITelemetryItem, ITelemetryPlugin, ITelemetryUnloadState, IUnloadHook, UnloadHandler, WatcherFunction, + cfgDfValidate, createDynamicConfig, onConfigChange, proxyFunctions } from "@microsoft/applicationinsights-core-js"; import { IPromise, createAsyncPromise, doAwaitResponse } from "@nevware21/ts-async"; import { isNullOrUndefined, isPromiseLike, isString, objDefine, throwError } from "@nevware21/ts-utils"; @@ -65,7 +66,10 @@ export class ApplicationInsights { "addPlugin", "evtNamespace", "addUnloadCb", - "onCfgChange" + "onCfgChange", + "getTraceCtx", + "updateCfg", + "addTelemetryInitializer" ]); function _initialize(): void { @@ -226,6 +230,29 @@ export class ApplicationInsights { // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging } + /** + * Gets the current distributed trace context for this instance if available + */ + public getTraceCtx(): IDistributedTraceContext | null | undefined { + // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging + return null; + } + + public addTelemetryInitializer(telemetryInitializer: (item: ITelemetryItem) => boolean | void): ITelemetryInitializerHandler { + // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging + return null; + } + + /** + * Update the configuration used and broadcast the changes to all loaded plugins + * @param newConfig - The new configuration is apply + * @param mergeExisting - Should the new configuration merge with the existing or just replace it. Default is to merge. + */ + public updateCfg(newConfig: T, mergeExisting?: boolean): void { + // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging + } + + /** * Watches and tracks changes for accesses to the current config, and if the accessed config changes the * handler will be recalled.