applicationinsights-js
Advanced tools
Comparing version 0.22.14 to 0.22.17
@@ -118,3 +118,3 @@ <properties | ||
trackException(exception: Error, handledAt?: string, properties?: {[string]:string}, measurements?: {[string]:number}) | ||
trackException(exception: Error, handledAt?: string, properties?: {[string]:string}, measurements?: {[string]:number}, severityLevel?: AI.SeverityLevel) | ||
@@ -129,2 +129,3 @@ Log an exception you have caught. (Exceptions caught by the browser are also logged.) | ||
`measurements` | Map of string to number: Metrics associated with this page, displayed in Metrics Explorer on the portal. Defaults to empty. | ||
`severityLevel` | Supported values: [SeverityLevel.ts](https://github.com/Microsoft/ApplicationInsights-JS/blob/master/JavaScript/JavaScriptSDK/Contracts/Generated/SeverityLevel.ts) | ||
@@ -131,0 +132,0 @@ In the portal, you can [search on exception type and view](https://azure.microsoft.com/documentation/articles/app-insights-diagnostic-search/) the type, message, and stack trace of individual instances. |
{ | ||
"name": "applicationinsights-js", | ||
"main": "dist/ai.0.js", | ||
"version": "0.22.14", | ||
"version": "0.22.17", | ||
"homepage": "https://github.com/Microsoft/ApplicationInsights-JS", | ||
@@ -6,0 +6,0 @@ "authors": [ |
@@ -36,2 +36,19 @@ /// <reference path="../../testframework/common.ts" /> | ||
this.testCase({ | ||
name: name + "Exception is initialized with undefined severityLevel", | ||
test: () => { | ||
var telemetry = new Microsoft.ApplicationInsights.Telemetry.Exception(new Error("test error"), "HA"); | ||
Assert.equal(undefined, telemetry.severityLevel, "Exception shouldn't have severity level by default"); | ||
} | ||
}); | ||
this.testCase({ | ||
name: name + "User can override severityLevel", | ||
test: () => { | ||
var level = AI.SeverityLevel.Critical; | ||
var telemetry = new Microsoft.ApplicationInsights.Telemetry.Exception(new Error("test error"), "HA", null, null, level); | ||
Assert.equal(level, telemetry.severityLevel, "Exception has proper severity level"); | ||
} | ||
}); | ||
this.testCase({ | ||
name: name + "Exception stack is limited to 32kb", | ||
@@ -38,0 +55,0 @@ test: () => { |
@@ -25,2 +25,11 @@ /// <reference path="../checkintests/appinsights.tests.ts" /> | ||
/// <reference path="../checkintests/ajax.tests.ts" /> | ||
/// <reference path="../checkintests/SplitTest.tests.ts" /> | ||
/// <reference path="../checkintests/SplitTest.tests.ts" /> | ||
/* import modules */ | ||
import AppInsightsModuleTests from "../CheckinTests/AppInsightsModule.Tests" | ||
export default function registerTests() { | ||
/* for every module call registerTests() */ | ||
new AppInsightsModuleTests().registerTests(); | ||
} | ||
@@ -11,2 +11,3 @@ /// <reference path="telemetrycontext.ts" /> | ||
/// <reference path="./SplitTest.ts"/> | ||
/// <reference path="./IAppInsights.ts"/> | ||
@@ -17,30 +18,4 @@ module Microsoft.ApplicationInsights { | ||
export var Version = "0.22.14"; | ||
export var Version = "0.22.17"; | ||
export interface IConfig { | ||
instrumentationKey: string; | ||
endpointUrl: string; | ||
emitLineDelimitedJson: boolean; | ||
accountId: string; | ||
sessionRenewalMs: number; | ||
sessionExpirationMs: number; | ||
maxBatchSizeInBytes: number; | ||
maxBatchInterval: number; | ||
enableDebug: boolean; | ||
disableExceptionTracking: boolean; | ||
disableTelemetry: boolean; | ||
verboseLogging: boolean; | ||
diagnosticLogInterval: number; | ||
samplingPercentage: number; | ||
autoTrackPageVisitTime: boolean; | ||
disableAjaxTracking: boolean; | ||
overridePageViewDuration: boolean; | ||
maxAjaxCallsPerView: number; | ||
disableDataLossAnalysis: boolean; | ||
disableCorrelationHeaders: boolean; | ||
disableFlushOnBeforeUnload: boolean; | ||
enableSessionStorageBuffer: boolean; | ||
cookieDomain: string; | ||
} | ||
/** | ||
@@ -59,3 +34,3 @@ * Internal interface to pass appInsights object to subcomponents without coupling | ||
*/ | ||
export class AppInsights implements IAppInsightsInternal { | ||
export class AppInsights implements IAppInsightsInternal, IAppInsights { | ||
@@ -75,3 +50,3 @@ // Counts number of trackAjax invokations. | ||
public context: TelemetryContext; | ||
public queue: (() => void)[]; | ||
public static defaultConfig: IConfig; | ||
@@ -110,5 +85,2 @@ | ||
// enable session storage buffer experiment | ||
this.config.enableSessionStorageBuffer = new SplitTest().isEnabled(this.config.instrumentationKey, 10); ; | ||
this.context = new ApplicationInsights.TelemetryContext(configGetters); | ||
@@ -310,4 +282,5 @@ | ||
* @param measurements map[string, number] - metrics associated with this event, displayed in Metrics Explorer on the portal. Defaults to empty. | ||
* @param severityLevel AI.SeverityLevel - severity level | ||
*/ | ||
public trackException(exception: Error, handledAt?: string, properties?: Object, measurements?: Object) { | ||
public trackException(exception: Error, handledAt?: string, properties?: Object, measurements?: Object, severityLevel?: AI.SeverityLevel) { | ||
try { | ||
@@ -323,3 +296,3 @@ if (!Util.isError(exception)) { | ||
var exceptionTelemetry = new Telemetry.Exception(exception, handledAt, properties, measurements); | ||
var exceptionTelemetry = new Telemetry.Exception(exception, handledAt, properties, measurements, severityLevel); | ||
var data = new ApplicationInsights.Telemetry.Common.Data<ApplicationInsights.Telemetry.Exception>(Telemetry.Exception.dataType, exceptionTelemetry); | ||
@@ -326,0 +299,0 @@ var envelope = new Telemetry.Common.Envelope(data, Telemetry.Exception.envelopeType); |
@@ -1,5 +0,8 @@ | ||
module Microsoft.ApplicationInsights.Context { | ||
/// <reference path="IApplication.ts" /> | ||
module Microsoft.ApplicationInsights.Context { | ||
"use strict"; | ||
export class Application { | ||
export class Application implements IApplication { | ||
/** | ||
@@ -6,0 +9,0 @@ * The application version. |
@@ -1,5 +0,8 @@ | ||
module Microsoft.ApplicationInsights.Context { | ||
/// <reference path="IDevice.ts" /> | ||
module Microsoft.ApplicationInsights.Context { | ||
"use strict"; | ||
export class Device { | ||
export class Device implements IDevice { | ||
@@ -6,0 +9,0 @@ /** |
@@ -1,5 +0,8 @@ | ||
module Microsoft.ApplicationInsights.Context { | ||
/// <reference path="IInternal.ts"/> | ||
module Microsoft.ApplicationInsights.Context { | ||
"use strict"; | ||
export class Internal { | ||
export class Internal implements IInternal { | ||
@@ -6,0 +9,0 @@ /** |
@@ -1,5 +0,8 @@ | ||
module Microsoft.ApplicationInsights.Context { | ||
/// <reference path="ILocation.ts" /> | ||
module Microsoft.ApplicationInsights.Context { | ||
"use strict"; | ||
export class Location { | ||
export class Location implements ILocation { | ||
@@ -6,0 +9,0 @@ /** |
/// <reference path="../util.ts" /> | ||
/// <reference path="IOperation.ts" /> | ||
module Microsoft.ApplicationInsights.Context { | ||
"use strict"; | ||
export class Operation { | ||
export class Operation implements IOperation { | ||
@@ -15,3 +17,3 @@ public id: string; | ||
constructor() { | ||
this.id = Util.newId(); | ||
this.id = Util.newId(); | ||
if (window && window.location && window.location.pathname) { | ||
@@ -18,0 +20,0 @@ this.name = window.location.pathname; |
/// <reference path="../SamplingScoreGenerator.ts" /> | ||
/// <reference path="../Contracts/Generated/Envelope.ts" /> | ||
/// <reference path="ISample.ts" /> | ||
module Microsoft.ApplicationInsights.Context { | ||
"use strict"; | ||
export class Sample { | ||
export class Sample implements ISample { | ||
public sampleRate: number; | ||
@@ -29,3 +32,3 @@ private samplingScoreGenerator: SamplingScoreGenerator; | ||
*/ | ||
public isSampledIn(envelope: Telemetry.Common.Envelope): boolean { | ||
public isSampledIn(envelope: Microsoft.Telemetry.Envelope): boolean { | ||
if (this.sampleRate == 100) return true; | ||
@@ -32,0 +35,0 @@ |
/// <reference path="../util.ts" /> | ||
/// <reference path="../Contracts/Generated/SessionState.ts"/> | ||
/// <reference path="ISession.ts" /> | ||
module Microsoft.ApplicationInsights.Context { | ||
"use strict"; | ||
@@ -13,3 +15,3 @@ | ||
export class Session { | ||
export class Session implements ISession { | ||
/** | ||
@@ -16,0 +18,0 @@ * The session ID. |
/// <reference path="../util.ts" /> | ||
/// <reference path="IUser.ts" /> | ||
module Microsoft.ApplicationInsights.Context { | ||
"use strict"; | ||
export class User { | ||
export class User implements IUser { | ||
@@ -8,0 +10,0 @@ static cookieSeparator: string = '|'; |
@@ -8,2 +8,3 @@ module Microsoft.ApplicationInsights { | ||
static issuesReportedForThisSession; | ||
static itemsRestoredFromSessionBuffer: number = 0; | ||
static LIMIT_PER_SESSION = 10; | ||
@@ -16,2 +17,3 @@ static ITEMS_QUEUED_KEY = "AI_itemsQueued"; | ||
Util.setSessionStorage(DataLossAnalyzer.ITEMS_QUEUED_KEY, "0"); | ||
DataLossAnalyzer.itemsRestoredFromSessionBuffer = 0; | ||
} | ||
@@ -77,4 +79,6 @@ } | ||
var lostItems = DataLossAnalyzer.getNumberOfLostItems() - DataLossAnalyzer.itemsRestoredFromSessionBuffer; | ||
DataLossAnalyzer.appInsights.trackTrace( | ||
"AI (Internal): Internal report DATALOSS:\"" + DataLossAnalyzer.getNumberOfLostItems() + "\"", | ||
"AI (Internal): Internal report DATALOSS:\"" + lostItems + "\"", | ||
null); | ||
@@ -81,0 +85,0 @@ DataLossAnalyzer.appInsights.flush(); |
/// <reference path="./HashCodeScoreGenerator.ts" /> | ||
/// <reference path="./Contracts/Generated/Envelope.ts" /> | ||
@@ -11,3 +12,3 @@ module Microsoft.ApplicationInsights { | ||
public getSamplingScore(envelope: Telemetry.Common.Envelope): number { | ||
public getSamplingScore(envelope: Microsoft.Telemetry.Envelope): number { | ||
var tagKeys: AI.ContextTagKeys = new AI.ContextTagKeys(); | ||
@@ -14,0 +15,0 @@ var score: number = 0; |
@@ -127,2 +127,5 @@ /// <reference path="serializer.ts" /> | ||
// update DataLossAnalyzer with the number of recovered items | ||
DataLossAnalyzer.itemsRestoredFromSessionBuffer = this._buffer.length; | ||
this.setBuffer(SessionStorageSendBuffer.BUFFER_KEY, this._buffer); | ||
@@ -129,0 +132,0 @@ this.setBuffer(SessionStorageSendBuffer.SENT_BUFFER_KEY, []); |
@@ -5,2 +5,3 @@ /// <reference path="serializer.ts" /> | ||
/// <reference path="Contracts/Generated/ContextTagKeys.ts"/> | ||
/// <reference path="Contracts/Generated/Envelope.ts" /> | ||
/// <reference path="Context/Application.ts"/> | ||
@@ -106,3 +107,3 @@ /// <reference path="Context/Device.ts"/> | ||
*/ | ||
public send(envelope: Telemetry.Common.Envelope) { | ||
public send(envelope: Microsoft.Telemetry.Envelope) { | ||
try { | ||
@@ -128,3 +129,3 @@ // if master off switch is set, don't send any data | ||
// check if the incoming payload is too large, truncate if necessary | ||
var payload: string = Serializer.serialize(envelope); | ||
var payload: string = Serializer.serialize(<ISerializable><any>envelope); | ||
@@ -131,0 +132,0 @@ // flush if we would exceet the max-size limit by adding this item |
@@ -26,3 +26,3 @@ /// <reference path="../Contracts/Generated/ExceptionData.ts" /> | ||
*/ | ||
constructor(exception: Error, handledAt?: string, properties?: Object, measurements?: Object) { | ||
constructor(exception: Error, handledAt?: string, properties?: Object, measurements?: Object, severityLevel?: AI.SeverityLevel) { | ||
super(); | ||
@@ -35,2 +35,6 @@ | ||
this.exceptions = [new _ExceptionDetails(exception)]; | ||
if (severityLevel) { | ||
this.severityLevel = severityLevel; | ||
} | ||
} | ||
@@ -37,0 +41,0 @@ |
@@ -10,2 +10,3 @@ /// <reference path="sender.ts"/> | ||
/// <reference path="./Contracts/Generated/SessionState.ts"/> | ||
/// <reference path="ITelemetryContext.ts" /> | ||
@@ -25,3 +26,3 @@ module Microsoft.ApplicationInsights { | ||
export class TelemetryContext { | ||
export class TelemetryContext implements ITelemetryContext { | ||
/** | ||
@@ -103,3 +104,3 @@ * The configuration for this telemetry context | ||
*/ | ||
public addTelemetryInitializer(telemetryInitializer: (envelope: Telemetry.Common.Envelope) => boolean) { | ||
public addTelemetryInitializer(telemetryInitializer: (envelope: Microsoft.Telemetry.Envelope) => boolean) { | ||
this.telemetryInitializers = this.telemetryInitializers || []; | ||
@@ -112,3 +113,3 @@ this.telemetryInitializers.push(telemetryInitializer); | ||
*/ | ||
public track(envelope: Telemetry.Common.Envelope) { | ||
public track(envelope: Microsoft.Telemetry.Envelope) { | ||
if (!envelope) { | ||
@@ -135,3 +136,3 @@ _InternalLogging.throwInternalUserActionable(LoggingSeverity.CRITICAL, new _InternalLogMessage(_InternalMessageId.USRACT_TrackArgumentsNotSpecified, "cannot call .track() with a null or undefined argument")); | ||
private _track(envelope: Telemetry.Common.Envelope) { | ||
private _track(envelope: Microsoft.Telemetry.Envelope) { | ||
@@ -138,0 +139,0 @@ if (this.session) { |
{ | ||
"name": "applicationinsights-js", | ||
"version": "0.22.14", | ||
"description": "[Application Insights](https://azure.microsoft.com/services/application-insights/) tells you about your app\u0027s performance and usage. By adding a few lines of code to your web pages, you get data about how many users you have, which pages are most popular, how fast pages load, whether they throw exceptions, and more. And you can add code to track more detailed user activity.", | ||
"main": "dist/ai.0.js", | ||
"version": "0.22.17", | ||
"description": "Microsoft Application Insights JavaScript SDK", | ||
"main": "JavaScriptSDK/AppInsightsModule", | ||
"keywords": [ | ||
"browser performance monitoring", | ||
"script errors", | ||
"application insights", | ||
"microsoft", | ||
"azure" | ||
], | ||
"scripts": { | ||
@@ -13,3 +20,3 @@ "test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"author": "Microsoft Application Insights Team", | ||
"license": "MIT", | ||
@@ -16,0 +23,0 @@ "bugs": { |
@@ -10,13 +10,73 @@ # Microsoft Application Insights JavaScript SDK | ||
To use this SDK, you'll need a subscription to [Microsoft Azure](https://azure.com). (There's a free package.) | ||
To use this SDK, you'll need a subscription to [Microsoft Azure](https://azure.com). Application Insights has a free subscription option. | ||
In the [Azure Preview Portal](https://portal.azure.com), create new or open an existing Application Insights resource. | ||
In the [Azure Preview Portal](https://portal.azure.com), open an Application Insights resource. | ||
## Initializing Application Insights JS SDK script | ||
There are several ways to initialize Aplication Insights. | ||
Get "code to monitor my web pages" from the Quick Start page, and insert it in the head of your web pages. | ||
| | **Dynamic loading.** JS script tag is inserted in the head of the page. This is the recommended approach as our CDN is getting frequent updates. | **Static loading.** You are responsible for including JS script tag or bundling the script with your other scripts. | | ||
|------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------| | ||
| **Using initialization `snippet`** | [Dynamic loading with snippet](README.md#use-js-snippet-and-initialize-dynamically-download-full-application-insights-script-from-cdn) This is default approach used in a new ASP.NET application created in Visual Studio. Use this for MVC applications. | [Host AI JS SDK and initialize statically](README.md#include-ai-js-sdk-script-and-initialize-statically). Cordova applications where you would like to embed scripts into your application for faster loading is an example of when you would use this approach. | | ||
| **Using module import** | [Dynamic loading using module import](README.md#import-as-a-module-and-initialize-dynamically-download-full-application-insights-script-from-cdn). This is the recommended approach for modern modular applications. | [TBD](issues/213) | | ||
Use your web pages, and then look for user and page view results in the Application Insights resource. | ||
### Use JS `snippet` and initialize dynamically (download full Application Insights script from CDN) | ||
Use this method for an MVC application. Get "code to monitor my web pages" from the Quick Start page, | ||
and insert it in the head of your web pages. Application Insights script will be downloaded | ||
from CDN or you can override the script hosting location by specifying `url` parameter in the config. | ||
``` | ||
<script type="text/javascript"> | ||
var appInsights = window.appInsights || function (config) { | ||
function s(config) { t[config] = function () { var i = arguments; t.queue.push(function () { t[config].apply(t, i) }) } } var t = { config: config }, r = document, f = window, e = "script", o = r.createElement(e), i, u; for (o.src = config.url || "//az416426.vo.msecnd.net/scripts/a/ai.0.js", r.getElementsByTagName(e)[0].parentNode.appendChild(o), t.cookie = r.cookie, t.queue = [], i = ["Event", "Exception", "Metric", "PageView", "Trace"]; i.length;) s("track" + i.pop()); return config.disableExceptionTracking || (i = "onerror", s("_" + i), u = f[i], f[i] = function (config, r, f, e, o) { var s = u && u(config, r, f, e, o); return s !== !0 && t["_" + i](config, r, f, e, o), s }), t | ||
}({ | ||
instrumentationKey: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" | ||
}); | ||
window.appInsights = appInsights; | ||
appInsights.trackPageView(); | ||
</script> | ||
``` | ||
[Learn more.](https://azure.microsoft.com/documentation/articles/app-insights-javascript/) | ||
### Import as a module and initialize dynamically (download full Application Insights script from CDN) | ||
Use this method for a modern JS application that is using modules. Just like in `snippet` scenario the full script will be downloaded from CDN. | ||
* Obtain instrumentation key from your Application Insights resource | ||
* Install applicationinsights-js with npm | ||
`npm install applicationinsights-js` | ||
* Import and call `downloadAndSetup` to initialize it. You can override the script hosting location by specifying `url` parameter in the config | ||
``` | ||
/* import AppInsights */ | ||
import {AppInsights} from "applicationinsights-js" | ||
/* Call downloadAndSetup to download full ApplicationInsights script from CDN and initialize it with instrumentation key */ | ||
AppInsights.downloadAndSetup({ instrumentationKey: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" }); | ||
/* example: track page view */ | ||
AppInsights.trackPageView( | ||
"FirstPage", /* (optional) page name */ | ||
null, /* (optional) page url if available */ | ||
{ prop1: "prop1", prop2: "prop2" }, /* (optional) dimension dictionary */ | ||
{ measurement1: 1 }, /* (optional) metric dictionary */ | ||
123 /* page view duration in milliseconds */ | ||
); | ||
/* example: track event */ | ||
AppInsights.trackEvent("TestEvent", { prop1: "prop1", prop2: "prop2" }, { measurement1: 1 }); | ||
``` | ||
### Include AI JS SDK script and initialize statically | ||
Use this approach if you would like to host AI JS SDK script on your endpoint or bundle it with other scripts. One popular example is Cordova applications (see [this blog post](http://www.teamfoundation.co.za/2016/02/application-insights-and-typescript/). After JS script has loaded, include the following snippet to initialize Application Insights: | ||
``` | ||
<!-- the snippet below assumes that JS SDK script has already loaded --> | ||
<script type="text/javascript" src="/pathToAIJSSDK.js"></script> | ||
<script type="text/javascript"> | ||
var snippet: any = { | ||
config: { | ||
instrumentationKey: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" | ||
} | ||
}; | ||
var init = new Microsoft.ApplicationInsights.Initialization(snippet); | ||
var appInsights = init.loadAppInsights(); | ||
appInsights.trackPageView(); | ||
</script> | ||
``` | ||
## API reference | ||
@@ -23,0 +83,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
13122503
234
36360
0
113