2 (function (Microsoft) {
3 var ApplicationInsights;
4 (function (ApplicationInsights) {
5 (function (LoggingSeverity) {
6 LoggingSeverity[LoggingSeverity["CRITICAL"] = 0] = "CRITICAL";
7 LoggingSeverity[LoggingSeverity["WARNING"] = 1] = "WARNING";
8 })(ApplicationInsights.LoggingSeverity || (ApplicationInsights.LoggingSeverity = {}));
9 var LoggingSeverity = ApplicationInsights.LoggingSeverity;
10 var _InternalLogging = (function () {
11 function _InternalLogging() {
13 _InternalLogging.throwInternalNonUserActionable = function (severity, message) {
14 if (this.enableDebugExceptions()) {
18 this.warnToConsole(message);
19 this.logInternalMessage(severity, this.AiNonUserActionablePrefix + message);
22 _InternalLogging.throwInternalUserActionable = function (severity, message) {
23 if (this.enableDebugExceptions()) {
27 this.warnToConsole(message);
28 this.logInternalMessage(severity, this.AiUserActionablePrefix + message);
31 _InternalLogging.warnToConsole = function (message) {
32 if (typeof console !== "undefined" && !!console) {
33 if (typeof console.warn === "function") {
34 console.warn(message);
36 else if (typeof console.log === "function") {
41 _InternalLogging.resetInternalMessageCount = function () {
42 this._messageCount = 0;
44 _InternalLogging.setMaxInternalMessageLimit = function (limit) {
46 throw new Error('limit cannot be undefined.');
48 this.MAX_INTERNAL_MESSAGE_LIMIT = limit;
50 _InternalLogging.logInternalMessage = function (severity, message) {
51 if (this._areInternalMessagesThrottled()) {
54 if (this.verboseLogging() || severity === 0 /* CRITICAL */) {
55 this.queue.push(message);
58 if (this._messageCount == this.MAX_INTERNAL_MESSAGE_LIMIT) {
59 var throttleLimitMessage = this.AiNonUserActionablePrefix + "Internal events throttle limit per PageView reached for this app.";
60 this.queue.push(throttleLimitMessage);
61 this.warnToConsole(throttleLimitMessage);
64 _InternalLogging._areInternalMessagesThrottled = function () {
65 return this._messageCount >= this.MAX_INTERNAL_MESSAGE_LIMIT;
67 _InternalLogging.AiUserActionablePrefix = "AI: ";
68 _InternalLogging.AiNonUserActionablePrefix = "AI (Internal): ";
69 _InternalLogging.enableDebugExceptions = function () { return false; };
70 _InternalLogging.verboseLogging = function () { return false; };
71 _InternalLogging.queue = [];
72 _InternalLogging.MAX_INTERNAL_MESSAGE_LIMIT = 25;
73 _InternalLogging._messageCount = 0;
74 return _InternalLogging;
76 ApplicationInsights._InternalLogging = _InternalLogging;
77 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
78 })(Microsoft || (Microsoft = {}));
80 (function (Microsoft) {
81 var ApplicationInsights;
82 (function (ApplicationInsights) {
83 var Util = (function () {
86 Util._getStorageObject = function () {
88 if (window.localStorage) {
89 return window.localStorage;
96 ApplicationInsights._InternalLogging.warnToConsole('Failed to get client localStorage: ' + e.message);
100 Util.canUseLocalStorage = function () {
101 return !!Util._getStorageObject();
103 Util.getStorage = function (name) {
104 var storage = Util._getStorageObject();
105 if (storage !== null) {
107 return storage.getItem(name);
110 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "Browser failed read of local storage." + Util.dump(e));
115 Util.setStorage = function (name, data) {
116 var storage = Util._getStorageObject();
117 if (storage !== null) {
119 storage.setItem(name, data);
123 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "Browser failed write to local storage." + Util.dump(e));
128 Util.removeStorage = function (name) {
129 var storage = Util._getStorageObject();
130 if (storage !== null) {
132 storage.removeItem(name);
136 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "Browser failed removal of local storage item." + Util.dump(e));
141 Util._getSessionStorageObject = function () {
143 if (window.sessionStorage) {
144 return window.sessionStorage;
151 ApplicationInsights._InternalLogging.warnToConsole('Failed to get client session storage: ' + e.message);
155 Util.canUseSessionStorage = function () {
156 return !!Util._getSessionStorageObject();
158 Util.getSessionStorage = function (name) {
159 var storage = Util._getSessionStorageObject();
160 if (storage !== null) {
162 return storage.getItem(name);
165 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Browser failed read of session storage." + Util.dump(e));
170 Util.setSessionStorage = function (name, data) {
171 var storage = Util._getSessionStorageObject();
172 if (storage !== null) {
174 storage.setItem(name, data);
178 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Browser failed write to session storage." + Util.dump(e));
183 Util.removeSessionStorage = function (name) {
184 var storage = Util._getSessionStorageObject();
185 if (storage !== null) {
187 storage.removeItem(name);
191 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Browser failed removal of session storage item." + Util.dump(e));
196 Util.setCookie = function (name, value) {
197 Util.document.cookie = name + "=" + value + ";path=/";
199 Util.stringToBoolOrDefault = function (str) {
203 return str.toString().toLowerCase() === "true";
205 Util.getCookie = function (name) {
207 if (name && name.length) {
208 var cookieName = name + "=";
209 var cookies = Util.document.cookie.split(";");
210 for (var i = 0; i < cookies.length; i++) {
211 var cookie = cookies[i];
212 cookie = Util.trim(cookie);
213 if (cookie && cookie.indexOf(cookieName) === 0) {
214 value = cookie.substring(cookieName.length, cookies[i].length);
221 Util.deleteCookie = function (name) {
222 Util.document.cookie = name + "=;path=/;expires=Thu, 01 Jan 1970 00:00:01 GMT;";
224 Util.trim = function (str) {
225 if (typeof str !== "string")
227 return str.replace(/^\s+|\s+$/g, "");
229 Util.newGuid = function () {
230 var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"];
232 for (var a = 0; a < 4; a++) {
233 tmp = (4294967296 * Math.random()) | 0;
234 oct += hexValues[tmp & 0xF] + hexValues[tmp >> 4 & 0xF] + hexValues[tmp >> 8 & 0xF] + hexValues[tmp >> 12 & 0xF] + hexValues[tmp >> 16 & 0xF] + hexValues[tmp >> 20 & 0xF] + hexValues[tmp >> 24 & 0xF] + hexValues[tmp >> 28 & 0xF];
236 var clockSequenceHi = hexValues[8 + (Math.random() * 4) | 0];
237 return oct.substr(0, 8) + "-" + oct.substr(9, 4) + "-4" + oct.substr(13, 3) + "-" + clockSequenceHi + oct.substr(16, 3) + "-" + oct.substr(19, 12);
239 Util.isArray = function (obj) {
240 return Object.prototype.toString.call(obj) === "[object Array]";
242 Util.isError = function (obj) {
243 return Object.prototype.toString.call(obj) === "[object Error]";
245 Util.isDate = function (obj) {
246 return Object.prototype.toString.call(obj) === "[object Date]";
248 Util.toISOStringForIE8 = function (date) {
249 if (Util.isDate(date)) {
250 if (Date.prototype.toISOString) {
251 return date.toISOString();
254 function pad(number) {
255 var r = String(number);
256 if (r.length === 1) {
261 return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) + "T" + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds()) + "." + String((date.getUTCMilliseconds() / 1000).toFixed(3)).slice(2, 5) + "Z";
265 Util.msToTimeSpan = function (totalms) {
266 if (isNaN(totalms) || totalms < 0) {
269 var ms = "" + totalms % 1000;
270 var sec = "" + Math.floor(totalms / 1000) % 60;
271 var min = "" + Math.floor(totalms / (1000 * 60)) % 60;
272 var hour = "" + Math.floor(totalms / (1000 * 60 * 60)) % 24;
273 ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
274 sec = sec.length < 2 ? "0" + sec : sec;
275 min = min.length < 2 ? "0" + min : min;
276 hour = hour.length < 2 ? "0" + hour : hour;
277 return hour + ":" + min + ":" + sec + "." + ms;
279 Util.isCrossOriginError = function (message, url, lineNumber, columnNumber, error) {
280 return (message == "Script error." || message == "Script error") && url == "" && lineNumber == 0 && columnNumber == 0 && error == null;
282 Util.dump = function (object) {
283 var objectTypeDump = Object.prototype.toString.call(object);
284 var propertyValueDump = JSON.stringify(object);
285 if (objectTypeDump === "[object Error]") {
286 propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
288 return objectTypeDump + propertyValueDump;
290 Util.addEventHandler = function (eventName, callback) {
291 if (!window || typeof eventName !== 'string' || typeof callback !== 'function') {
294 var verbEventName = 'on' + eventName;
295 if (window.addEventListener) {
296 window.addEventListener(eventName, callback, false);
298 else if (window.attachEvent) {
299 window.attachEvent(verbEventName, callback);
306 Util.document = typeof document !== "undefined" ? document : {};
307 Util.NotSpecified = "not_specified";
310 ApplicationInsights.Util = Util;
311 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
312 })(Microsoft || (Microsoft = {}));
314 (function (Microsoft) {
315 var ApplicationInsights;
316 (function (ApplicationInsights) {
318 var Serializer = (function () {
319 function Serializer() {
321 Serializer.serialize = function (input) {
322 var output = Serializer._serializeObject(input, "root");
323 return JSON.stringify(output);
325 Serializer._serializeObject = function (source, name) {
326 var circularReferenceCheck = "__aiCircularRefCheck";
329 ApplicationInsights._InternalLogging.throwInternalUserActionable(0 /* CRITICAL */, "cannot serialize " + name + " because it is null or undefined");
332 if (source[circularReferenceCheck]) {
333 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "Circular reference detected while serializing: '" + name);
336 if (!source.aiDataContract) {
337 if (name === "measurements") {
338 output = Serializer._serializeStringMap(source, "number", name);
340 else if (name === "properties") {
341 output = Serializer._serializeStringMap(source, "string", name);
343 else if (name === "tags") {
344 output = Serializer._serializeStringMap(source, "string", name);
346 else if (ApplicationInsights.Util.isArray(source)) {
347 output = Serializer._serializeArray(source, name);
350 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "Attempting to serialize an object which does not implement ISerializable: " + name);
352 JSON.stringify(source);
356 ApplicationInsights._InternalLogging.throwInternalUserActionable(0 /* CRITICAL */, e && typeof e.toString === 'function' ? e.toString() : "Error serializing object");
361 source[circularReferenceCheck] = true;
362 for (var field in source.aiDataContract) {
363 var isRequired = source.aiDataContract[field];
364 var isArray = typeof isRequired !== "boolean";
365 var isPresent = source[field] !== undefined;
366 var isObject = typeof source[field] === "object" && source[field] !== null;
367 if (isRequired && !isPresent && !isArray) {
368 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Missing required field specification: The field '" + field + "' on '" + name + "' is required but not present on source");
374 value = Serializer._serializeArray(source[field], field);
377 value = Serializer._serializeObject(source[field], field);
381 value = source[field];
383 if (value !== undefined) {
384 output[field] = value;
387 delete source[circularReferenceCheck];
390 Serializer._serializeArray = function (sources, name) {
391 var output = undefined;
393 if (!ApplicationInsights.Util.isArray(sources)) {
394 ApplicationInsights._InternalLogging.throwInternalUserActionable(0 /* CRITICAL */, "This field was specified as an array in the contract but the item is not an array.\r\n" + name);
398 for (var i = 0; i < sources.length; i++) {
399 var source = sources[i];
400 var item = Serializer._serializeObject(source, name + "[" + i + "]");
407 Serializer._serializeStringMap = function (map, expectedType, name) {
408 var output = undefined;
411 for (var field in map) {
412 var value = map[field];
413 if (expectedType === "string") {
414 if (value === undefined) {
415 output[field] = "undefined";
417 else if (value === null) {
418 output[field] = "null";
420 else if (!value.toString) {
421 output[field] = "invalid field: toString() is not defined.";
424 output[field] = value.toString();
427 else if (expectedType === "number") {
428 if (value === undefined) {
429 output[field] = "undefined";
431 else if (value === null) {
432 output[field] = "null";
435 var num = parseFloat(value);
437 output[field] = "NaN";
445 output[field] = "invalid field: " + name + " is of unknown type.";
446 ApplicationInsights._InternalLogging.throwInternalUserActionable(0 /* CRITICAL */, output[field]);
454 ApplicationInsights.Serializer = Serializer;
455 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
456 })(Microsoft || (Microsoft = {}));
458 (function (Microsoft) {
460 (function (Telemetry) {
462 var Base = (function () {
467 Telemetry.Base = Base;
468 })(Telemetry = Microsoft.Telemetry || (Microsoft.Telemetry = {}));
469 })(Microsoft || (Microsoft = {}));
471 (function (Microsoft) {
473 (function (Telemetry) {
475 var Envelope = (function () {
476 function Envelope() {
478 this.sampleRate = 100.0;
483 Telemetry.Envelope = Envelope;
484 })(Telemetry = Microsoft.Telemetry || (Microsoft.Telemetry = {}));
485 })(Microsoft || (Microsoft = {}));
486 var __extends = this.__extends || function (d, b) {
487 for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
488 function __() { this.constructor = d; }
489 __.prototype = b.prototype;
490 d.prototype = new __();
493 (function (Microsoft) {
494 var ApplicationInsights;
495 (function (ApplicationInsights) {
497 (function (Telemetry) {
501 var Envelope = (function (_super) {
502 __extends(Envelope, _super);
503 function Envelope(data, name) {
507 this.time = ApplicationInsights.Util.toISOStringForIE8(new Date());
508 this.aiDataContract = {
517 })(Microsoft.Telemetry.Envelope);
518 Common.Envelope = Envelope;
519 })(Common = Telemetry.Common || (Telemetry.Common = {}));
520 })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
521 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
522 })(Microsoft || (Microsoft = {}));
524 (function (Microsoft) {
525 var ApplicationInsights;
526 (function (ApplicationInsights) {
528 (function (Telemetry) {
532 var Base = (function (_super) {
533 __extends(Base, _super);
535 _super.apply(this, arguments);
536 this.aiDataContract = {};
539 })(Microsoft.Telemetry.Base);
541 })(Common = Telemetry.Common || (Telemetry.Common = {}));
542 })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
543 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
544 })(Microsoft || (Microsoft = {}));
548 var ContextTagKeys = (function () {
549 function ContextTagKeys() {
550 this.applicationVersion = "ai.application.ver";
551 this.applicationBuild = "ai.application.build";
552 this.applicationTypeId = "ai.application.typeId";
553 this.deviceId = "ai.device.id";
554 this.deviceIp = "ai.device.ip";
555 this.deviceLanguage = "ai.device.language";
556 this.deviceLocale = "ai.device.locale";
557 this.deviceModel = "ai.device.model";
558 this.deviceNetwork = "ai.device.network";
559 this.deviceNetworkName = "ai.device.networkName";
560 this.deviceOEMName = "ai.device.oemName";
561 this.deviceOS = "ai.device.os";
562 this.deviceOSVersion = "ai.device.osVersion";
563 this.deviceRoleInstance = "ai.device.roleInstance";
564 this.deviceRoleName = "ai.device.roleName";
565 this.deviceScreenResolution = "ai.device.screenResolution";
566 this.deviceType = "ai.device.type";
567 this.deviceMachineName = "ai.device.machineName";
568 this.deviceVMName = "ai.device.vmName";
569 this.locationIp = "ai.location.ip";
570 this.operationId = "ai.operation.id";
571 this.operationName = "ai.operation.name";
572 this.operationParentId = "ai.operation.parentId";
573 this.operationRootId = "ai.operation.rootId";
574 this.operationSyntheticSource = "ai.operation.syntheticSource";
575 this.operationIsSynthetic = "ai.operation.isSynthetic";
576 this.sessionId = "ai.session.id";
577 this.sessionIsFirst = "ai.session.isFirst";
578 this.sessionIsNew = "ai.session.isNew";
579 this.userAccountAcquisitionDate = "ai.user.accountAcquisitionDate";
580 this.userAccountId = "ai.user.accountId";
581 this.userAgent = "ai.user.userAgent";
582 this.userId = "ai.user.id";
583 this.userStoreRegion = "ai.user.storeRegion";
584 this.userAuthUserId = "ai.user.authUserId";
585 this.userAnonymousUserAcquisitionDate = "ai.user.anonUserAcquisitionDate";
586 this.userAuthenticatedUserAcquisitionDate = "ai.user.authUserAcquisitionDate";
587 this.sampleRate = "ai.sample.sampleRate";
588 this.internalSdkVersion = "ai.internal.sdkVersion";
589 this.internalAgentVersion = "ai.internal.agentVersion";
590 this.internalDataCollectorReceivedTime = "ai.internal.dataCollectorReceivedTime";
591 this.internalProfileId = "ai.internal.profileId";
592 this.internalProfileClassId = "ai.internal.profileClassId";
593 this.internalAccountId = "ai.internal.accountId";
594 this.internalApplicationName = "ai.internal.applicationName";
595 this.internalInstrumentationKey = "ai.internal.instrumentationKey";
596 this.internalTelemetryItemId = "ai.internal.telemetryItemId";
597 this.internalApplicationType = "ai.internal.applicationType";
598 this.internalRequestSource = "ai.internal.requestSource";
599 this.internalFlowType = "ai.internal.flowType";
600 this.internalIsAudit = "ai.internal.isAudit";
601 this.internalTrackingSourceId = "ai.internal.trackingSourceId";
602 this.internalTrackingType = "ai.internal.trackingType";
604 return ContextTagKeys;
606 AI.ContextTagKeys = ContextTagKeys;
609 (function (Microsoft) {
610 var ApplicationInsights;
611 (function (ApplicationInsights) {
613 (function (Context) {
615 var Application = (function () {
616 function Application() {
620 Context.Application = Application;
621 })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
622 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
623 })(Microsoft || (Microsoft = {}));
625 (function (Microsoft) {
626 var ApplicationInsights;
627 (function (ApplicationInsights) {
629 (function (Context) {
631 var Device = (function () {
634 if (typeof screen !== "undefined" && screen.width && screen.height) {
635 this.resolution = screen.width + "X" + screen.height;
637 this.locale = (typeof screen !== "undefined" && navigator.browserLanguage) ? navigator.browserLanguage : "unknown";
641 Context.Device = Device;
642 })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
643 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
644 })(Microsoft || (Microsoft = {}));
646 (function (Microsoft) {
647 var ApplicationInsights;
648 (function (ApplicationInsights) {
650 (function (Context) {
652 var Internal = (function () {
653 function Internal() {
654 this.sdkVersion = "JavaScript:" + ApplicationInsights.Version;
658 Context.Internal = Internal;
659 })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
660 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
661 })(Microsoft || (Microsoft = {}));
663 (function (Microsoft) {
664 var ApplicationInsights;
665 (function (ApplicationInsights) {
667 (function (Context) {
669 var Location = (function () {
670 function Location() {
674 Context.Location = Location;
675 })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
676 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
677 })(Microsoft || (Microsoft = {}));
679 (function (Microsoft) {
680 var ApplicationInsights;
681 (function (ApplicationInsights) {
683 (function (Context) {
685 var Operation = (function () {
686 function Operation() {
687 this.id = ApplicationInsights.Util.newGuid();
691 Context.Operation = Operation;
692 })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
693 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
694 })(Microsoft || (Microsoft = {}));
696 (function (Microsoft) {
697 var ApplicationInsights;
698 (function (ApplicationInsights) {
699 var SamplingScoreGenerator = (function () {
700 function SamplingScoreGenerator() {
702 SamplingScoreGenerator.getScore = function (envelope) {
703 var tagKeys = new AI.ContextTagKeys();
705 if (envelope.tags[tagKeys.userId]) {
706 score = SamplingScoreGenerator.getSamplingHashCode(envelope.tags[tagKeys.userId]) / SamplingScoreGenerator.INT_MAX_VALUE;
708 else if (envelope.tags[tagKeys.operationId]) {
709 score = SamplingScoreGenerator.getSamplingHashCode(envelope.tags[tagKeys.operationId]) / SamplingScoreGenerator.INT_MAX_VALUE;
712 score = Math.random();
716 SamplingScoreGenerator.getSamplingHashCode = function (input) {
721 for (var i = 0; i < input.length; ++i) {
722 hash = ((hash << 5) + hash) + input.charCodeAt(i);
725 return Math.abs(hash);
727 SamplingScoreGenerator.INT_MAX_VALUE = 2147483647;
728 return SamplingScoreGenerator;
730 ApplicationInsights.SamplingScoreGenerator = SamplingScoreGenerator;
731 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
732 })(Microsoft || (Microsoft = {}));
734 (function (Microsoft) {
735 var ApplicationInsights;
736 (function (ApplicationInsights) {
738 (function (Context) {
740 var Sample = (function () {
741 function Sample(sampleRate) {
742 this.INT_MAX_VALUE = 2147483647;
743 if (sampleRate > 100 || sampleRate < 0) {
744 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "Sampling rate is out of range (0..100): '" + sampleRate + "'. Sampling will be disabled, you may be sending too much data which may affect your AI service level.");
745 this.sampleRate = 100;
747 this.sampleRate = sampleRate;
749 Sample.prototype.isSampledIn = function (envelope) {
750 if (this.sampleRate == 100)
752 var score = ApplicationInsights.SamplingScoreGenerator.getScore(envelope);
753 return score < this.sampleRate;
757 Context.Sample = Sample;
758 })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
759 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
760 })(Microsoft || (Microsoft = {}));
764 (function (SessionState) {
765 SessionState[SessionState["Start"] = 0] = "Start";
766 SessionState[SessionState["End"] = 1] = "End";
767 })(AI.SessionState || (AI.SessionState = {}));
768 var SessionState = AI.SessionState;
771 (function (Microsoft) {
772 var ApplicationInsights;
773 (function (ApplicationInsights) {
775 (function (Context) {
777 var Session = (function () {
782 Context.Session = Session;
783 var _SessionManager = (function () {
784 function _SessionManager(config, sessionHandler) {
788 if (!(typeof config.sessionExpirationMs === "function")) {
789 config.sessionExpirationMs = function () { return _SessionManager.acquisitionSpan; };
791 if (!(typeof config.sessionRenewalMs === "function")) {
792 config.sessionRenewalMs = function () { return _SessionManager.renewalSpan; };
794 this.config = config;
795 this._sessionHandler = sessionHandler;
796 this.automaticSession = new Session();
798 _SessionManager.prototype.update = function () {
799 if (!this.automaticSession.id) {
800 this.initializeAutomaticSession();
803 var acquisitionExpired = now - this.automaticSession.acquisitionDate > this.config.sessionExpirationMs();
804 var renewalExpired = now - this.automaticSession.renewalDate > this.config.sessionRenewalMs();
805 if (acquisitionExpired || renewalExpired) {
806 if (typeof this._sessionHandler === "function") {
807 this._sessionHandler(1 /* End */, this.automaticSession.renewalDate);
809 this.automaticSession.isFirst = undefined;
813 this.automaticSession.renewalDate = +new Date;
814 this.setCookie(this.automaticSession.id, this.automaticSession.acquisitionDate, this.automaticSession.renewalDate);
817 _SessionManager.prototype.backup = function () {
818 this.setStorage(this.automaticSession.id, this.automaticSession.acquisitionDate, this.automaticSession.renewalDate);
820 _SessionManager.prototype.initializeAutomaticSession = function () {
821 var cookie = ApplicationInsights.Util.getCookie('ai_session');
822 if (cookie && typeof cookie.split === "function") {
823 this.initializeAutomaticSessionWithData(cookie);
826 var storage = ApplicationInsights.Util.getStorage('ai_session');
828 this.initializeAutomaticSessionWithData(storage);
831 if (!this.automaticSession.id) {
832 this.automaticSession.isFirst = true;
836 _SessionManager.prototype.initializeAutomaticSessionWithData = function (sessionData) {
837 var params = sessionData.split("|");
838 if (params.length > 0) {
839 this.automaticSession.id = params[0];
842 if (params.length > 1) {
843 var acq = +params[1];
844 this.automaticSession.acquisitionDate = +new Date(acq);
845 this.automaticSession.acquisitionDate = this.automaticSession.acquisitionDate > 0 ? this.automaticSession.acquisitionDate : 0;
847 if (params.length > 2) {
848 var renewal = +params[2];
849 this.automaticSession.renewalDate = +new Date(renewal);
850 this.automaticSession.renewalDate = this.automaticSession.renewalDate > 0 ? this.automaticSession.renewalDate : 0;
854 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Error parsing ai_session cookie, session will be reset: " + ApplicationInsights.Util.dump(e));
856 if (this.automaticSession.renewalDate == 0) {
857 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "AI session renewal date is 0, session will be reset.");
860 _SessionManager.prototype.renew = function () {
862 this.automaticSession.id = ApplicationInsights.Util.newGuid();
863 this.automaticSession.acquisitionDate = now;
864 this.automaticSession.renewalDate = now;
865 this.setCookie(this.automaticSession.id, this.automaticSession.acquisitionDate, this.automaticSession.renewalDate);
866 if (typeof this._sessionHandler === "function") {
867 this._sessionHandler(0 /* Start */, now);
869 if (!ApplicationInsights.Util.canUseLocalStorage()) {
870 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "Browser does not support local storage. Session durations will be inaccurate.");
873 _SessionManager.prototype.setCookie = function (guid, acq, renewal) {
874 var acquisitionExpiry = acq + this.config.sessionExpirationMs();
875 var renewalExpiry = renewal + this.config.sessionRenewalMs();
876 var cookieExpiry = new Date();
877 var cookie = [guid, acq, renewal];
878 if (acquisitionExpiry < renewalExpiry) {
879 cookieExpiry.setTime(acquisitionExpiry);
882 cookieExpiry.setTime(renewalExpiry);
884 ApplicationInsights.Util.setCookie('ai_session', cookie.join('|') + ';expires=' + cookieExpiry.toUTCString());
886 _SessionManager.prototype.setStorage = function (guid, acq, renewal) {
887 ApplicationInsights.Util.setStorage('ai_session', [guid, acq, renewal].join('|'));
889 _SessionManager.acquisitionSpan = 86400000;
890 _SessionManager.renewalSpan = 1800000;
891 return _SessionManager;
893 Context._SessionManager = _SessionManager;
894 })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
895 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
896 })(Microsoft || (Microsoft = {}));
898 (function (Microsoft) {
899 var ApplicationInsights;
900 (function (ApplicationInsights) {
902 (function (Context) {
904 var User = (function () {
905 function User(accountId) {
906 var cookie = ApplicationInsights.Util.getCookie(User.userCookieName);
908 var params = cookie.split(User.cookieSeparator);
909 if (params.length > 0) {
914 this.id = ApplicationInsights.Util.newGuid();
915 var date = new Date();
916 var acqStr = ApplicationInsights.Util.toISOStringForIE8(date);
917 this.accountAcquisitionDate = acqStr;
918 date.setTime(date.getTime() + 31536000000);
919 var newCookie = [this.id, acqStr];
920 ApplicationInsights.Util.setCookie(User.userCookieName, newCookie.join(User.cookieSeparator) + ';expires=' + date.toUTCString());
921 ApplicationInsights.Util.removeStorage('ai_session');
923 this.accountId = accountId;
924 var authCookie = ApplicationInsights.Util.getCookie(User.authUserCookieName);
926 authCookie = decodeURI(authCookie);
927 var authCookieString = authCookie.split(User.cookieSeparator);
928 if (authCookieString[0]) {
929 this.authenticatedId = authCookieString[0];
931 if (authCookieString.length > 1 && authCookieString[1]) {
932 this.accountId = authCookieString[1];
936 User.prototype.setAuthenticatedUserContext = function (authenticatedUserId, accountId) {
937 var isInvalidInput = !this.validateUserInput(authenticatedUserId) || (accountId && !this.validateUserInput(accountId));
938 if (isInvalidInput) {
939 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "Setting auth user context failed. " + "User auth/account id should be of type string, and not contain commas, semi-colons, equal signs, spaces, or vertical-bars.");
942 this.authenticatedId = authenticatedUserId;
943 var authCookie = this.authenticatedId;
945 this.accountId = accountId;
946 authCookie = [this.authenticatedId, this.accountId].join(User.cookieSeparator);
948 ApplicationInsights.Util.setCookie(User.authUserCookieName, encodeURI(authCookie));
950 User.prototype.clearAuthenticatedUserContext = function () {
951 this.authenticatedId = null;
952 this.accountId = null;
953 ApplicationInsights.Util.deleteCookie(User.authUserCookieName);
955 User.prototype.validateUserInput = function (id) {
956 if (typeof id !== 'string' || !id || id.match(/,|;|=| |\|/)) {
961 User.cookieSeparator = '|';
962 User.userCookieName = 'ai_user';
963 User.authUserCookieName = 'ai_authUser';
967 })(Context = ApplicationInsights.Context || (ApplicationInsights.Context = {}));
968 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
969 })(Microsoft || (Microsoft = {}));
971 (function (Microsoft) {
972 var ApplicationInsights;
973 (function (ApplicationInsights) {
975 var Sender = (function () {
976 function Sender(config) {
979 this._config = config;
981 if (typeof XMLHttpRequest != "undefined") {
982 var testXhr = new XMLHttpRequest();
983 if ("withCredentials" in testXhr) {
984 this._sender = this._xhrSender;
986 else if (typeof XDomainRequest !== "undefined") {
987 this._sender = this._xdrSender;
991 Sender.prototype.send = function (envelope) {
994 if (this._config.disableTelemetry()) {
998 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Cannot send empty telemetry");
1001 if (!this._sender) {
1002 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Sender was not initialized");
1005 var payload = ApplicationInsights.Serializer.serialize(envelope);
1006 if (this._getSizeInBytes(this._buffer) + payload.length > this._config.maxBatchSizeInBytes()) {
1009 this._buffer.push(payload);
1010 if (!this._timeoutHandle) {
1011 this._timeoutHandle = setTimeout(function () {
1012 _this._timeoutHandle = null;
1013 _this.triggerSend();
1014 }, this._config.maxBatchInterval());
1018 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Failed adding telemetry to the sender's buffer, some telemetry will be lost: " + ApplicationInsights.Util.dump(e));
1021 Sender.prototype._getSizeInBytes = function (list) {
1023 if (list && list.length) {
1024 for (var i = 0; i < list.length; i++) {
1026 if (item && item.length) {
1027 size += item.length;
1033 Sender.prototype.triggerSend = function (async) {
1035 if (typeof async === 'boolean') {
1039 if (!this._config.disableTelemetry()) {
1040 if (this._buffer.length) {
1041 var batch = this._config.emitLineDelimitedJson() ? this._buffer.join("\n") : "[" + this._buffer.join(",") + "]";
1042 this._sender(batch, isAsync);
1044 this._lastSend = +new Date;
1046 this._buffer.length = 0;
1047 clearTimeout(this._timeoutHandle);
1048 this._timeoutHandle = null;
1051 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "Telemetry transmission failed, some telemetry will be lost: " + ApplicationInsights.Util.dump(e));
1054 Sender.prototype._xhrSender = function (payload, isAsync) {
1055 var xhr = new XMLHttpRequest();
1056 xhr.open("POST", this._config.endpointUrl(), isAsync);
1057 xhr.setRequestHeader("Content-type", "application/json");
1058 xhr.onreadystatechange = function () { return Sender._xhrReadyStateChange(xhr, payload); };
1059 xhr.onerror = function (event) { return Sender._onError(payload, xhr.responseText || xhr.response || "", event); };
1062 Sender.prototype._xdrSender = function (payload, isAsync) {
1063 var xdr = new XDomainRequest();
1064 xdr.onload = function () { return Sender._xdrOnLoad(xdr, payload); };
1065 xdr.onerror = function (event) { return Sender._onError(payload, xdr.responseText || "", event); };
1066 xdr.open('POST', this._config.endpointUrl());
1069 Sender._xhrReadyStateChange = function (xhr, payload) {
1070 if (xhr.readyState === 4) {
1071 if ((xhr.status < 200 || xhr.status >= 300) && xhr.status !== 0) {
1072 Sender._onError(payload, xhr.responseText || xhr.response || "");
1075 Sender._onSuccess(payload);
1079 Sender._xdrOnLoad = function (xdr, payload) {
1080 if (xdr && (xdr.responseText + "" === "200" || xdr.responseText === "")) {
1081 Sender._onSuccess(payload);
1084 Sender._onError(payload, xdr && xdr.responseText || "");
1087 Sender._onError = function (payload, message, event) {
1088 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "Failed to send telemetry:\n" + message);
1090 Sender._onSuccess = function (payload) {
1094 ApplicationInsights.Sender = Sender;
1095 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1096 })(Microsoft || (Microsoft = {}));
1098 (function (Microsoft) {
1100 (function (Telemetry) {
1102 var Domain = (function () {
1107 Telemetry.Domain = Domain;
1108 })(Telemetry = Microsoft.Telemetry || (Microsoft.Telemetry = {}));
1109 })(Microsoft || (Microsoft = {}));
1113 (function (SeverityLevel) {
1114 SeverityLevel[SeverityLevel["Verbose"] = 0] = "Verbose";
1115 SeverityLevel[SeverityLevel["Information"] = 1] = "Information";
1116 SeverityLevel[SeverityLevel["Warning"] = 2] = "Warning";
1117 SeverityLevel[SeverityLevel["Error"] = 3] = "Error";
1118 SeverityLevel[SeverityLevel["Critical"] = 4] = "Critical";
1119 })(AI.SeverityLevel || (AI.SeverityLevel = {}));
1120 var SeverityLevel = AI.SeverityLevel;
1121 })(AI || (AI = {}));
1125 var MessageData = (function (_super) {
1126 __extends(MessageData, _super);
1127 function MessageData() {
1129 this.properties = {};
1133 })(Microsoft.Telemetry.Domain);
1134 AI.MessageData = MessageData;
1135 })(AI || (AI = {}));
1137 (function (Microsoft) {
1138 var ApplicationInsights;
1139 (function (ApplicationInsights) {
1141 (function (Telemetry) {
1143 (function (Common) {
1145 var DataSanitizer = (function () {
1146 function DataSanitizer() {
1148 DataSanitizer.sanitizeKeyAndAddUniqueness = function (key, map) {
1149 var origLength = key.length;
1150 var field = DataSanitizer.sanitizeKey(key);
1151 if (field.length !== origLength) {
1153 var uniqueField = field;
1154 while (map[uniqueField] !== undefined) {
1156 uniqueField = field.substring(0, DataSanitizer.MAX_NAME_LENGTH - 3) + DataSanitizer.padNumber(i);
1158 field = uniqueField;
1162 DataSanitizer.sanitizeKey = function (name) {
1164 name = ApplicationInsights.Util.trim(name.toString());
1165 if (name.search(/[^0-9a-zA-Z-._()\/ ]/g) >= 0) {
1166 name = name.replace(/[^0-9a-zA-Z-._()\/ ]/g, "_");
1167 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "name contains illegal characters. Illgeal character have been replaced with '_'. new name: " + name);
1169 if (name.length > DataSanitizer.MAX_NAME_LENGTH) {
1170 name = name.substring(0, DataSanitizer.MAX_NAME_LENGTH);
1171 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "name is too long. It has been truncated to " + DataSanitizer.MAX_NAME_LENGTH + " characters. name: " + name);
1176 DataSanitizer.sanitizeString = function (value) {
1178 value = ApplicationInsights.Util.trim(value);
1179 if (value.toString().length > DataSanitizer.MAX_STRING_LENGTH) {
1180 value = value.substring(0, DataSanitizer.MAX_STRING_LENGTH);
1181 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "string value is too long. It has been truncated to " + DataSanitizer.MAX_STRING_LENGTH + " characters. value: " + value);
1186 DataSanitizer.sanitizeUrl = function (url) {
1188 if (url.length > DataSanitizer.MAX_URL_LENGTH) {
1189 url = url.substring(0, DataSanitizer.MAX_URL_LENGTH);
1190 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "url is too long, it has been trucated to " + DataSanitizer.MAX_URL_LENGTH + " characters. url: " + url);
1195 DataSanitizer.sanitizeMessage = function (message) {
1197 if (message.length > DataSanitizer.MAX_MESSAGE_LENGTH) {
1198 message = message.substring(0, DataSanitizer.MAX_MESSAGE_LENGTH);
1199 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "message is too long, it has been trucated to " + DataSanitizer.MAX_MESSAGE_LENGTH + " characters. message: " + message);
1204 DataSanitizer.sanitizeException = function (exception) {
1206 if (exception.length > DataSanitizer.MAX_EXCEPTION_LENGTH) {
1207 exception = exception.substring(0, DataSanitizer.MAX_EXCEPTION_LENGTH);
1208 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "exception is too long, iit has been trucated to " + DataSanitizer.MAX_EXCEPTION_LENGTH + " characters. exception: " + exception);
1213 DataSanitizer.sanitizeProperties = function (properties) {
1216 for (var prop in properties) {
1217 var value = DataSanitizer.sanitizeString(properties[prop]);
1218 prop = DataSanitizer.sanitizeKeyAndAddUniqueness(prop, tempProps);
1219 tempProps[prop] = value;
1221 properties = tempProps;
1225 DataSanitizer.sanitizeMeasurements = function (measurements) {
1227 var tempMeasurements = {};
1228 for (var measure in measurements) {
1229 var value = measurements[measure];
1230 measure = DataSanitizer.sanitizeKeyAndAddUniqueness(measure, tempMeasurements);
1231 tempMeasurements[measure] = value;
1233 measurements = tempMeasurements;
1235 return measurements;
1237 DataSanitizer.padNumber = function (num) {
1239 return s.substr(s.length - 3);
1241 DataSanitizer.MAX_NAME_LENGTH = 150;
1242 DataSanitizer.MAX_STRING_LENGTH = 1024;
1243 DataSanitizer.MAX_URL_LENGTH = 2048;
1244 DataSanitizer.MAX_MESSAGE_LENGTH = 32768;
1245 DataSanitizer.MAX_EXCEPTION_LENGTH = 32768;
1246 return DataSanitizer;
1248 Common.DataSanitizer = DataSanitizer;
1249 })(Common = Telemetry.Common || (Telemetry.Common = {}));
1250 })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1251 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1252 })(Microsoft || (Microsoft = {}));
1254 (function (Microsoft) {
1255 var ApplicationInsights;
1256 (function (ApplicationInsights) {
1258 (function (Telemetry) {
1260 var Trace = (function (_super) {
1261 __extends(Trace, _super);
1262 function Trace(message, properties) {
1264 this.aiDataContract = {
1267 severityLevel: false,
1268 measurements: false,
1271 message = message || ApplicationInsights.Util.NotSpecified;
1272 this.message = Telemetry.Common.DataSanitizer.sanitizeMessage(message);
1273 this.properties = Telemetry.Common.DataSanitizer.sanitizeProperties(properties);
1275 Trace.envelopeType = "Microsoft.ApplicationInsights.Message";
1276 Trace.dataType = "MessageData";
1279 Telemetry.Trace = Trace;
1280 })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1281 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1282 })(Microsoft || (Microsoft = {}));
1286 var EventData = (function (_super) {
1287 __extends(EventData, _super);
1288 function EventData() {
1290 this.properties = {};
1291 this.measurements = {};
1295 })(Microsoft.Telemetry.Domain);
1296 AI.EventData = EventData;
1297 })(AI || (AI = {}));
1299 (function (Microsoft) {
1300 var ApplicationInsights;
1301 (function (ApplicationInsights) {
1303 (function (Telemetry) {
1305 var Event = (function (_super) {
1306 __extends(Event, _super);
1307 function Event(name, properties, measurements) {
1309 this.aiDataContract = {
1315 this.name = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeString(name);
1316 this.properties = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeProperties(properties);
1317 this.measurements = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeMeasurements(measurements);
1319 Event.envelopeType = "Microsoft.ApplicationInsights.Event";
1320 Event.dataType = "EventData";
1323 Telemetry.Event = Event;
1324 })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1325 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1326 })(Microsoft || (Microsoft = {}));
1330 var ExceptionDetails = (function () {
1331 function ExceptionDetails() {
1332 this.hasFullStack = true;
1333 this.parsedStack = [];
1335 return ExceptionDetails;
1337 AI.ExceptionDetails = ExceptionDetails;
1338 })(AI || (AI = {}));
1342 var ExceptionData = (function (_super) {
1343 __extends(ExceptionData, _super);
1344 function ExceptionData() {
1346 this.exceptions = [];
1347 this.properties = {};
1348 this.measurements = {};
1351 return ExceptionData;
1352 })(Microsoft.Telemetry.Domain);
1353 AI.ExceptionData = ExceptionData;
1354 })(AI || (AI = {}));
1358 var StackFrame = (function () {
1359 function StackFrame() {
1363 AI.StackFrame = StackFrame;
1364 })(AI || (AI = {}));
1366 (function (Microsoft) {
1367 var ApplicationInsights;
1368 (function (ApplicationInsights) {
1370 (function (Telemetry) {
1372 var Exception = (function (_super) {
1373 __extends(Exception, _super);
1374 function Exception(exception, handledAt, properties, measurements) {
1376 this.aiDataContract = {
1380 severityLevel: false,
1384 this.properties = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeProperties(properties);
1385 this.measurements = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeMeasurements(measurements);
1386 this.handledAt = handledAt || "unhandled";
1387 this.exceptions = [new _ExceptionDetails(exception)];
1389 Exception.CreateSimpleException = function (message, typeName, assembly, fileName, details, line, handledAt) {
1390 var exceptionTelemetry;
1395 exceptionTelemetry = new Telemetry.Exception(e);
1397 var stack = exceptionTelemetry.exceptions[0].parsedStack[0];
1398 stack.assembly = assembly;
1399 stack.fileName = fileName;
1402 stack.method = "unknown";
1403 var exception = exceptionTelemetry.exceptions[0];
1404 exception.hasFullStack = true;
1405 exception.message = message;
1406 exception.parsedStack = null;
1407 exception.stack = details;
1408 exception.typeName = typeName;
1409 exceptionTelemetry.handledAt = handledAt || "unhandled";
1410 return exceptionTelemetry;
1412 Exception.envelopeType = "Microsoft.ApplicationInsights.Exception";
1413 Exception.dataType = "ExceptionData";
1415 })(AI.ExceptionData);
1416 Telemetry.Exception = Exception;
1417 var _ExceptionDetails = (function (_super) {
1418 __extends(_ExceptionDetails, _super);
1419 function _ExceptionDetails(exception) {
1421 this.aiDataContract = {
1426 hasFullStack: false,
1430 this.typeName = Telemetry.Common.DataSanitizer.sanitizeString(exception.name || ApplicationInsights.Util.NotSpecified);
1431 this.message = Telemetry.Common.DataSanitizer.sanitizeMessage(exception.message || ApplicationInsights.Util.NotSpecified);
1432 var stack = exception["stack"];
1433 this.parsedStack = this.parseStack(stack);
1434 this.stack = Telemetry.Common.DataSanitizer.sanitizeException(stack);
1435 this.hasFullStack = ApplicationInsights.Util.isArray(this.parsedStack) && this.parsedStack.length > 0;
1437 _ExceptionDetails.prototype.parseStack = function (stack) {
1438 var parsedStack = undefined;
1439 if (typeof stack === "string") {
1440 var frames = stack.split('\n');
1443 var totalSizeInBytes = 0;
1444 for (var i = 0; i <= frames.length; i++) {
1445 var frame = frames[i];
1446 if (_StackFrame.regex.test(frame)) {
1447 var parsedFrame = new _StackFrame(frames[i], level++);
1448 totalSizeInBytes += parsedFrame.sizeInBytes;
1449 parsedStack.push(parsedFrame);
1452 var exceptionParsedStackThreshold = 32 * 1024;
1453 if (totalSizeInBytes > exceptionParsedStackThreshold) {
1455 var right = parsedStack.length - 1;
1457 var acceptedLeft = left;
1458 var acceptedRight = right;
1459 while (left < right) {
1460 var lSize = parsedStack[left].sizeInBytes;
1461 var rSize = parsedStack[right].sizeInBytes;
1462 size += lSize + rSize;
1463 if (size > exceptionParsedStackThreshold) {
1464 var howMany = acceptedRight - acceptedLeft + 1;
1465 parsedStack.splice(acceptedLeft, howMany);
1468 acceptedLeft = left;
1469 acceptedRight = right;
1477 return _ExceptionDetails;
1478 })(AI.ExceptionDetails);
1479 var _StackFrame = (function (_super) {
1480 __extends(_StackFrame, _super);
1481 function _StackFrame(frame, level) {
1483 this.sizeInBytes = 0;
1484 this.aiDataContract = {
1492 this.method = "unavailable";
1493 this.assembly = ApplicationInsights.Util.trim(frame);
1494 var matches = frame.match(_StackFrame.regex);
1495 if (matches && matches.length >= 5) {
1496 this.method = ApplicationInsights.Util.trim(matches[2]);
1497 this.fileName = ApplicationInsights.Util.trim(matches[4]);
1498 this.line = parseInt(matches[5]) || 0;
1500 this.sizeInBytes += this.method.length;
1501 this.sizeInBytes += this.fileName.length;
1502 this.sizeInBytes += this.assembly.length;
1503 this.sizeInBytes += _StackFrame.baseSize;
1504 this.sizeInBytes += this.level.toString().length;
1505 this.sizeInBytes += this.line.toString().length;
1507 _StackFrame.regex = /^([\s]+at)?(.*?)(\@|\s\(|\s)([^\(\@\n]+):([0-9]+):([0-9]+)(\)?)$/;
1508 _StackFrame.baseSize = 58;
1511 })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1512 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1513 })(Microsoft || (Microsoft = {}));
1517 var MetricData = (function (_super) {
1518 __extends(MetricData, _super);
1519 function MetricData() {
1522 this.properties = {};
1526 })(Microsoft.Telemetry.Domain);
1527 AI.MetricData = MetricData;
1528 })(AI || (AI = {}));
1532 (function (DataPointType) {
1533 DataPointType[DataPointType["Measurement"] = 0] = "Measurement";
1534 DataPointType[DataPointType["Aggregation"] = 1] = "Aggregation";
1535 })(AI.DataPointType || (AI.DataPointType = {}));
1536 var DataPointType = AI.DataPointType;
1537 })(AI || (AI = {}));
1541 var DataPoint = (function () {
1542 function DataPoint() {
1543 this.kind = 0 /* Measurement */;
1547 AI.DataPoint = DataPoint;
1548 })(AI || (AI = {}));
1550 (function (Microsoft) {
1551 var ApplicationInsights;
1552 (function (ApplicationInsights) {
1554 (function (Telemetry) {
1556 (function (Common) {
1558 var DataPoint = (function (_super) {
1559 __extends(DataPoint, _super);
1560 function DataPoint() {
1561 _super.apply(this, arguments);
1562 this.aiDataContract = {
1574 Common.DataPoint = DataPoint;
1575 })(Common = Telemetry.Common || (Telemetry.Common = {}));
1576 })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1577 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1578 })(Microsoft || (Microsoft = {}));
1580 (function (Microsoft) {
1581 var ApplicationInsights;
1582 (function (ApplicationInsights) {
1584 (function (Telemetry) {
1586 var Metric = (function (_super) {
1587 __extends(Metric, _super);
1588 function Metric(name, value, count, min, max, properties) {
1590 this.aiDataContract = {
1595 var dataPoint = new Microsoft.ApplicationInsights.Telemetry.Common.DataPoint();
1596 dataPoint.count = count > 0 ? count : undefined;
1597 dataPoint.max = isNaN(max) || max === null ? undefined : max;
1598 dataPoint.min = isNaN(min) || min === null ? undefined : min;
1599 dataPoint.name = Telemetry.Common.DataSanitizer.sanitizeString(name);
1600 dataPoint.value = value;
1601 this.metrics = [dataPoint];
1602 this.properties = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeProperties(properties);
1604 Metric.envelopeType = "Microsoft.ApplicationInsights.Metric";
1605 Metric.dataType = "MetricData";
1608 Telemetry.Metric = Metric;
1609 })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1610 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1611 })(Microsoft || (Microsoft = {}));
1615 var PageViewData = (function (_super) {
1616 __extends(PageViewData, _super);
1617 function PageViewData() {
1619 this.properties = {};
1620 this.measurements = {};
1623 return PageViewData;
1625 AI.PageViewData = PageViewData;
1626 })(AI || (AI = {}));
1628 (function (Microsoft) {
1629 var ApplicationInsights;
1630 (function (ApplicationInsights) {
1632 (function (Telemetry) {
1634 var PageView = (function (_super) {
1635 __extends(PageView, _super);
1636 function PageView(name, url, durationMs, properties, measurements) {
1638 this.aiDataContract = {
1646 this.url = Telemetry.Common.DataSanitizer.sanitizeUrl(url);
1647 this.name = Telemetry.Common.DataSanitizer.sanitizeString(name || ApplicationInsights.Util.NotSpecified);
1648 if (!isNaN(durationMs)) {
1649 this.duration = ApplicationInsights.Util.msToTimeSpan(durationMs);
1651 this.properties = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeProperties(properties);
1652 this.measurements = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeMeasurements(measurements);
1654 PageView.envelopeType = "Microsoft.ApplicationInsights.Pageview";
1655 PageView.dataType = "PageviewData";
1657 })(AI.PageViewData);
1658 Telemetry.PageView = PageView;
1659 })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1660 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1661 })(Microsoft || (Microsoft = {}));
1665 var PageViewPerfData = (function (_super) {
1666 __extends(PageViewPerfData, _super);
1667 function PageViewPerfData() {
1669 this.properties = {};
1670 this.measurements = {};
1673 return PageViewPerfData;
1674 })(AI.PageViewData);
1675 AI.PageViewPerfData = PageViewPerfData;
1676 })(AI || (AI = {}));
1678 (function (Microsoft) {
1679 var ApplicationInsights;
1680 (function (ApplicationInsights) {
1682 (function (Telemetry) {
1684 var PageViewPerformance = (function (_super) {
1685 __extends(PageViewPerformance, _super);
1686 function PageViewPerformance(name, url, durationMs, properties, measurements) {
1688 this.aiDataContract = {
1694 networkConnect: false,
1696 receivedResponse: false,
1697 domProcessing: false,
1701 this.isValid = false;
1702 var timing = PageViewPerformance.getPerformanceTiming();
1704 var total = PageViewPerformance.getDuration(timing.navigationStart, timing.loadEventEnd);
1705 var network = PageViewPerformance.getDuration(timing.navigationStart, timing.connectEnd);
1706 var request = PageViewPerformance.getDuration(timing.requestStart, timing.responseStart);
1707 var response = PageViewPerformance.getDuration(timing.responseStart, timing.responseEnd);
1708 var dom = PageViewPerformance.getDuration(timing.responseEnd, timing.loadEventEnd);
1710 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "error calculating page view performance: total='" + total + "', network='" + network + "', request='" + request + "', response='" + response + "', dom='" + dom + "'");
1712 else if (total < Math.floor(network) + Math.floor(request) + Math.floor(response) + Math.floor(dom)) {
1713 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "client performance math error:" + total + " < " + network + " + " + request + " + " + response + " + " + dom);
1717 this.perfTotal = ApplicationInsights.Util.msToTimeSpan(total);
1718 this.networkConnect = ApplicationInsights.Util.msToTimeSpan(network);
1719 this.sentRequest = ApplicationInsights.Util.msToTimeSpan(request);
1720 this.receivedResponse = ApplicationInsights.Util.msToTimeSpan(response);
1721 this.domProcessing = ApplicationInsights.Util.msToTimeSpan(dom);
1722 this.isValid = true;
1725 this.url = Telemetry.Common.DataSanitizer.sanitizeUrl(url);
1726 this.name = Telemetry.Common.DataSanitizer.sanitizeString(name || ApplicationInsights.Util.NotSpecified);
1727 if (!isNaN(durationMs)) {
1728 this.duration = ApplicationInsights.Util.msToTimeSpan(durationMs);
1730 this.properties = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeProperties(properties);
1731 this.measurements = ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeMeasurements(measurements);
1733 PageViewPerformance.getPerformanceTiming = function () {
1734 if (typeof window != "undefined" && window.performance && window.performance.timing) {
1735 return window.performance.timing;
1739 PageViewPerformance.isPerformanceTimingSupported = function () {
1740 return typeof window != "undefined" && window.performance && window.performance.timing;
1742 PageViewPerformance.isPerformanceTimingDataReady = function () {
1743 var timing = window.performance.timing;
1744 return timing.domainLookupStart > 0 && timing.navigationStart > 0 && timing.responseStart > 0 && timing.requestStart > 0 && timing.loadEventEnd > 0 && timing.responseEnd > 0 && timing.connectEnd > 0 && timing.domLoading > 0;
1746 PageViewPerformance.getDuration = function (start, end) {
1748 if (!(isNaN(start) || isNaN(end))) {
1749 duration = Math.max(end - start, 0);
1753 PageViewPerformance.envelopeType = "Microsoft.ApplicationInsights.PageviewPerformance";
1754 PageViewPerformance.dataType = "PageviewPerformanceData";
1755 return PageViewPerformance;
1756 })(AI.PageViewPerfData);
1757 Telemetry.PageViewPerformance = PageViewPerformance;
1758 })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1759 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1760 })(Microsoft || (Microsoft = {}));
1764 var SessionStateData = (function (_super) {
1765 __extends(SessionStateData, _super);
1766 function SessionStateData() {
1768 this.state = 0 /* Start */;
1771 return SessionStateData;
1772 })(Microsoft.Telemetry.Domain);
1773 AI.SessionStateData = SessionStateData;
1774 })(AI || (AI = {}));
1776 (function (Microsoft) {
1777 var ApplicationInsights;
1778 (function (ApplicationInsights) {
1780 (function (Telemetry) {
1782 var SessionTelemetry = (function (_super) {
1783 __extends(SessionTelemetry, _super);
1784 function SessionTelemetry(state) {
1786 this.aiDataContract = {
1792 SessionTelemetry.envelopeType = "Microsoft.ApplicationInsights.SessionState";
1793 SessionTelemetry.dataType = "SessionStateData";
1794 return SessionTelemetry;
1795 })(AI.SessionStateData);
1796 Telemetry.SessionTelemetry = SessionTelemetry;
1797 })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
1798 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
1799 })(Microsoft || (Microsoft = {}));
1801 (function (Microsoft) {
1802 var ApplicationInsights;
1803 (function (ApplicationInsights) {
1805 var TelemetryContext = (function () {
1806 function TelemetryContext(config) {
1808 this._config = config;
1809 this._sender = new ApplicationInsights.Sender(config);
1810 if (typeof window !== 'undefined') {
1811 this._sessionManager = new ApplicationInsights.Context._SessionManager(config, function (sessionState, timestamp) { return TelemetryContext._sessionHandler(_this, sessionState, timestamp); });
1812 this.application = new ApplicationInsights.Context.Application();
1813 this.device = new ApplicationInsights.Context.Device();
1814 this.internal = new ApplicationInsights.Context.Internal();
1815 this.location = new ApplicationInsights.Context.Location();
1816 this.user = new ApplicationInsights.Context.User(config.accountId());
1817 this.operation = new ApplicationInsights.Context.Operation();
1818 this.session = new ApplicationInsights.Context.Session();
1819 this.sample = new ApplicationInsights.Context.Sample(config.sampleRate());
1822 TelemetryContext.prototype.addTelemetryInitializer = function (telemetryInitializer) {
1823 this.telemetryInitializers = this.telemetryInitializers || [];
1824 this.telemetryInitializers.push(telemetryInitializer);
1826 TelemetryContext.prototype.track = function (envelope) {
1828 ApplicationInsights._InternalLogging.throwInternalUserActionable(0 /* CRITICAL */, "cannot call .track() with a null or undefined argument");
1831 if (envelope.name === ApplicationInsights.Telemetry.PageView.envelopeType) {
1832 ApplicationInsights._InternalLogging.resetInternalMessageCount();
1835 if (typeof this.session.id !== "string") {
1836 this._sessionManager.update();
1839 this._track(envelope);
1843 TelemetryContext.prototype._track = function (envelope) {
1845 if (typeof this.session.id === "string") {
1846 this._applySessionContext(envelope, this.session);
1849 this._applySessionContext(envelope, this._sessionManager.automaticSession);
1852 this._applyApplicationContext(envelope, this.application);
1853 this._applyDeviceContext(envelope, this.device);
1854 this._applyInternalContext(envelope, this.internal);
1855 this._applyLocationContext(envelope, this.location);
1856 this._applySampleContext(envelope, this.sample);
1857 this._applyUserContext(envelope, this.user);
1858 this._applyOperationContext(envelope, this.operation);
1859 envelope.iKey = this._config.instrumentationKey();
1860 var telemetryInitializersFailed = false;
1862 this.telemetryInitializers = this.telemetryInitializers || [];
1863 var telemetryInitializersCount = this.telemetryInitializers.length;
1864 for (var i = 0; i < telemetryInitializersCount; ++i) {
1865 var telemetryInitializer = this.telemetryInitializers[i];
1866 if (telemetryInitializer) {
1867 telemetryInitializer.apply(null, [envelope]);
1872 telemetryInitializersFailed = true;
1873 ApplicationInsights._InternalLogging.throwInternalUserActionable(0 /* CRITICAL */, "One of telemetry initializers failed, telemetry item will not be sent: " + ApplicationInsights.Util.dump(e));
1875 if (!telemetryInitializersFailed) {
1876 if (envelope.name === ApplicationInsights.Telemetry.SessionTelemetry.envelopeType || envelope.name === ApplicationInsights.Telemetry.Metric.envelopeType || this.sample.isSampledIn(envelope)) {
1877 this._sender.send(envelope);
1880 ApplicationInsights._InternalLogging.logInternalMessage(1 /* WARNING */, "Telemetry is sampled and not sent to the AI service. SampleRate is " + this.sample.sampleRate);
1885 TelemetryContext._sessionHandler = function (tc, sessionState, timestamp) {
1886 var sessionStateTelemetry = new ApplicationInsights.Telemetry.SessionTelemetry(sessionState);
1887 var sessionStateData = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.SessionTelemetry.dataType, sessionStateTelemetry);
1888 var sessionStateEnvelope = new ApplicationInsights.Telemetry.Common.Envelope(sessionStateData, ApplicationInsights.Telemetry.SessionTelemetry.envelopeType);
1889 sessionStateEnvelope.time = ApplicationInsights.Util.toISOStringForIE8(new Date(timestamp));
1890 tc._track(sessionStateEnvelope);
1892 TelemetryContext.prototype._applyApplicationContext = function (envelope, appContext) {
1894 var tagKeys = new AI.ContextTagKeys();
1895 if (typeof appContext.ver === "string") {
1896 envelope.tags[tagKeys.applicationVersion] = appContext.ver;
1898 if (typeof appContext.build === "string") {
1899 envelope.tags[tagKeys.applicationBuild] = appContext.build;
1903 TelemetryContext.prototype._applyDeviceContext = function (envelope, deviceContext) {
1904 var tagKeys = new AI.ContextTagKeys();
1905 if (deviceContext) {
1906 if (typeof deviceContext.id === "string") {
1907 envelope.tags[tagKeys.deviceId] = deviceContext.id;
1909 if (typeof deviceContext.ip === "string") {
1910 envelope.tags[tagKeys.deviceIp] = deviceContext.ip;
1912 if (typeof deviceContext.language === "string") {
1913 envelope.tags[tagKeys.deviceLanguage] = deviceContext.language;
1915 if (typeof deviceContext.locale === "string") {
1916 envelope.tags[tagKeys.deviceLocale] = deviceContext.locale;
1918 if (typeof deviceContext.model === "string") {
1919 envelope.tags[tagKeys.deviceModel] = deviceContext.model;
1921 if (typeof deviceContext.network !== "undefined") {
1922 envelope.tags[tagKeys.deviceNetwork] = deviceContext.network;
1924 if (typeof deviceContext.oemName === "string") {
1925 envelope.tags[tagKeys.deviceOEMName] = deviceContext.oemName;
1927 if (typeof deviceContext.os === "string") {
1928 envelope.tags[tagKeys.deviceOS] = deviceContext.os;
1930 if (typeof deviceContext.osversion === "string") {
1931 envelope.tags[tagKeys.deviceOSVersion] = deviceContext.osversion;
1933 if (typeof deviceContext.resolution === "string") {
1934 envelope.tags[tagKeys.deviceScreenResolution] = deviceContext.resolution;
1936 if (typeof deviceContext.type === "string") {
1937 envelope.tags[tagKeys.deviceType] = deviceContext.type;
1941 TelemetryContext.prototype._applyInternalContext = function (envelope, internalContext) {
1942 if (internalContext) {
1943 var tagKeys = new AI.ContextTagKeys();
1944 if (typeof internalContext.agentVersion === "string") {
1945 envelope.tags[tagKeys.internalAgentVersion] = internalContext.agentVersion;
1947 if (typeof internalContext.sdkVersion === "string") {
1948 envelope.tags[tagKeys.internalSdkVersion] = internalContext.sdkVersion;
1952 TelemetryContext.prototype._applyLocationContext = function (envelope, locationContext) {
1953 if (locationContext) {
1954 var tagKeys = new AI.ContextTagKeys();
1955 if (typeof locationContext.ip === "string") {
1956 envelope.tags[tagKeys.locationIp] = locationContext.ip;
1960 TelemetryContext.prototype._applyOperationContext = function (envelope, operationContext) {
1961 if (operationContext) {
1962 var tagKeys = new AI.ContextTagKeys();
1963 if (typeof operationContext.id === "string") {
1964 envelope.tags[tagKeys.operationId] = operationContext.id;
1966 if (typeof operationContext.name === "string") {
1967 envelope.tags[tagKeys.operationName] = operationContext.name;
1969 if (typeof operationContext.parentId === "string") {
1970 envelope.tags[tagKeys.operationParentId] = operationContext.parentId;
1972 if (typeof operationContext.rootId === "string") {
1973 envelope.tags[tagKeys.operationRootId] = operationContext.rootId;
1975 if (typeof operationContext.syntheticSource === "string") {
1976 envelope.tags[tagKeys.operationSyntheticSource] = operationContext.syntheticSource;
1980 TelemetryContext.prototype._applySampleContext = function (envelope, sampleContext) {
1981 if (sampleContext) {
1982 var tagKeys = new AI.ContextTagKeys();
1983 envelope.tags[tagKeys.sampleRate] = sampleContext.sampleRate;
1986 TelemetryContext.prototype._applySessionContext = function (envelope, sessionContext) {
1987 if (sessionContext) {
1988 var tagKeys = new AI.ContextTagKeys();
1989 if (typeof sessionContext.id === "string") {
1990 envelope.tags[tagKeys.sessionId] = sessionContext.id;
1992 if (typeof sessionContext.isFirst !== "undefined") {
1993 envelope.tags[tagKeys.sessionIsFirst] = sessionContext.isFirst;
1997 TelemetryContext.prototype._applyUserContext = function (envelope, userContext) {
1999 var tagKeys = new AI.ContextTagKeys();
2000 if (typeof userContext.accountAcquisitionDate === "string") {
2001 envelope.tags[tagKeys.userAccountAcquisitionDate] = userContext.accountAcquisitionDate;
2003 if (typeof userContext.accountId === "string") {
2004 envelope.tags[tagKeys.userAccountId] = userContext.accountId;
2006 if (typeof userContext.agent === "string") {
2007 envelope.tags[tagKeys.userAgent] = userContext.agent;
2009 if (typeof userContext.id === "string") {
2010 envelope.tags[tagKeys.userId] = userContext.id;
2012 if (typeof userContext.authenticatedId === "string") {
2013 envelope.tags[tagKeys.userAuthUserId] = userContext.authenticatedId;
2015 if (typeof userContext.storeRegion === "string") {
2016 envelope.tags[tagKeys.userStoreRegion] = userContext.storeRegion;
2020 return TelemetryContext;
2022 ApplicationInsights.TelemetryContext = TelemetryContext;
2023 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
2024 })(Microsoft || (Microsoft = {}));
2026 (function (Microsoft) {
2028 (function (Telemetry) {
2030 var Data = (function (_super) {
2031 __extends(Data, _super);
2036 })(Microsoft.Telemetry.Base);
2037 Telemetry.Data = Data;
2038 })(Telemetry = Microsoft.Telemetry || (Microsoft.Telemetry = {}));
2039 })(Microsoft || (Microsoft = {}));
2041 (function (Microsoft) {
2042 var ApplicationInsights;
2043 (function (ApplicationInsights) {
2045 (function (Telemetry) {
2047 (function (Common) {
2049 var Data = (function (_super) {
2050 __extends(Data, _super);
2051 function Data(type, data) {
2053 this.aiDataContract = {
2057 this.baseType = type;
2058 this.baseData = data;
2061 })(Microsoft.Telemetry.Data);
2063 })(Common = Telemetry.Common || (Telemetry.Common = {}));
2064 })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
2065 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
2066 })(Microsoft || (Microsoft = {}));
2068 (function (Microsoft) {
2069 var ApplicationInsights;
2070 (function (ApplicationInsights) {
2072 (function (Telemetry) {
2074 var PageVisitTimeManager = (function () {
2075 function PageVisitTimeManager(pageVisitTimeTrackingHandler) {
2076 this.prevPageVisitDataKeyName = "prevPageVisitData";
2077 this.pageVisitTimeTrackingHandler = pageVisitTimeTrackingHandler;
2079 PageVisitTimeManager.prototype.trackPreviousPageVisit = function (currentPageName, currentPageUrl) {
2081 var prevPageVisitTimeData = this.restartPageVisitTimer(currentPageName, currentPageUrl);
2082 if (prevPageVisitTimeData) {
2083 this.pageVisitTimeTrackingHandler(prevPageVisitTimeData.pageName, prevPageVisitTimeData.pageUrl, prevPageVisitTimeData.pageVisitTime);
2087 ApplicationInsights._InternalLogging.warnToConsole("Auto track page visit time failed, metric will not be collected: " + ApplicationInsights.Util.dump(e));
2090 PageVisitTimeManager.prototype.restartPageVisitTimer = function (pageName, pageUrl) {
2092 var prevPageVisitData = this.stopPageVisitTimer();
2093 this.startPageVisitTimer(pageName, pageUrl);
2094 return prevPageVisitData;
2097 ApplicationInsights._InternalLogging.warnToConsole("Call to restart failed: " + ApplicationInsights.Util.dump(e));
2101 PageVisitTimeManager.prototype.startPageVisitTimer = function (pageName, pageUrl) {
2103 if (ApplicationInsights.Util.canUseSessionStorage()) {
2104 if (ApplicationInsights.Util.getSessionStorage(this.prevPageVisitDataKeyName) != null) {
2105 throw new Error("Cannot call startPageVisit consecutively without first calling stopPageVisit");
2107 var currPageVisitData = new PageVisitData(pageName, pageUrl);
2108 var currPageVisitDataStr = JSON.stringify(currPageVisitData);
2109 ApplicationInsights.Util.setSessionStorage(this.prevPageVisitDataKeyName, currPageVisitDataStr);
2113 ApplicationInsights._InternalLogging.warnToConsole("Call to start failed: " + ApplicationInsights.Util.dump(e));
2116 PageVisitTimeManager.prototype.stopPageVisitTimer = function () {
2118 if (ApplicationInsights.Util.canUseSessionStorage()) {
2119 var pageVisitEndTime = Date.now();
2120 var pageVisitDataJsonStr = ApplicationInsights.Util.getSessionStorage(this.prevPageVisitDataKeyName);
2121 if (pageVisitDataJsonStr) {
2122 var prevPageVisitData = JSON.parse(pageVisitDataJsonStr);
2123 prevPageVisitData.pageVisitTime = pageVisitEndTime - prevPageVisitData.pageVisitStartTime;
2124 ApplicationInsights.Util.removeSessionStorage(this.prevPageVisitDataKeyName);
2125 return prevPageVisitData;
2134 ApplicationInsights._InternalLogging.warnToConsole("Stop page visit timer failed: " + ApplicationInsights.Util.dump(e));
2138 return PageVisitTimeManager;
2140 Telemetry.PageVisitTimeManager = PageVisitTimeManager;
2141 var PageVisitData = (function () {
2142 function PageVisitData(pageName, pageUrl) {
2143 this.pageVisitStartTime = Date.now();
2144 this.pageName = pageName;
2145 this.pageUrl = pageUrl;
2147 return PageVisitData;
2149 Telemetry.PageVisitData = PageVisitData;
2150 })(Telemetry = ApplicationInsights.Telemetry || (ApplicationInsights.Telemetry = {}));
2151 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
2152 })(Microsoft || (Microsoft = {}));
2154 (function (Microsoft) {
2155 var ApplicationInsights;
2156 (function (ApplicationInsights) {
2158 ApplicationInsights.Version = "0.18.0";
2159 var AppInsights = (function () {
2160 function AppInsights(config) {
2162 this.config = config || {};
2163 var defaults = AppInsights.defaultConfig;
2164 if (defaults !== undefined) {
2165 for (var field in defaults) {
2166 if (this.config[field] === undefined) {
2167 this.config[field] = defaults[field];
2171 ApplicationInsights._InternalLogging.verboseLogging = function () { return _this.config.verboseLogging; };
2172 ApplicationInsights._InternalLogging.enableDebugExceptions = function () { return _this.config.enableDebug; };
2173 var configGetters = {
2174 instrumentationKey: function () { return _this.config.instrumentationKey; },
2175 accountId: function () { return _this.config.accountId; },
2176 appUserId: function () { return _this.config.appUserId; },
2177 sessionRenewalMs: function () { return _this.config.sessionRenewalMs; },
2178 sessionExpirationMs: function () { return _this.config.sessionExpirationMs; },
2179 endpointUrl: function () { return _this.config.endpointUrl; },
2180 emitLineDelimitedJson: function () { return _this.config.emitLineDelimitedJson; },
2181 maxBatchSizeInBytes: function () { return _this.config.maxBatchSizeInBytes; },
2182 maxBatchInterval: function () { return _this.config.maxBatchInterval; },
2183 disableTelemetry: function () { return _this.config.disableTelemetry; },
2184 sampleRate: function () { return _this.config.samplingPercentage; }
2186 this.context = new ApplicationInsights.TelemetryContext(configGetters);
2187 this._eventTracking = new Timing("trackEvent");
2188 this._eventTracking.action = function (name, url, duration, properties, measurements) {
2189 var event = new ApplicationInsights.Telemetry.Event(name, properties, measurements);
2190 var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.Event.dataType, event);
2191 var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.Event.envelopeType);
2192 _this.context.track(envelope);
2194 this._pageTracking = new Timing("trackPageView");
2195 this._pageTracking.action = function (name, url, duration, properties, measurements) {
2196 _this.sendPageViewInternal(name, url, duration, properties, measurements);
2198 this._pageVisitTimeManager = new ApplicationInsights.Telemetry.PageVisitTimeManager(function (pageName, pageUrl, pageVisitTime) { return _this.trackPageVisitTime(pageName, pageUrl, pageVisitTime); });
2200 AppInsights.prototype.sendPageViewInternal = function (name, url, duration, properties, measurements) {
2201 var pageView = new ApplicationInsights.Telemetry.PageView(name, url, duration, properties, measurements);
2202 var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.PageView.dataType, pageView);
2203 var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.PageView.envelopeType);
2204 this.context.track(envelope);
2206 AppInsights.prototype.startTrackPage = function (name) {
2208 if (typeof name !== "string") {
2209 name = window.document && window.document.title || "";
2211 this._pageTracking.start(name);
2214 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "startTrackPage failed, page view may not be collected: " + ApplicationInsights.Util.dump(e));
2217 AppInsights.prototype.stopTrackPage = function (name, url, properties, measurements) {
2219 if (typeof name !== "string") {
2220 name = window.document && window.document.title || "";
2222 if (typeof url !== "string") {
2223 url = window.location && window.location.href || "";
2225 this._pageTracking.stop(name, url, properties, measurements);
2226 if (this.config.autoTrackPageVisitTime) {
2227 this._pageVisitTimeManager.trackPreviousPageVisit(name, url);
2231 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "stopTrackPage failed, page view will not be collected: " + ApplicationInsights.Util.dump(e));
2234 AppInsights.prototype.trackPageView = function (name, url, properties, measurements) {
2236 if (typeof name !== "string") {
2237 name = window.document && window.document.title || "";
2239 if (typeof url !== "string") {
2240 url = window.location && window.location.href || "";
2242 this.trackPageViewInternal(name, url, properties, measurements);
2243 if (this.config.autoTrackPageVisitTime) {
2244 this._pageVisitTimeManager.trackPreviousPageVisit(name, url);
2248 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "trackPageView failed, page view will not be collected: " + ApplicationInsights.Util.dump(e));
2251 AppInsights.prototype.trackPageViewInternal = function (name, url, properties, measurements) {
2254 if (ApplicationInsights.Telemetry.PageViewPerformance.isPerformanceTimingSupported()) {
2255 var startTime = window.performance.timing.navigationStart;
2256 durationMs = ApplicationInsights.Telemetry.PageViewPerformance.getDuration(startTime, +new Date);
2257 var handle = setInterval(function () {
2259 durationMs = ApplicationInsights.Telemetry.PageViewPerformance.getDuration(startTime, +new Date);
2260 var timingDataReady = ApplicationInsights.Telemetry.PageViewPerformance.isPerformanceTimingDataReady();
2261 var timeoutReached = durationMs > 60000;
2262 if (timeoutReached || timingDataReady) {
2263 clearInterval(handle);
2264 durationMs = ApplicationInsights.Telemetry.PageViewPerformance.getDuration(startTime, +new Date);
2265 var pageViewPerformance = new ApplicationInsights.Telemetry.PageViewPerformance(name, url, durationMs, properties, measurements);
2266 _this.sendPageViewInternal(name, url, pageViewPerformance.isValid && !isNaN(pageViewPerformance.duration) ? +pageViewPerformance.duration : durationMs, properties, measurements);
2267 if (pageViewPerformance.isValid) {
2268 var pageViewPerformanceData = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.PageViewPerformance.dataType, pageViewPerformance);
2269 var pageViewPerformanceEnvelope = new ApplicationInsights.Telemetry.Common.Envelope(pageViewPerformanceData, ApplicationInsights.Telemetry.PageViewPerformance.envelopeType);
2270 _this.context.track(pageViewPerformanceEnvelope);
2272 _this.context._sender.triggerSend();
2276 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "trackPageView failed on page load calculation: " + ApplicationInsights.Util.dump(e));
2281 AppInsights.prototype.startTrackEvent = function (name) {
2283 this._eventTracking.start(name);
2286 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "startTrackEvent failed, event will not be collected: " + ApplicationInsights.Util.dump(e));
2289 AppInsights.prototype.stopTrackEvent = function (name, properties, measurements) {
2291 this._eventTracking.stop(name, undefined, properties, measurements);
2294 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "stopTrackEvent failed, event will not be collected: " + ApplicationInsights.Util.dump(e));
2297 AppInsights.prototype.trackEvent = function (name, properties, measurements) {
2299 var eventTelemetry = new ApplicationInsights.Telemetry.Event(name, properties, measurements);
2300 var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.Event.dataType, eventTelemetry);
2301 var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.Event.envelopeType);
2302 this.context.track(envelope);
2305 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "trackEvent failed, event will not be collected: " + ApplicationInsights.Util.dump(e));
2308 AppInsights.prototype.trackException = function (exception, handledAt, properties, measurements) {
2310 if (!ApplicationInsights.Util.isError(exception)) {
2312 throw new Error(exception);
2318 var exceptionTelemetry = new ApplicationInsights.Telemetry.Exception(exception, handledAt, properties, measurements);
2319 var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.Exception.dataType, exceptionTelemetry);
2320 var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.Exception.envelopeType);
2321 this.context.track(envelope);
2324 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "trackException failed, exception will not be collected: " + ApplicationInsights.Util.dump(e));
2327 AppInsights.prototype.trackMetric = function (name, average, sampleCount, min, max, properties) {
2329 var telemetry = new ApplicationInsights.Telemetry.Metric(name, average, sampleCount, min, max, properties);
2330 var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.Metric.dataType, telemetry);
2331 var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.Metric.envelopeType);
2332 this.context.track(envelope);
2335 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "trackMetric failed, metric will not be collected: " + ApplicationInsights.Util.dump(e));
2338 AppInsights.prototype.trackTrace = function (message, properties) {
2340 var telemetry = new ApplicationInsights.Telemetry.Trace(message, properties);
2341 var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.Trace.dataType, telemetry);
2342 var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.Trace.envelopeType);
2343 this.context.track(envelope);
2346 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, "trackTrace failed, trace will not be collected: " + ApplicationInsights.Util.dump(e));
2349 AppInsights.prototype.trackPageVisitTime = function (pageName, pageUrl, pageVisitTime) {
2350 var properties = { PageName: pageName, PageUrl: pageUrl };
2351 this.trackMetric("PageVisitTime", pageVisitTime, 1, pageVisitTime, pageVisitTime, properties);
2353 AppInsights.prototype.flush = function () {
2355 this.context._sender.triggerSend();
2358 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "flush failed, telemetry will not be collected: " + ApplicationInsights.Util.dump(e));
2361 AppInsights.prototype.setAuthenticatedUserContext = function (authenticatedUserId, accountId) {
2363 this.context.user.setAuthenticatedUserContext(authenticatedUserId, accountId);
2366 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "Setting auth user context failed. " + ApplicationInsights.Util.dump(e));
2369 AppInsights.prototype.clearAuthenticatedUserContext = function () {
2371 this.context.user.clearAuthenticatedUserContext();
2374 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "Clearing auth user context failed. " + ApplicationInsights.Util.dump(e));
2377 AppInsights.prototype.SendCORSException = function (properties) {
2378 var exceptionData = Microsoft.ApplicationInsights.Telemetry.Exception.CreateSimpleException("Script error.", "Error", "unknown", "unknown", "The browser’s same-origin policy prevents us from getting the details of this exception.The exception occurred in a script loaded from an origin different than the web page.For cross- domain error reporting you can use crossorigin attribute together with appropriate CORS HTTP headers.For more information please see http://www.w3.org/TR/cors/.", 0, null);
2379 exceptionData.properties = properties;
2380 var data = new ApplicationInsights.Telemetry.Common.Data(ApplicationInsights.Telemetry.Exception.dataType, exceptionData);
2381 var envelope = new ApplicationInsights.Telemetry.Common.Envelope(data, ApplicationInsights.Telemetry.Exception.envelopeType);
2382 this.context.track(envelope);
2384 AppInsights.prototype._onerror = function (message, url, lineNumber, columnNumber, error) {
2386 var properties = { url: url ? url : document.URL };
2387 if (ApplicationInsights.Util.isCrossOriginError(message, url, lineNumber, columnNumber, error)) {
2388 this.SendCORSException(properties);
2391 if (!ApplicationInsights.Util.isError(error)) {
2392 var stack = "window.onerror@" + properties.url + ":" + lineNumber + ":" + (columnNumber || 0);
2393 error = new Error(message);
2394 error["stack"] = stack;
2396 this.trackException(error, null, properties);
2400 var errorString = error ? (error.name + ", " + error.message) : "null";
2401 var exceptionDump = ApplicationInsights.Util.dump(exception);
2402 ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, "_onerror threw " + exceptionDump + " while logging error, error will not be collected: " + errorString);
2407 ApplicationInsights.AppInsights = AppInsights;
2408 var Timing = (function () {
2409 function Timing(name) {
2413 Timing.prototype.start = function (name) {
2414 if (typeof this._events[name] !== "undefined") {
2415 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "start" + this._name + " was called more than once for this event without calling stop" + this._name + ". key is '" + name + "'");
2417 this._events[name] = +new Date;
2419 Timing.prototype.stop = function (name, url, properties, measurements) {
2420 var start = this._events[name];
2422 ApplicationInsights._InternalLogging.throwInternalUserActionable(1 /* WARNING */, "stop" + this._name + " was called without a corresponding start" + this._name + " . Event name is '" + name + "'");
2425 var end = +new Date;
2426 var duration = ApplicationInsights.Telemetry.PageViewPerformance.getDuration(start, end);
2427 this.action(name, url, duration, properties, measurements);
2429 delete this._events[name];
2430 this._events[name] = undefined;
2434 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
2435 })(Microsoft || (Microsoft = {}));
2439 var AjaxCallData = (function (_super) {
2440 __extends(AjaxCallData, _super);
2441 function AjaxCallData() {
2443 this.properties = {};
2444 this.measurements = {};
2447 return AjaxCallData;
2448 })(AI.PageViewData);
2449 AI.AjaxCallData = AjaxCallData;
2450 })(AI || (AI = {}));
2454 (function (DependencyKind) {
2455 DependencyKind[DependencyKind["SQL"] = 0] = "SQL";
2456 DependencyKind[DependencyKind["Http"] = 1] = "Http";
2457 DependencyKind[DependencyKind["Other"] = 2] = "Other";
2458 })(AI.DependencyKind || (AI.DependencyKind = {}));
2459 var DependencyKind = AI.DependencyKind;
2460 })(AI || (AI = {}));
2464 (function (DependencySourceType) {
2465 DependencySourceType[DependencySourceType["Undefined"] = 0] = "Undefined";
2466 DependencySourceType[DependencySourceType["Aic"] = 1] = "Aic";
2467 DependencySourceType[DependencySourceType["Apmc"] = 2] = "Apmc";
2468 })(AI.DependencySourceType || (AI.DependencySourceType = {}));
2469 var DependencySourceType = AI.DependencySourceType;
2470 })(AI || (AI = {}));
2474 var RemoteDependencyData = (function (_super) {
2475 __extends(RemoteDependencyData, _super);
2476 function RemoteDependencyData() {
2478 this.kind = 0 /* Measurement */;
2479 this.dependencyKind = 2 /* Other */;
2480 this.success = true;
2481 this.dependencySource = 0 /* Undefined */;
2482 this.properties = {};
2485 return RemoteDependencyData;
2486 })(Microsoft.Telemetry.Domain);
2487 AI.RemoteDependencyData = RemoteDependencyData;
2488 })(AI || (AI = {}));
2492 var RequestData = (function (_super) {
2493 __extends(RequestData, _super);
2494 function RequestData() {
2496 this.properties = {};
2497 this.measurements = {};
2501 })(Microsoft.Telemetry.Domain);
2502 AI.RequestData = RequestData;
2503 })(AI || (AI = {}));
2505 (function (Microsoft) {
2506 var ApplicationInsights;
2507 (function (ApplicationInsights) {
2509 var Initialization = (function () {
2510 function Initialization(snippet) {
2511 snippet.queue = snippet.queue || [];
2512 var config = snippet.config || {};
2513 if (config && !config.instrumentationKey) {
2515 if (config["iKey"]) {
2516 Microsoft.ApplicationInsights.Version = "0.10.0.0";
2517 config.instrumentationKey = config["iKey"];
2519 else if (config["applicationInsightsId"]) {
2520 Microsoft.ApplicationInsights.Version = "0.7.2.0";
2521 config.instrumentationKey = config["applicationInsightsId"];
2524 throw new Error("Cannot load Application Insights SDK, no instrumentationKey was provided.");
2527 config = Initialization.getDefaultConfig(config);
2528 this.snippet = snippet;
2529 this.config = config;
2531 Initialization.prototype.loadAppInsights = function () {
2532 var appInsights = new Microsoft.ApplicationInsights.AppInsights(this.config);
2533 if (this.config["iKey"]) {
2534 var originalTrackPageView = appInsights.trackPageView;
2535 appInsights.trackPageView = function (pagePath, properties, measurements) {
2536 originalTrackPageView.apply(appInsights, [null, pagePath, properties, measurements]);
2539 var legacyPageView = "logPageView";
2540 if (typeof this.snippet[legacyPageView] === "function") {
2541 appInsights[legacyPageView] = function (pagePath, properties, measurements) {
2542 appInsights.trackPageView(null, pagePath, properties, measurements);
2545 var legacyEvent = "logEvent";
2546 if (typeof this.snippet[legacyEvent] === "function") {
2547 appInsights[legacyEvent] = function (name, properties, measurements) {
2548 appInsights.trackEvent(name, properties, measurements);
2553 Initialization.prototype.emptyQueue = function () {
2555 if (Microsoft.ApplicationInsights.Util.isArray(this.snippet.queue)) {
2556 var length = this.snippet.queue.length;
2557 for (var i = 0; i < length; i++) {
2558 var call = this.snippet.queue[i];
2561 this.snippet.queue = undefined;
2562 delete this.snippet.queue;
2566 var message = "Failed to send queued telemetry";
2567 if (exception && typeof exception.toString === "function") {
2568 message += ": " + exception.toString();
2570 Microsoft.ApplicationInsights._InternalLogging.throwInternalNonUserActionable(1 /* WARNING */, message);
2573 Initialization.prototype.pollInteralLogs = function (appInsightsInstance) {
2574 return setInterval(function () {
2575 var queue = Microsoft.ApplicationInsights._InternalLogging.queue;
2576 var length = queue.length;
2577 for (var i = 0; i < length; i++) {
2578 appInsightsInstance.trackTrace(queue[i]);
2581 }, this.config.diagnosticLogInterval);
2583 Initialization.prototype.addHousekeepingBeforeUnload = function (appInsightsInstance) {
2584 if ('onbeforeunload' in window) {
2585 var performHousekeeping = function () {
2586 appInsightsInstance.context._sender.triggerSend();
2587 appInsightsInstance.context._sessionManager.backup();
2589 if (!Microsoft.ApplicationInsights.Util.addEventHandler('beforeunload', performHousekeeping)) {
2590 Microsoft.ApplicationInsights._InternalLogging.throwInternalNonUserActionable(0 /* CRITICAL */, 'Could not add handler for beforeunload');
2594 Initialization.getDefaultConfig = function (config) {
2598 config.endpointUrl = config.endpointUrl || "//dc.services.visualstudio.com/v2/track";
2599 config.accountId = config.accountId;
2600 config.appUserId = config.appUserId;
2601 config.sessionRenewalMs = 30 * 60 * 1000;
2602 config.sessionExpirationMs = 24 * 60 * 60 * 1000;
2603 config.maxBatchSizeInBytes = config.maxBatchSizeInBytes > 0 ? config.maxBatchSizeInBytes : 1000000;
2604 config.maxBatchInterval = !isNaN(config.maxBatchInterval) ? config.maxBatchInterval : 15000;
2605 config.enableDebug = ApplicationInsights.Util.stringToBoolOrDefault(config.enableDebug);
2606 config.autoCollectErrors = (config.autoCollectErrors !== undefined && config.autoCollectErrors !== null) ? ApplicationInsights.Util.stringToBoolOrDefault(config.autoCollectErrors) : true;
2607 config.disableTelemetry = ApplicationInsights.Util.stringToBoolOrDefault(config.disableTelemetry);
2608 config.verboseLogging = ApplicationInsights.Util.stringToBoolOrDefault(config.verboseLogging);
2609 config.emitLineDelimitedJson = ApplicationInsights.Util.stringToBoolOrDefault(config.emitLineDelimitedJson);
2610 config.diagnosticLogInterval = config.diagnosticLogInterval || 10000;
2611 config.autoTrackPageVisitTime = ApplicationInsights.Util.stringToBoolOrDefault(config.autoTrackPageVisitTime);
2612 if (isNaN(config.samplingPercentage) || config.samplingPercentage <= 0 || config.samplingPercentage >= 100) {
2613 config.samplingPercentage = 100;
2617 return Initialization;
2619 ApplicationInsights.Initialization = Initialization;
2620 })(ApplicationInsights = Microsoft.ApplicationInsights || (Microsoft.ApplicationInsights = {}));
2621 })(Microsoft || (Microsoft = {}));
2622 function initializeAppInsights() {
2624 if (typeof window !== "undefined" && typeof JSON !== "undefined") {
2625 var aiName = "appInsights";
2626 if (window[aiName] === undefined) {
2627 Microsoft.ApplicationInsights.AppInsights.defaultConfig = Microsoft.ApplicationInsights.Initialization.getDefaultConfig();
2630 var snippet = window[aiName] || {};
2631 var init = new Microsoft.ApplicationInsights.Initialization(snippet);
2632 var appInsightsLocal = init.loadAppInsights();
2633 for (var field in appInsightsLocal) {
2634 snippet[field] = appInsightsLocal[field];
2637 init.pollInteralLogs(appInsightsLocal);
2638 init.addHousekeepingBeforeUnload(appInsightsLocal);
2643 Microsoft.ApplicationInsights._InternalLogging.warnToConsole('Failed to initialize AppInsights JS SDK: ' + e.message);
2646 initializeAppInsights();