/
Init.ts
36 lines (29 loc) · 1.43 KB
/
Init.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { Initialization as ApplicationInsights, Snippet } from "./Initialization";
import { ApplicationInsightsContainer } from "./ApplicationInsightsContainer";
export { Initialization as ApplicationInsights, Snippet } from "./Initialization";
"use strict";
//should be global function that should load as soon as SDK loads
try {
// E2E sku on load initializes core and pipeline using snippet as input for configuration
var aiName;
if (typeof window !== "undefined" && typeof JSON !== "undefined") {
// get snippet or initialize to an empty object
aiName = window["appInsightsSDK"] || "appInsights";
if (window[aiName] !== undefined) {
// this is the typical case for browser+snippet
var snippet: Snippet = window[aiName] || <any>{ version: 2.0 };
// overwrite snippet with full appInsights
// for 2.0 initialize only if required
if ((snippet.version === 2.0 && window[aiName].initialize) || snippet.version === undefined ) {
ApplicationInsightsContainer.getAppInsights(snippet, snippet.version);
}
}
}
} catch (e) {
// TODO: Find better place to warn to console when SDK initialization fails
if (console) {
console.warn('Failed to initialize AppInsights JS SDK for instance ' + aiName + e.message);
}
}