Skip to content

Commit

Permalink
Beta Part 3: Part of Mega Dynamic Load/Unload support (#1780)
Browse files Browse the repository at this point in the history
* Beta Part 3: Part of Mega Dynamic Load/Unload support
- Add Core SDK Unload support

* Fix telemetry chain for null and undefined
  • Loading branch information
MSNev authored Mar 10, 2022
1 parent 90a3990 commit 4c4b428
Show file tree
Hide file tree
Showing 10 changed files with 1,139 additions and 24 deletions.
795 changes: 791 additions & 4 deletions shared/AppInsightsCore/Tests/Unit/src/Dynamic.Tests.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export const enum SendRequestReason {
* The event(s) being sent as a retry
*/
Retry = 5,

/**
* The SDK is unloading
*/
SdkUnload = 6,

/**
* Maximum batch size would be exceeded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
/**
* Just this plugin is being removed
*/
//PluginUnload = 1,
PluginUnload = 1,

/**
* This instance of the plugin is being removed and replaced
*/
//PluginReplace = 2,
PluginReplace = 2,

/**
* The entire SDK is being unloaded
*/
//SdkUnload = 50
SdkUnload = 50
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.
import { ITelemetryItem } from "./ITelemetryItem";
import { IChannelControls } from "./IChannelControls";
import { IPlugin } from "./ITelemetryPlugin";
import { IPlugin, ITelemetryPlugin } from "./ITelemetryPlugin";
import { IConfiguration } from "./IConfiguration";
import { INotificationManager } from "./INotificationManager";
import { INotificationListener } from "./INotificationListener";
Expand All @@ -11,6 +11,7 @@ import { IProcessTelemetryContext } from "./IProcessTelemetryContext";
import { IPerfManagerProvider } from "./IPerfManager";
import { ICookieMgr } from "./ICookieMgr";
import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "./ITelemetryInitializers";
import { UnloadHandler } from "../applicationinsights-core-js";

export interface ILoadedPlugin<T extends IPlugin> {
plugin: T;
Expand All @@ -29,6 +30,8 @@ export interface ILoadedPlugin<T extends IPlugin> {
* (unless it's also been re-initialized)
*/
setEnabled: (isEnabled: boolean) => void;

remove: (isAsync?: boolean, removeCb?: (removed?: boolean) => void) => void;
}

export interface IAppInsightsCore extends IPerfManagerProvider {
Expand Down Expand Up @@ -106,14 +109,38 @@ export interface IAppInsightsCore extends IPerfManagerProvider {
*/
getProcessTelContext() : IProcessTelemetryContext;

/**
* Unload and Tear down the SDK and any initialized plugins, after calling this the SDK will be considered
* to be un-initialized and non-operational, re-initializing the SDK should only be attempted if the previous
* unload call return `true` stating that all plugins reported that they also unloaded, the recommended
* approach is to create a new instance and initialize that instance.
* This is due to possible unexpected side effects caused by plugins not supporting unload / teardown, unable
* to successfully remove any global references or they may just be completing the unload process asynchronously.
*/
unload(isAsync?: boolean, unloadComplete?: () => void): void;

/**
* Find and return the (first) plugin with the specified identifier if present
* @param pluginIdentifier
*/
getPlugin<T extends IPlugin = IPlugin>(pluginIdentifier: string): ILoadedPlugin<T>;

/**
* Add a new plugin to the installation
* @param plugin - The new plugin to add
* @param replaceExisting - should any existing plugin be replaced
* @param doAsync - Should the add be performed asynchronously
*/
addPlugin<T extends IPlugin = ITelemetryPlugin>(plugin: T, replaceExisting: boolean, doAsync: boolean, addCb?: (added?: boolean) => void): void;

/**
* Returns the unique event namespace that should be used when registering events
*/
evtNamespace(): string;
}

/**
* Add a handler that will be called when the SDK is being unloaded
* @param handler - the handler
*/
addUnloadCb(handler: UnloadHandler): void;
}
Loading

0 comments on commit 4c4b428

Please sign in to comment.