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

Beta Part 3: Part of Mega Dynamic Load/Unload support #1780

Merged
merged 2 commits into from
Mar 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big jump from 2 to 50, any specific reason for this one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, I figured SDK unload should be separated from the other "plugin" related reasons

}
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;
}