Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNev committed Feb 11, 2021
1 parent c194571 commit c54c314
Show file tree
Hide file tree
Showing 27 changed files with 1,041 additions and 634 deletions.
3 changes: 2 additions & 1 deletion AISKU/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
},
"scripts": {
"clean": "rm -rfv browser types dist-esm",
"build": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build": "npm run build:esm && npm run build:browser",
"build-gen": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build:esm": "grunt aisku",
"build:browser": "rollup -c rollup.config.js",
"build:snippet": "grunt snippetvnext",
Expand Down
3 changes: 2 additions & 1 deletion AISKULight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"types": "types/index.d.ts",
"sideEffects": false,
"scripts": {
"build": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build": "npm run build:esm && npm run build:browser",
"build-gen": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build:esm": "grunt aiskulite",
"build:browser": "rollup -c rollup.config.js",
"test": "echo 'No tests'",
Expand Down
3 changes: 2 additions & 1 deletion channels/applicationinsights-channel-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"repository": "github:Microsoft/applicationinsights-js",
"scripts": {
"clean": "rm -rf browser dist dist-esm types",
"build": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build": "npm run build:esm && npm run build:browser",
"build-gen": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build:esm": "grunt aichannel",
"build:browser": "rollup -c",
"test": "grunt aichanneltest",
Expand Down
3 changes: 2 additions & 1 deletion extensions/applicationinsights-analytics-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"url": "https://github.com/microsoft/ApplicationInsights-JS/tree/master/extensions/applicationinsights-analytics-js"
},
"scripts": {
"build": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build": "npm run build:esm && npm run build:browser",
"build-gen": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build:esm": "grunt ai",
"build:browser": "rollup -c",
"test": "grunt aitests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"types": "types/applicationinsights-clickanalytics-js.d.ts",
"sideEffects": false,
"scripts": {
"build": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build": "npm run build:esm && npm run build:browser",
"build-gen": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build:esm": "grunt clickanalytics",
"build:browser": "rollup -c",
"test": "grunt clickanalyticstests",
Expand Down
3 changes: 2 additions & 1 deletion extensions/applicationinsights-debugplugin-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"url": "https://github.com/microsoft/ApplicationInsights-JS/tree/master/extensions/applicationinsights-debugplugin-js"
},
"scripts": {
"build": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build": "npm run build:esm && npm run build:browser",
"build-gen": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build:esm": "grunt debugplugin",
"build:browser": "rollup -c",
"test": "",
Expand Down
3 changes: 2 additions & 1 deletion extensions/applicationinsights-dependencies-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"url": "https://github.com/microsoft/ApplicationInsights-JS/tree/master/extensions/applicationinsights-dependencies-js"
},
"scripts": {
"build": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build": "npm run build:esm && npm run build:browser",
"build-gen": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build:esm": "grunt deps",
"build:browser": "rollup -c",
"test": "grunt depstest",
Expand Down
1 change: 1 addition & 0 deletions extensions/applicationinsights-properties-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"scripts": {
"build": "npm run build:esm && npm run build:browser",
"build-gen": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build:esm": "grunt properties",
"build:browser": "rollup -c",
"test": "grunt propertiestests",
Expand Down
3 changes: 2 additions & 1 deletion shared/AppInsightsCommon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"url": "https://github.com/microsoft/ApplicationInsights-JS/tree/master/shared/AppInsightsCommon"
},
"scripts": {
"build": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build": "npm run build:esm && npm run build:browser",
"build-gen": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build:esm": "grunt common",
"build:browser": "rollup -c",
"test": "grunt commontest",
Expand Down
3 changes: 2 additions & 1 deletion shared/AppInsightsCore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"types": "types/applicationinsights-core-js.d.ts",
"scripts": {
"clean": "grunt clean",
"build": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build": "npm run build:esm && npm run build:browser",
"build-gen": "npm run build:esm && npm run build:browser && npm run dtsgen",
"build:esm": "grunt core",
"build:browser": "rollup -c rollup.config.js",
"test": "grunt coretest",
Expand Down
10 changes: 5 additions & 5 deletions shared/AppInsightsCore/src/JavaScriptSDK/AppInsightsCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
import { INotificationListener } from "../JavaScriptSDK.Interfaces/INotificationListener";
import { EventsDiscardedReason } from "../JavaScriptSDK.Enums/EventsDiscardedReason";
import { NotificationManager } from "./NotificationManager";
import { CoreUtils } from "./CoreUtils";
import { doPerf } from "./PerfManager";
import { INotificationManager } from '../JavaScriptSDK.Interfaces/INotificationManager';
import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
import { _InternalLogMessage, DiagnosticLogger } from "./DiagnosticLogger";
import dynamicProto from '@microsoft/dynamicproto-js';
import { arrForEach, isNullOrUndefined, toISOString, throwError } from "./HelperFuncs";

"use strict";

Expand All @@ -32,7 +32,7 @@ export class AppInsightsCore extends BaseCore implements IAppInsightsCore {
if (telemetryItem === null) {
_notifyInvalidEvent(telemetryItem);
// throw error
throw Error("Invalid telemetry item");
throwError("Invalid telemetry item");
}

// do basic validation before sending it through the pipeline
Expand Down Expand Up @@ -78,11 +78,11 @@ export class AppInsightsCore extends BaseCore implements IAppInsightsCore {
return setInterval(() => {
const queue: _InternalLogMessage[] = _self.logger ? _self.logger.queue : [];

CoreUtils.arrForEach(queue, (logMessage: _InternalLogMessage) => {
arrForEach(queue, (logMessage: _InternalLogMessage) => {
const item: ITelemetryItem = {
name: eventName ? eventName : "InternalMessageId: " + logMessage.messageId,
iKey: _self.config.instrumentationKey,
time: CoreUtils.toISOString(new Date()),
time: toISOString(new Date()),
baseType: _InternalLogMessage.dataType,
baseData: { message: logMessage.message }
};
Expand All @@ -94,7 +94,7 @@ export class AppInsightsCore extends BaseCore implements IAppInsightsCore {
}

function _validateTelemetryItem(telemetryItem: ITelemetryItem) {
if (CoreUtils.isNullOrUndefined(telemetryItem.name)) {
if (isNullOrUndefined(telemetryItem.name)) {
_notifyInvalidEvent(telemetryItem);
throw Error("telemetry name required");
}
Expand Down
56 changes: 26 additions & 30 deletions shared/AppInsightsCore/src/JavaScriptSDK/BaseCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Licensed under the MIT License.
"use strict";

import { objCreateFn } from "@microsoft/applicationinsights-shims";
import dynamicProto from '@microsoft/dynamicproto-js';
import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore"
import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetryPlugin";
import { IChannelControls } from "../JavaScriptSDK.Interfaces/IChannelControls";
import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
import { CoreUtils } from "./CoreUtils";
import { INotificationManager } from '../JavaScriptSDK.Interfaces/INotificationManager';
import { INotificationListener } from "../JavaScriptSDK.Interfaces/INotificationListener";
import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
Expand All @@ -16,14 +17,13 @@ import { IProcessTelemetryContext } from '../JavaScriptSDK.Interfaces/IProcessTe
import { ProcessTelemetryContext } from './ProcessTelemetryContext';
import { initializePlugins, sortPlugins } from './TelemetryHelpers';
import { _InternalMessageId, LoggingSeverity } from "../JavaScriptSDK.Enums/LoggingEnums";
import dynamicProto from '@microsoft/dynamicproto-js';
import { IPerfManager } from "../JavaScriptSDK.Interfaces/IPerfManager";
import { PerfManager } from "./PerfManager";
import { arrForEach, isNullOrUndefined, isUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy } from "./HelperFuncs";
import { strExtensionConfig, strIKey } from "./Constants";

const validationError = "Extensions must provide callback to initialize";

const _arrForEach = CoreUtils.arrForEach;
const _isNullOrUndefined = CoreUtils.isNullOrUndefined;
const strNotificationManager = "_notificationManager";

export class BaseCore implements IAppInsightsCore {
Expand All @@ -44,7 +44,7 @@ export class BaseCore implements IAppInsightsCore {
dynamicProto(BaseCore, this, (_self) => {
_self._extensions = new Array<IPlugin>();
_channelController = new ChannelController();
_self.logger = CoreUtils.objCreate({
_self.logger = objCreateFn({
throwInternal: (severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct = false) => { },
warnToConsole: (message: string) => { },
resetInternalMessageCount: () => { }
Expand All @@ -56,11 +56,11 @@ export class BaseCore implements IAppInsightsCore {
_self.initialize = (config: IConfiguration, extensions: IPlugin[], logger?: IDiagnosticLogger, notificationManager?: INotificationManager): void => {
// Make sure core is only initialized once
if (_self.isInitialized()) {
throw Error("Core should not be initialized more than once");
throwError("Core should not be initialized more than once");
}

if (!config || _isNullOrUndefined(config.instrumentationKey)) {
throw Error("Please provide instrumentation key");
if (!config || isNullOrUndefined(config.instrumentationKey)) {
throwError("Please provide instrumentation key");
}

_notificationManager = notificationManager;
Expand All @@ -69,11 +69,11 @@ export class BaseCore implements IAppInsightsCore {
_self[strNotificationManager] = notificationManager;

_self.config = config || {};
config.extensions = _isNullOrUndefined(config.extensions) ? [] : config.extensions;

config.extensions = isNullOrUndefined(config.extensions) ? [] : config.extensions;

// add notification to the extensions in the config so other plugins can access it
let extConfig = config.extensionConfig = _isNullOrUndefined(config.extensionConfig) ? {} : config.extensionConfig;
let extConfig = getSetValue(config, strExtensionConfig);
extConfig.NotificationManager = notificationManager;

if (logger) {
Expand All @@ -93,16 +93,16 @@ export class BaseCore implements IAppInsightsCore {
const extPriorities = {};

// Extension validation
_arrForEach(allExtensions, (ext: ITelemetryPlugin) => {
if (_isNullOrUndefined(ext) || _isNullOrUndefined(ext.initialize)) {
throw Error(validationError);
arrForEach(allExtensions, (ext: ITelemetryPlugin) => {
if (isNullOrUndefined(ext) || isNullOrUndefined(ext.initialize)) {
throwError(validationError);
}

const extPriority = ext.priority;
const identifier = ext.identifier;

if (ext && extPriority) {
if (!_isNullOrUndefined(extPriorities[extPriority])) {
if (!isNullOrUndefined(extPriorities[extPriority])) {
logger.warnToConsole("Two extensions have same priority #" + extPriority + " - " + extPriorities[extPriority] + ", " + identifier);
} else {
// set a value
Expand Down Expand Up @@ -138,7 +138,7 @@ export class BaseCore implements IAppInsightsCore {
_self._extensions = coreExtensions;

if (_self.getTransmissionControls().length === 0) {
throw new Error("No channels available");
throwError("No channels available");
}

_isInitialized = true;
Expand All @@ -150,18 +150,14 @@ export class BaseCore implements IAppInsightsCore {
};

_self.track = (telemetryItem: ITelemetryItem) => {
if (!telemetryItem.iKey) {
// setup default iKey if not passed in
telemetryItem.iKey = _self.config.instrumentationKey;
}
if (!telemetryItem.time) {
// add default timestamp if not passed in
telemetryItem.time = CoreUtils.toISOString(new Date());
}
if (_isNullOrUndefined(telemetryItem.ver)) {
// CommonSchema 4.0
telemetryItem.ver = "4.0";
}
// setup default iKey if not passed in
setValue(telemetryItem, strIKey, _self.config.instrumentationKey, null, isNotTruthy);

// add default timestamp if not passed in
setValue(telemetryItem, "time", toISOString(new Date()), null, isNotTruthy);

// Common Schema 4.0
setValue(telemetryItem, "ver", "4.0", null, isNullOrUndefined);

if (_self.isInitialized()) {
// Process the telemetry plugin chain
Expand All @@ -188,7 +184,7 @@ export class BaseCore implements IAppInsightsCore {
_self.getNotifyMgr = (): INotificationManager => {
if (!_notificationManager) {
// Create Dummy notification manager
_notificationManager = CoreUtils.objCreate({
_notificationManager = objCreateFn({
addNotificationListener: (listener: INotificationListener) => { },
removeNotificationListener: (listener: INotificationListener) => { },
eventsSent: (events: ITelemetryItem[]) => { },
Expand Down Expand Up @@ -223,7 +219,7 @@ export class BaseCore implements IAppInsightsCore {

_self.releaseQueue = () => {
if (_eventQueue.length > 0) {
_arrForEach(_eventQueue, (event: ITelemetryItem) => {
arrForEach(_eventQueue, (event: ITelemetryItem) => {
_self.getProcessTelContext().processNext(event);
});

Expand Down
18 changes: 9 additions & 9 deletions shared/AppInsightsCore/src/JavaScriptSDK/BaseTelemetryPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { IPlugin, ITelemetryPlugin } from "../JavaScriptSDK.Interfaces/ITelemetr
import { ITelemetryItem } from "../JavaScriptSDK.Interfaces/ITelemetryItem";
import { IProcessTelemetryContext } from "../JavaScriptSDK.Interfaces/IProcessTelemetryContext";
import { ITelemetryPluginChain } from "../JavaScriptSDK.Interfaces/ITelemetryPluginChain";
import { CoreUtils } from "./CoreUtils";
import { ProcessTelemetryContext } from './ProcessTelemetryContext';
import { isFunction, isNullOrUndefined, setValue } from "./HelperFuncs";
import { strExtensionConfig } from "./Constants";

let _isFunction = CoreUtils.isFunction;
let getPlugin = "getPlugin";
let strGetPlugin = "getPlugin";

/**
* BaseTelemetryPlugin provides a basic implementation of the ITelemetryPlugin interface so that plugins
Expand Down Expand Up @@ -109,7 +109,7 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
if (itemCtx) {
// Normal core execution sequence
itemCtx.processNext(env);
} else if (_nextPlugin && _isFunction(_nextPlugin.processTelemetry)) {
} else if (_nextPlugin && isFunction(_nextPlugin.processTelemetry)) {
// Looks like backward compatibility or out of band processing. And as it looks
// like a ITelemetryPlugin or ITelemetryPluginChain, just call processTelemetry
_nextPlugin.processTelemetry(env, null);
Expand All @@ -121,9 +121,9 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
if (!itemCtx) {
let rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
// tslint:disable-next-line: prefer-conditional-expression
if (_nextPlugin && _nextPlugin[getPlugin]) {
if (_nextPlugin && _nextPlugin[strGetPlugin]) {
// Looks like a chain object
itemCtx = rootCtx.createNew(null, _nextPlugin[getPlugin]);
itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
} else {
itemCtx = rootCtx.createNew(null, _nextPlugin as ITelemetryPlugin);
}
Expand All @@ -135,7 +135,7 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
_self._baseTelInit = (config: IConfiguration, core: IAppInsightsCore, extensions: IPlugin[], pluginChain?:ITelemetryPluginChain) => {
if (config) {
// Make sure the extensionConfig exists
config.extensionConfig = config.extensionConfig || [];
setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
}

if (!pluginChain && core) {
Expand All @@ -144,9 +144,9 @@ export abstract class BaseTelemetryPlugin implements ITelemetryPlugin {
}

let nextPlugin:IPlugin = _nextPlugin as IPlugin;
if (_nextPlugin && _nextPlugin[getPlugin]) {
if (_nextPlugin && _nextPlugin[strGetPlugin]) {
// If it looks like a proxy/chain then get the plugin
nextPlugin = _nextPlugin[getPlugin]();
nextPlugin = _nextPlugin[strGetPlugin]();
}

// Support legacy plugins where core was defined as a property
Expand Down
Loading

0 comments on commit c54c314

Please sign in to comment.