Merge branch 'master' into users/lxiao/minor

This commit is contained in:
Xiao 2020-01-28 13:37:32 -08:00 коммит произвёл GitHub
Родитель aaea200a31 04f4cd41df
Коммит 99adbad377
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 47 добавлений и 28 удалений

Просмотреть файл

@ -15,6 +15,7 @@
"build": "npm run build:esm && npm run build:browser",
"build:esm": "grunt aisku",
"build:browser": "rollup -c",
"build:snippet": "grunt snippetvnext",
"test": "grunt aiskutests",
"lint": "tslint -p tsconfig.json",
"nightwatch:chrome": "nightwatch -c Tests/nightwatch/nightwatch.json Tests/nightwatch/run_nightwatch.js --env chrome",

Просмотреть файл

@ -18,7 +18,7 @@ const browserRollupConfigFactory = (isProduction, libVersion = '2') => {
file: `browser/ai.${libVersion}.js`,
banner: banner,
format: "umd",
name: "Microsoft.ApplicationInsights",
name: "Microsoft.ApplicationInsightsJS",
sourcemap: true
},
plugins: [
@ -60,7 +60,7 @@ const nodeUmdRollupConfigFactory = (isProduction) => {
file: `dist/applicationinsights-web.js`,
banner: banner,
format: "umd",
name: "Microsoft.ApplicationInsights",
name: "Microsoft.ApplicationInsightsJS",
sourcemap: true
},
plugins: [

Просмотреть файл

@ -46,7 +46,7 @@ var aisdk = window[aiName] || (function (aiConfig) {
createLazyMethod("start" + trackPage);
createLazyMethod("stop" + trackPage);
var trackEvent = track + method[0];
var trackEvent = track + "Event";
createLazyMethod("start" + trackEvent);
createLazyMethod("stop" + trackEvent);
@ -63,7 +63,7 @@ var aisdk = window[aiName] || (function (aiConfig) {
Error : 3,
Critical : 4,
};
// Collect global errors
// Note: ApplicationInsightsAnalytics is the extension string identifier for
// AppAnalytics. It is defined in ApplicationInsights.ts:ApplicationInsights.identifer

6
AISKU/snippet/snippet.min.js поставляемый
Просмотреть файл

@ -1 +1,5 @@
var sdkInstance="appInsightsSDK";window[sdkInstance]="appInsights";var aiName=window[sdkInstance],aisdk=window[aiName]||function(e){function n(e){t[e]=function(){var n=arguments;t.queue.push(function(){t[e].apply(t,n)})}}var t={config:e};t.initialize=!0;var i=document,a=window;setTimeout(function(){var n=i.createElement("script");n.src=e.url||"https://az416426.vo.msecnd.net/scripts/b/ai.2.min.js",i.getElementsByTagName("script")[0].parentNode.appendChild(n)});try{t.cookie=i.cookie}catch(e){}t.queue=[],t.version=2;for(var r=["Event","PageView","Exception","Trace","DependencyData","Metric","PageViewPerformance"];r.length;)n("track"+r.pop());n("startTrackPage"),n("stopTrackPage");var s="Track"+r[0];if(n("start"+s),n("stop"+s),n("addTelemetryInitializer"),n("setAuthenticatedUserContext"),n("clearAuthenticatedUserContext"),n("flush"),t.SeverityLevel={Verbose:0,Information:1,Warning:2,Error:3,Critical:4},!(!0===e.disableExceptionTracking||e.extensionConfig&&e.extensionConfig.ApplicationInsightsAnalytics&&!0===e.extensionConfig.ApplicationInsightsAnalytics.disableExceptionTracking)){n("_"+(r="onerror"));var o=a[r];a[r]=function(e,n,i,a,s){var c=o&&o(e,n,i,a,s);return!0!==c&&t["_"+r]({message:e,url:n,lineNumber:i,columnNumber:a,error:s}),c},e.autoExceptionInstrumented=!0}return t}({instrumentationKey:"INSTRUMENTATION_KEY"});window[aiName]=aisdk,aisdk.queue&&0===aisdk.queue.length&&aisdk.trackPageView({});
var sdkInstance="appInsightsSDK";window[sdkInstance]="appInsights";var aiName=window[sdkInstance],aisdk=window[aiName]||function(n){var o={config:n,initialize:!0},t=document,e=window,i="script";setTimeout(function(){var e=t.createElement(i);e.src=n.url||"https://az416426.vo.msecnd.net/scripts/b/ai.2.min.js",t.getElementsByTagName(i)[0].parentNode.appendChild(e)});try{o.cookie=t.cookie}catch(e){}function a(n){o[n]=function(){var e=arguments;o.queue.push(function(){o[n].apply(o,e)})}}o.queue=[],o.version=2;for(var s=["Event","PageView","Exception","Trace","DependencyData","Metric","PageViewPerformance"];s.length;)a("track"+s.pop());var r="Track",c=r+"Page";a("start"+c),a("stop"+c);var u=r+"Event";if(a("start"+u),a("stop"+u),a("addTelemetryInitializer"),a("setAuthenticatedUserContext"),a("clearAuthenticatedUserContext"),a("flush"),o.SeverityLevel={Verbose:0,Information:1,Warning:2,Error:3,Critical:4},!(!0===n.disableExceptionTracking||n.extensionConfig&&n.extensionConfig.ApplicationInsightsAnalytics&&!0===n.extensionConfig.ApplicationInsightsAnalytics.disableExceptionTracking)){a("_"+(s="onerror"));var p=e[s];e[s]=function(e,n,t,i,a){var r=p&&p(e,n,t,i,a);return!0!==r&&o["_"+s]({message:e,url:n,lineNumber:t,columnNumber:i,error:a}),r},n.autoExceptionInstrumented=!0}return o}(
{
instrumentationKey:"INSTRUMENTATION_KEY"
}
);(window[aiName]=aisdk).queue&&0===aisdk.queue.length&&aisdk.trackPageView({});

Просмотреть файл

@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { Initialization as ApplicationInsights, Snippet } from "./Initialization";
import { Initialization as ApplicationInsights, Telemetry, Snippet } from "./Initialization";
import { ApplicationInsightsContainer } from "./ApplicationInsightsContainer";
export { Initialization as ApplicationInsights, Snippet } from "./Initialization";
export { Initialization as ApplicationInsights, Telemetry, Snippet } from "./Initialization";
"use strict";
@ -45,6 +45,16 @@ try {
} else {
_logWarn(aiName, "Missing window");
}
// Hack: If legacy SDK exists, skip this step (Microsoft.ApplicationInsights exists).
// else write what was there for v2 SDK prior to rollup bundle output name change.
// e.g Microsoft.ApplicationInsights.ApplicationInsights, Microsoft.ApplicationInsights.Telemetry
if (typeof window !== Undefined && window && !((window as any).Microsoft && (window as any).Microsoft.ApplicationInsights)) {
(window as any).Microsoft = {
ApplicationInsights: {
ApplicationInsights, Telemetry
}
}
}
} catch (e) {
_logWarn(aiName, e.message);
}

Просмотреть файл

@ -3,12 +3,10 @@
import { CoreUtils, IConfiguration, AppInsightsCore, IAppInsightsCore, LoggingSeverity, _InternalMessageId, ITelemetryItem, ICustomProperties, IChannelControls, EventHelper, hasWindow, hasDocument } from "@microsoft/applicationinsights-core-js";
import { ApplicationInsights } from "@microsoft/applicationinsights-analytics-js";
import { Util, IConfig, IDependencyTelemetry, IPageViewPerformanceTelemetry,IPropertiesPlugin,
IPageViewTelemetry, IExceptionTelemetry, IAutoExceptionTelemetry, ITraceTelemetry, ITelemetryContext,
IMetricTelemetry, IEventTelemetry, IAppInsights, PropertiesPluginIdentifier, ConnectionStringParser } from "@microsoft/applicationinsights-common";
import { Sender } from "@microsoft/applicationinsights-channel-js";
import { PropertiesPlugin, TelemetryContext } from "@microsoft/applicationinsights-properties-js";
import { AjaxPlugin as DependenciesPlugin, IDependenciesPlugin } from '@microsoft/applicationinsights-dependencies-js';
import * as Common from "@microsoft/applicationinsights-common"
"use strict";
@ -18,17 +16,22 @@ import { AjaxPlugin as DependenciesPlugin, IDependenciesPlugin } from '@microsof
* @interface Snippet
*/
export interface Snippet {
config: IConfiguration & IConfig;
config: IConfiguration & Common.IConfig;
queue?: Array<() => void>;
version?: number;
}
export interface IApplicationInsights extends IAppInsights, IDependenciesPlugin, IPropertiesPlugin {
export interface IApplicationInsights extends Common.IAppInsights, IDependenciesPlugin, Common.IPropertiesPlugin {
appInsights: ApplicationInsights;
flush: (async?: boolean) => void;
onunloadFlush: (async?: boolean) => void;
};
/**
* Telemetry type classes, e.g. PageView, Exception, etc
*/
export const Telemetry = Common;
/**
* Application Insights API
* @class Initialization
@ -36,7 +39,7 @@ export interface IApplicationInsights extends IAppInsights, IDependenciesPlugin,
*/
export class Initialization implements IApplicationInsights {
public snippet: Snippet;
public config: IConfiguration & IConfig;
public config: IConfiguration & Common.IConfig;
public appInsights: ApplicationInsights;
public core: IAppInsightsCore;
public context: TelemetryContext;
@ -48,10 +51,10 @@ export class Initialization implements IApplicationInsights {
// initialize the queue and config in case they are undefined
snippet.queue = snippet.queue || [];
snippet.version = snippet.version || 2.0; // Default to new version
let config: IConfiguration & IConfig = snippet.config || ({} as any);
let config: IConfiguration & Common.IConfig = snippet.config || ({} as any);
if (config.connectionString) {
const cs = ConnectionStringParser.parse(config.connectionString);
const cs = Common.ConnectionStringParser.parse(config.connectionString);
const ingest = cs.ingestionendpoint;
config.endpointUrl = ingest ? `${ingest}/v2/track` : config.endpointUrl; // only add /v2/track when from connectionstring
config.instrumentationKey = cs.instrumentationkey || config.instrumentationKey;
@ -75,7 +78,7 @@ export class Initialization implements IApplicationInsights {
* @param {ICustomProperties} [customProperties]
* @memberof Initialization
*/
public trackEvent(event: IEventTelemetry, customProperties?: ICustomProperties) {
public trackEvent(event: Common.IEventTelemetry, customProperties?: ICustomProperties) {
this.appInsights.trackEvent(event, customProperties);
}
@ -84,7 +87,7 @@ export class Initialization implements IApplicationInsights {
* @param {IPageViewTelemetry} pageView
* @memberof Initialization
*/
public trackPageView(pageView?: IPageViewTelemetry) {
public trackPageView(pageView?: Common.IPageViewTelemetry) {
const inPv = pageView || {};
this.appInsights.trackPageView(inPv);
}
@ -94,7 +97,7 @@ export class Initialization implements IApplicationInsights {
* @param {IPageViewPerformanceTelemetry} pageViewPerformance
* @memberof Initialization
*/
public trackPageViewPerformance(pageViewPerformance: IPageViewPerformanceTelemetry): void {
public trackPageViewPerformance(pageViewPerformance: Common.IPageViewPerformanceTelemetry): void {
const inPvp = pageViewPerformance || {};
this.appInsights.trackPageViewPerformance(inPvp);
}
@ -104,7 +107,7 @@ export class Initialization implements IApplicationInsights {
* @param {IExceptionTelemetry} exception
* @memberof Initialization
*/
public trackException(exception: IExceptionTelemetry): void {
public trackException(exception: Common.IExceptionTelemetry): void {
if (!exception.exception && (exception as any).error) {
exception.exception = (exception as any).error;
}
@ -117,7 +120,7 @@ export class Initialization implements IApplicationInsights {
* @param {IAutoExceptionTelemetry} exception
* @memberof Initialization
*/
public _onerror(exception: IAutoExceptionTelemetry): void {
public _onerror(exception: Common.IAutoExceptionTelemetry): void {
this.appInsights._onerror(exception);
}
@ -127,7 +130,7 @@ export class Initialization implements IApplicationInsights {
* @param {ICustomProperties} [customProperties]
* @memberof Initialization
*/
public trackTrace(trace: ITraceTelemetry, customProperties?: ICustomProperties): void {
public trackTrace(trace: Common.ITraceTelemetry, customProperties?: ICustomProperties): void {
this.appInsights.trackTrace(trace, customProperties);
}
@ -145,7 +148,7 @@ export class Initialization implements IApplicationInsights {
* @param {ICustomProperties} [customProperties]
* @memberof Initialization
*/
public trackMetric(metric: IMetricTelemetry, customProperties?: ICustomProperties): void {
public trackMetric(metric: Common.IMetricTelemetry, customProperties?: ICustomProperties): void {
this.appInsights.trackMetric(metric, customProperties);
}
/**
@ -218,7 +221,7 @@ export class Initialization implements IApplicationInsights {
* @param {IDependencyTelemetry} dependency
* @memberof Initialization
*/
public trackDependencyData(dependency: IDependencyTelemetry): void {
public trackDependencyData(dependency: Common.IDependencyTelemetry): void {
this.dependencies.trackDependencyData(dependency);
}
@ -313,7 +316,7 @@ export class Initialization implements IApplicationInsights {
let _this = this;
// call functions that were queued before the main script was loaded
try {
if (Util.isArray(_this.snippet.queue)) {
if (Common.Util.isArray(_this.snippet.queue)) {
// note: do not check length in the for-loop conditional in case something goes wrong and the stub methods are not overridden.
const length = _this.snippet.queue.length;
for (let i = 0; i < length; i++) {
@ -360,7 +363,7 @@ export class Initialization implements IApplicationInsights {
// Back up the current session to local storage
// This lets us close expired sessions after the cookies themselves expire
const ext = appInsightsInstance.appInsights.core['_extensions'][PropertiesPluginIdentifier];
const ext = appInsightsInstance.appInsights.core['_extensions'][Common.PropertiesPluginIdentifier];
if (ext && ext.context && ext.context._sessionManager) {
ext.context._sessionManager.backup();
}

Просмотреть файл

@ -1,7 +1,8 @@
export {
IApplicationInsights,
Snippet,
Initialization as ApplicationInsights
Initialization as ApplicationInsights,
Telemetry
} from "./Initialization";
export { ApplicationInsightsContainer } from "./ApplicationInsightsContainer";

Просмотреть файл

@ -59,11 +59,11 @@ If your app does not use NPM, you can directly instrument your webpages with App
```html
<script type="text/javascript">
var sdkInstance="appInsightsSDK";window[sdkInstance]="appInsights";var aiName=window[sdkInstance],aisdk=window[aiName]||function(e){function n(e){t[e]=function(){var n=arguments;t.queue.push(function(){t[e].apply(t,n)})}}var t={config:e};t.initialize=!0;var i=document,a=window;setTimeout(function(){var n=i.createElement("script");n.src=e.url||"https://az416426.vo.msecnd.net/scripts/b/ai.2.min.js",i.getElementsByTagName("script")[0].parentNode.appendChild(n)});try{t.cookie=i.cookie}catch(e){}t.queue=[],t.version=2;for(var r=["Event","PageView","Exception","Trace","DependencyData","Metric","PageViewPerformance"];r.length;)n("track"+r.pop());n("startTrackPage"),n("stopTrackPage");var s="Track"+r[0];if(n("start"+s),n("stop"+s),n("addTelemetryInitializer"),n("setAuthenticatedUserContext"),n("clearAuthenticatedUserContext"),n("flush"),t.SeverityLevel={Verbose:0,Information:1,Warning:2,Error:3,Critical:4},!(!0===e.disableExceptionTracking||e.extensionConfig&&e.extensionConfig.ApplicationInsightsAnalytics&&!0===e.extensionConfig.ApplicationInsightsAnalytics.disableExceptionTracking)){n("_"+(r="onerror"));var o=a[r];a[r]=function(e,n,i,a,s){var c=o&&o(e,n,i,a,s);return!0!==c&&t["_"+r]({message:e,url:n,lineNumber:i,columnNumber:a,error:s}),c},e.autoExceptionInstrumented=!0}return t}(
var sdkInstance="appInsightsSDK";window[sdkInstance]="appInsights";var aiName=window[sdkInstance],aisdk=window[aiName]||function(n){var o={config:n,initialize:!0},t=document,e=window,i="script";setTimeout(function(){var e=t.createElement(i);e.src=n.url||"https://az416426.vo.msecnd.net/scripts/b/ai.2.min.js",t.getElementsByTagName(i)[0].parentNode.appendChild(e)});try{o.cookie=t.cookie}catch(e){}function a(n){o[n]=function(){var e=arguments;o.queue.push(function(){o[n].apply(o,e)})}}o.queue=[],o.version=2;for(var s=["Event","PageView","Exception","Trace","DependencyData","Metric","PageViewPerformance"];s.length;)a("track"+s.pop());var r="Track",c=r+"Page";a("start"+c),a("stop"+c);var u=r+"Event";if(a("start"+u),a("stop"+u),a("addTelemetryInitializer"),a("setAuthenticatedUserContext"),a("clearAuthenticatedUserContext"),a("flush"),o.SeverityLevel={Verbose:0,Information:1,Warning:2,Error:3,Critical:4},!(!0===n.disableExceptionTracking||n.extensionConfig&&n.extensionConfig.ApplicationInsightsAnalytics&&!0===n.extensionConfig.ApplicationInsightsAnalytics.disableExceptionTracking)){a("_"+(s="onerror"));var p=e[s];e[s]=function(e,n,t,i,a){var r=p&&p(e,n,t,i,a);return!0!==r&&o["_"+s]({message:e,url:n,lineNumber:t,columnNumber:i,error:a}),r},n.autoExceptionInstrumented=!0}return o}(
{
instrumentationKey:"INSTRUMENTATION_KEY"
}
);window[aiName]=aisdk,aisdk.queue&&0===aisdk.queue.length&&aisdk.trackPageView({});
);(window[aiName]=aisdk).queue&&0===aisdk.queue.length&&aisdk.trackPageView({});
</script>
```