Adding module and extract public surface into interfaces

This commit is contained in:
Alex Bulankou 2016-05-22 22:13:20 -07:00
Родитель bfef348695
Коммит aecdb1554a
5 изменённых файлов: 143 добавлений и 4 удалений

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

@ -8,6 +8,7 @@
/// <reference path="./ajax/ajax.ts"/>
/// <reference path="./DataLossAnalyzer.ts"/>
/// <reference path="./SplitTest.ts"/>
/// <reference path="./IAppInsights.ts"/>
module Microsoft.ApplicationInsights {
@ -54,7 +55,7 @@ module Microsoft.ApplicationInsights {
* The main API that sends telemetry to Application Insights.
* Learn more: http://go.microsoft.com/fwlink/?LinkID=401493
*/
export class AppInsights implements IAppInsightsInternal {
export class AppInsights implements IAppInsightsInternal, IAppInsights {
// Counts number of trackAjax invokations.
// By default we only monitor X ajax call per view to avoid too much load.

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

@ -0,0 +1,69 @@
/// <reference path="./AppInsights.ts"/>
/// <reference path="./IAppInsights.ts"/>
class AppInsightsModule {
private static appInsightsName = "appInsights";
public static appInsightsInstance: Microsoft.ApplicationInsights.IAppInsights;
private static _createLazyMethod(name) {
var aiObject = window[AppInsightsModule.appInsightsName];
// Define a temporary method that queues-up a the real method call
aiObject[name] = function () {
// Capture the original arguments passed to the method
var originalArguments = arguments;
// If the queue is available, it means that the function wasn't yet replaced with actual function value
if (aiObject.queue) {
aiObject.queue.push(() => aiObject[name].apply(aiObject, originalArguments));
}
else {
// otheriwse execute the function
aiObject[name].apply(aiObject, originalArguments);
}
}
AppInsightsModule.appInsightsInstance[name] = aiObject[name];
};
public static initialize(aiConfig: Microsoft.ApplicationInsights.IConfig) {
if (!window[AppInsightsModule.appInsightsName]) {
window[AppInsightsModule.appInsightsName] = {
config: aiConfig
};
var scriptElement = document.createElement("script");
scriptElement.src = "http://az416426.vo.msecnd.net/scripts/a/ai.0.js";
document.head.appendChild(scriptElement);
var aiObject = window[AppInsightsModule.appInsightsName];
// capture initial cookie
aiObject.cookie = document.cookie;
aiObject.queue = [];
var method = ["trackEvent", "trackException", "trackMetric", "trackPageView", "trackTrace", "trackAjax", "setAuthenticatedUserContext", "clearAuthenticatedUserContext"];
while (method.length) {
AppInsightsModule._createLazyMethod(method.pop());
}
// collect global errors
if (!aiConfig.disableExceptionTracking) {
AppInsightsModule._createLazyMethod("_onerror");
var originalOnError = window["_onerror"];
window["_onerror"] = function (message, url, lineNumber, columnNumber, error) {
var handled = originalOnError && originalOnError(message, url, lineNumber, columnNumber, error);
if (handled !== true) {
aiObject["_onerror"](message, url, lineNumber, columnNumber, error);
}
return handled;
};
}
}
}
}
export var initialize: (config: Microsoft.ApplicationInsights.IConfig) => void = AppInsightsModule.initialize;
export var AppInsights: Microsoft.ApplicationInsights.IAppInsights = AppInsightsModule.appInsightsInstance;

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

@ -0,0 +1,59 @@
module Microsoft.ApplicationInsights {
export interface IAppInsights {
/**
* Starts timing how long the user views a page or other item. Call this when the page opens.
* This method doesn't send any telemetry. Call {@link stopTrackTelemetry} to log the page when it closes.
* @param name A string that idenfities this item, unique within this HTML document. Defaults to the document title.
*/
startTrackPage(name?: string);
/**
* Logs how long a page or other item was visible, after {@link startTrackPage}. Call this when the page closes.
* @param name The string you used as the name in startTrackPage. Defaults to the document title.
* @param url String - a relative or absolute URL that identifies the page or other item. Defaults to the window location.
* @param properties map[string, string] - additional data used to filter pages and metrics in the portal. Defaults to empty.
* @param measurements map[string, number] - metrics associated with this page, displayed in Metrics Explorer on the portal. Defaults to empty.
*/
stopTrackPage(name?: string, url?: string, properties?: Object, measurements?: Object);
/**
* Logs that a page or other item was viewed.
* @param name The string you used as the name in startTrackPage. Defaults to the document title.
* @param url String - a relative or absolute URL that identifies the page or other item. Defaults to the window location.
* @param properties map[string, string] - additional data used to filter pages and metrics in the portal. Defaults to empty.
* @param measurements map[string, number] - metrics associated with this page, displayed in Metrics Explorer on the portal. Defaults to empty.
* @param duration number - the number of milliseconds it took to load the page. Defaults to undefined. If set to default value, page load time is calculated internally.
*/
trackPageView(name?: string, url?: string, properties?: Object, measurements?: Object, duration?: number);
/**
* Start timing an extended event. Call {@link stopTrackEvent} to log the event when it ends.
* @param name A string that identifies this event uniquely within the document.
*/
startTrackEvent(name: string);
/**
* Log an extended event that you started timing with {@link startTrackEvent}.
* @param name The string you used to identify this event in startTrackEvent.
* @param properties map[string, string] - additional data used to filter events and metrics in the portal. Defaults to empty.
* @param measurements map[string, number] - metrics associated with this event, displayed in Metrics Explorer on the portal. Defaults to empty.
*/
stopTrackEvent(name: string, properties?: Object, measurements?: Object);
/**
* Log a user action or other occurrence.
* @param name A string to identify this event in the portal.
* @param properties map[string, string] - additional data used to filter events and metrics in the portal. Defaults to empty.
* @param measurements map[string, number] - metrics associated with this event, displayed in Metrics Explorer on the portal. Defaults to empty.
*/
trackEvent(name: string, properties?: Object, measurements?: Object);
/**
* Log an AJAX request
* @param
*/
trackAjax(id: string, absoluteUrl: string, pathName: string, totalTime: number, success: boolean, resultCode: number, method?: string);
}
}

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

@ -16,7 +16,6 @@
<IISExpressUseClassicPipelineMode />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<VisualStudioVersion>12.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<RootNamespace>ApplicationInsights.Javascript</RootNamespace>
<!-- What version is being built? -->
@ -25,8 +24,10 @@
<VersionedOutFileBaseName>min\$(OutFileBaseName).$(AIVersionMajor)</VersionedOutFileBaseName>
<TypeScriptOutFile>min\$(OutFileBaseName).js</TypeScriptOutFile>
<TypeScriptGeneratesDeclarations>True</TypeScriptGeneratesDeclarations>
<TypeScriptModuleKind>AMD</TypeScriptModuleKind>
<!-- Suppress the "CS2008: No source files specified" warning -->
<NoWarn>2008</NoWarn>
<UseGlobalApplicationHostFile />
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
@ -123,6 +124,8 @@
<TypeScriptCompile Include="ajax\ajaxRecord.ts" />
<TypeScriptCompile Include="ajax\ajaxUtils.ts" />
<TypeScriptCompile Include="HashCodeScoreGenerator.ts" />
<TypeScriptCompile Include="AppInsightsModule.ts" />
<TypeScriptCompile Include="IAppInsights.ts" />
<TypeScriptCompile Include="SendBuffer.ts" />
<TypeScriptCompile Include="Sender.ts" />
<TypeScriptCompile Include="SplitTest.ts" />

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

@ -1,8 +1,15 @@
{
"name": "applicationinsights-js",
"version": "0.22.14",
"description": "[Application Insights](https://azure.microsoft.com/services/application-insights/) tells you about your app\u0027s performance and usage. By adding a few lines of code to your web pages, you get data about how many users you have, which pages are most popular, how fast pages load, whether they throw exceptions, and more. And you can add code to track more detailed user activity.",
"description": "Microsoft Application Insights JavaScript SDK",
"main": "dist/ai.0.js",
"keywords": [
"browser performance monitoring",
"script errors",
"application insights",
"microsoft",
"azure"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
@ -10,7 +17,7 @@
"type": "git",
"url": "git+https://github.com/Microsoft/ApplicationInsights-JS.git"
},
"author": "",
"author": "Microsoft Application Insights Team",
"license": "MIT",
"bugs": {
"url": "https://github.com/Microsoft/ApplicationInsights-JS/issues"