Skip to content

Commit

Permalink
Merge branch 'master' into MSNev/AddSameSiteUserAgentCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
MSNev committed Jan 28, 2020
2 parents eba7874 + 18162ec commit 76f8c0c
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 34 deletions.
1 change: 1 addition & 0 deletions AISKU/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions AISKU/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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: [
Expand Down
4 changes: 2 additions & 2 deletions AISKU/snippet/snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion AISKU/snippet/snippet.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions AISKU/src/Init.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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);
}
39 changes: 21 additions & 18 deletions AISKU/src/Initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -18,25 +16,30 @@ 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
* @implements {IApplicationInsights}
*/
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;
Expand All @@ -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;
Expand All @@ -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);
}

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}
/**
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion AISKU/src/applicationinsights-web.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export {
IApplicationInsights,
Snippet,
Initialization as ApplicationInsights
Initialization as ApplicationInsights,
Telemetry
} from "./Initialization";

export { ApplicationInsightsContainer } from "./ApplicationInsightsContainer";
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
```

Expand Down Expand Up @@ -193,7 +193,7 @@ Most configuration fields are named such that they can be defaulted to falsey. A
| sessionExpirationMs | 86400000 | A session is logged if it has continued for this amount of time in milliseconds. Default is 24 hours |
| maxBatchSizeInBytes | 10000 | Max size of telemetry batch. If a batch exceeds this limit, it is immediately sent and a new batch is started |
| maxBatchInterval | 15000 | How long to batch telemetry for before sending (milliseconds) |
| disableExceptionTracking | false | If true, exceptions are no autocollected. Default is false. |
| disableExceptionTracking | false | If true, exceptions are not autocollected. Default is false. |
| disableTelemetry | false | If true, telemetry is not collected or sent. Default is false. |
| enableDebug | false | If true, **internal** debugging data is thrown as an exception **instead** of being logged, regardless of SDK logging settings. Default is false. <br>***Note:*** Enabling this setting will result in dropped telemetry whenever an internal error occurs. This can be useful for quickly identifying issues with your configuration or usage of the SDK. If you do not want to lose telemetry while debugging, consider using `consoleLoggingLevel` or `telemetryLoggingLevel` instead of `enableDebug`. |
| loggingLevelConsole | 0 | Logs **internal** Application Insights errors to console. <br>0: off, <br>1: Critical errors only, <br>2: Everything (errors & warnings) |
Expand Down
8 changes: 4 additions & 4 deletions shared/AppInsightsCommon/src/Interfaces/IConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export interface IConfig {
samplingPercentage?: number;

/**
* @description
* @description If true, on a pageview,the previous instrumented page's view time is tracked and sent as telemetry and a new timer is started for the current pageview. Default is false.
* @type {boolean}
* @memberof IConfig
*/
Expand Down Expand Up @@ -263,7 +263,7 @@ export interface IConfig {
appId?: string;

/**
* @description If true, the SDK will add two headers ('Request-Id' and 'Request-Context') to all CORS requests tocorrelate outgoing AJAX dependencies with corresponding requests on the server side. Default is false
* @description If true, the SDK will add two headers ('Request-Id' and 'Request-Context') to all CORS requests to correlate outgoing AJAX dependencies with corresponding requests on the server side. Default is false
* @type {boolean}
* @memberof IConfig
* @defaultValue false
Expand All @@ -287,15 +287,15 @@ export interface IConfig {
enableRequestHeaderTracking?: boolean;

/**
* @description An optional value that will track Resonse Header through trackDependency function.
* @description An optional value that will track Response Header through trackDependency function.
* @type {boolean}
* @memberof IConfig
* @defaultValue false
*/
enableResponseHeaderTracking?: boolean;

/**
* @description An optional value that will track Resonse Error data through trackDependency function.
* @description An optional value that will track Response Error data through trackDependency function.
* @type {boolean}
* @memberof IConfig
* @defaultValue false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { _InternalLogMessage, DiagnosticLogger } from "./DiagnosticLogger";
"use strict";

export class AppInsightsCore extends BaseCore implements IAppInsightsCore {
public baseCore: BaseCore;
public config: IConfiguration;
public logger: IDiagnosticLogger;

Expand Down

0 comments on commit 76f8c0c

Please sign in to comment.