Bringing AI-JS version on GitHub up to date with the latest changes in AppDataCollection-JS

This commit is contained in:
Alex Bulankou 2015-05-04 15:21:14 -07:00
Родитель a920a1c9a5
Коммит a36db2415b
22 изменённых файлов: 216 добавлений и 23 удалений

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

@ -105,8 +105,6 @@ class SessionContextTests extends TestClass {
Assert.equal(2, cookieValueParts.length, "Cookie value should have actual value and expiration");
Assert.equal(3, cookieValueParts[0].split('|').length, "Cookie value before expiration should include user id, acq date and renew date");
Assert.equal("newGuid", cookieValueParts[0].split('|')[0], "First part of cookie value should be new user id guid");
Assert.equal(new Date().toString(), (new Date(cookieValueParts[0].split('|')[1])).toString(), "Second part of cookie should be parsable as date");
Assert.equal(new Date().toString(), (new Date(cookieValueParts[0].split('|')[2])).toString(), "Third part of cookie should be parsable as date");
// Having expiration 1 year allows to set sesion.IsFirst only when we generated cookie for the first time for a given browser
var expiration = cookieValueParts[1];

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

@ -13,6 +13,7 @@ class InitializationTests extends TestClass {
var snippet: Microsoft.ApplicationInsights.IConfig = {
instrumentationKey: "ffffffff-ffff-ffff-ffff-ffffffffffff",
endpointUrl: "//dc-int.services.visualstudio.com/v2/track",
emitLineDelimitedJson: false,
accountId: undefined,
appUserId: undefined,
sessionRenewalMs: 10,
@ -148,6 +149,51 @@ class InitializationTests extends TestClass {
}
});
this.testCase({
name: "InitializationTests: in config - 'false' string is treated as a boolean false",
test: () => {
var userConfig = {
enableDebug: "false",
autoCollectErrors: "false",
disableTelemetry: "false",
verboseLogging: "false",
emitLineDelimitedJson: "false",
};
var config = Microsoft.ApplicationInsights.Initialization.getDefaultConfig(<any>userConfig);
Assert.ok(!config.enableDebug);
Assert.ok(!config.autoCollectErrors);
Assert.ok(!config.disableTelemetry);
Assert.ok(!config.verboseLogging);
Assert.ok(!config.emitLineDelimitedJson);
}
});
this.testCase({
name: "InitializationTests: in config - 'true' string is treated as a boolean true",
test: () => {
var userConfig = {
enableDebug: "true",
autoCollectErrors: "true",
disableTelemetry: "true",
verboseLogging: "true",
emitLineDelimitedJson: "true",
};
var config = Microsoft.ApplicationInsights.Initialization.getDefaultConfig(<any>userConfig);
Assert.ok(config.enableDebug);
Assert.ok(config.autoCollectErrors);
Assert.ok(config.disableTelemetry);
Assert.ok(config.verboseLogging);
Assert.ok(config.emitLineDelimitedJson);
}
});
}
}

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

@ -13,6 +13,7 @@ class SenderTests extends TestClass {
private loggingSpy;
private testTelemetry;
private endpointUrl: string;
private emitLineDelimitedJson: boolean;
private maxBatchSizeInBytes: number;
private maxBatchInterval: number;
private disableTelemetry: boolean;
@ -28,6 +29,7 @@ class SenderTests extends TestClass {
var config: Microsoft.ApplicationInsights.ISenderConfig = {
endpointUrl: () => this.endpointUrl,
emitLineDelimitedJson: () => this.emitLineDelimitedJson,
maxBatchSizeInBytes: () => this.maxBatchSizeInBytes,
maxBatchInterval: () => this.maxBatchInterval,
disableTelemetry: () => this.disableTelemetry

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

@ -19,7 +19,7 @@ class SerializerTests extends TestClass {
}
public registerTests() {
this.testCase({
name: "SerializerTests: empty input",
test: () => {

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

@ -1,5 +1,6 @@
/// <reference path="../../testframework/common.ts" />
/// <reference path="../../../JavaScriptSDK/telemetry/Common/DataSanitizer.ts" />
/// <reference path="../../../JavaScriptSDK/Util.ts"/>
class DataSanitizerTests extends TestClass {
@ -121,7 +122,7 @@ class DataSanitizerTests extends TestClass {
}
var expectedMap = {
"he000": 1,
"hello": 1,
"he001": 2,
"he002": 3,
"he003": 4,
@ -132,6 +133,31 @@ class DataSanitizerTests extends TestClass {
Assert.deepEqual(expectedMap, validatedMap);
}
});
this.testCase({
name: "DataSanitizerTests: Validate sanitizeString trims whitespaces",
test: () => {
var expected = "NoWhiteSpaces";
var input = " NoWhiteSpaces ";
var actual = Microsoft.ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeString(input);
Assert.equal(expected, actual);
}
});
this.testCase({
name: "DataSanitizerTests: Validate sanitizeProperties trims whitespaces in properties names and values",
test: () => {
var expected = "NoWhiteSpaces";
var input = " NoWhiteSpaces ";
var testProps = { " prop1 ": " val ", " prop2 ": " val " };
var actual = Microsoft.ApplicationInsights.Telemetry.Common.DataSanitizer.sanitizeProperties(testProps);
Assert.equal("val", actual["prop1"]);
Assert.equal("val", actual["prop2"]);
}
});
}
}

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

@ -17,6 +17,7 @@ class TelemetryContextTests extends TestClass {
sessionRenewalMs: () => 10,
sessionExpirationMs: () => 10,
endpointUrl: () => "asdf",
emitLineDelimitedJson: () => false,
maxBatchSizeInBytes: () => 1000000,
maxBatchInterval: () => 1,
disableTelemetry: () => false

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

@ -155,6 +155,22 @@ class UtilTests extends TestClass {
test(-1, "00:00:00.000", "invalid input");
}
});
this.testCase({
name: "Tests stringToBoolOrDefault() returns true only for 'true' string (ignoring case)",
test: () => {
Assert.ok(Microsoft.ApplicationInsights.Util.stringToBoolOrDefault(undefined) === false);
Assert.ok(Microsoft.ApplicationInsights.Util.stringToBoolOrDefault(null) === false);
Assert.ok(Microsoft.ApplicationInsights.Util.stringToBoolOrDefault("") === false);
Assert.ok(Microsoft.ApplicationInsights.Util.stringToBoolOrDefault("asdf") === false);
Assert.ok(Microsoft.ApplicationInsights.Util.stringToBoolOrDefault(0) === false);
Assert.ok(Microsoft.ApplicationInsights.Util.stringToBoolOrDefault({ asfd: "sdf" }) === false);
Assert.ok(Microsoft.ApplicationInsights.Util.stringToBoolOrDefault(new Object()) === false);
Assert.ok(Microsoft.ApplicationInsights.Util.stringToBoolOrDefault("true") === true);
Assert.ok(Microsoft.ApplicationInsights.Util.stringToBoolOrDefault("TrUe") === true);
}
});
}
}
new UtilTests().registerTests();

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

@ -8,6 +8,7 @@ class AppInsightsTests extends TestClass {
var snippet: Microsoft.ApplicationInsights.IConfig = {
instrumentationKey: "",
endpointUrl: "//dc.services.visualstudio.com/v2/track",
emitLineDelimitedJson: false,
accountId: undefined,
appUserId: undefined,
sessionRenewalMs: 10,

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

@ -23,6 +23,9 @@
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<!-- In gated, ..\Javascript does not resolve, so grab the files that were copied to output instead. -->
<JavascriptSourceLocation Condition="'$(TF_Build_BINARIESDIRECTORY)' == ''">..\JavaScriptSDK</JavascriptSourceLocation>
<JavascriptSourceLocation Condition="'$(TF_Build_BINARIESDIRECTORY)' != ''">$(TF_Build_BINARIESDIRECTORY)</JavascriptSourceLocation>
<TypeScriptSourceMap>true</TypeScriptSourceMap>
<TypeScriptModuleKind>CommonJS</TypeScriptModuleKind>
<EnableTypeScript>true</EnableTypeScript>

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

@ -21,7 +21,7 @@ namespace ApplicationInsights.Javascript.Tests
private static IISExpress iisExpress;
private const string PATH_TO_TESTS = "/Selenium/Tests.html";
private const string PATH_TO_PERF_TESTS = "/Selenium/PerfTests.html";
private const string PERF_RESULTS_PATH = @"perfResults.txt";
private const string PERF_RESULTS_PATH = @"\\smfiles\Privates\scsouthw\perfResults.txt";
[ClassInitialize]
public static void Setup(TestContext context)

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

@ -17,7 +17,7 @@
* Constructs a new instance of the internal telemetry data class.
*/
constructor() {
this.sdkVersion = Version;
this.sdkVersion = "JavaScript:" + Version;
}
}
}

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

@ -96,13 +96,13 @@ module Microsoft.ApplicationInsights.Context {
}
if (params.length > 1) {
var acq = params[1];
var acq = +params[1];
this.automaticSession.acquisitionDate = +new Date(acq);
this.automaticSession.acquisitionDate = this.automaticSession.acquisitionDate > 0 ? this.automaticSession.acquisitionDate : 0;
}
if (params.length > 2) {
var renewal = params[2];
var renewal = +params[2];
this.automaticSession.renewalDate = +new Date(renewal);
this.automaticSession.renewalDate = this.automaticSession.renewalDate > 0 ? this.automaticSession.renewalDate : 0;
}
@ -130,9 +130,7 @@ module Microsoft.ApplicationInsights.Context {
private setCookie(guid: string, acq: number, renewal: number) {
var date = new Date(acq);
var acqStr = Util.toISOStringForIE8(date);
var renewalStr = Util.toISOStringForIE8(new Date(renewal));
var cookie = [guid, acqStr, renewalStr];
var cookie = [guid, acq, renewal];
// Set cookie to never expire so we can set Session.IsFirst only when cookie is generated for the first time
// 365 * 24 * 60 * 60 * 1000 = 31536000000
date.setTime(date.getTime() + 31536000000);

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

@ -122,10 +122,13 @@ module Microsoft.ApplicationInsights {
config.sessionExpirationMs = 24 * 60 * 60 * 1000;
config.maxBatchSizeInBytes = config.maxBatchSizeInBytes > 0 ? config.maxBatchSizeInBytes : 1000000;
config.maxBatchInterval = !isNaN(config.maxBatchInterval) ? config.maxBatchInterval : 15000;
config.enableDebug = !!config.enableDebug;
config.autoCollectErrors = typeof config.autoCollectErrors === "boolean" ? config.autoCollectErrors : true;
config.disableTelemetry = !!config.disableTelemetry;
config.verboseLogging = !!config.verboseLogging;
config.enableDebug = Util.stringToBoolOrDefault(config.enableDebug);
config.autoCollectErrors = (config.autoCollectErrors !== undefined && config.autoCollectErrors !== null) ?
Util.stringToBoolOrDefault(config.autoCollectErrors) :
true;
config.disableTelemetry = Util.stringToBoolOrDefault(config.disableTelemetry);
config.verboseLogging = Util.stringToBoolOrDefault(config.verboseLogging);
config.emitLineDelimitedJson = Util.stringToBoolOrDefault(config.emitLineDelimitedJson);
config.diagnosticLogInterval = config.diagnosticLogInterval || 10000;
return config;

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

@ -9,7 +9,7 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
<TypeScriptToolsVersion>1.0</TypeScriptToolsVersion>
<TypeScriptToolsVersion>1.4</TypeScriptToolsVersion>
<UseIISExpress>true</UseIISExpress>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
@ -99,9 +99,16 @@
</ItemGroup>
<ItemGroup>
<Content Include="snippet.js" />
<Content Include="web.config" />
<Content Include="min\ai.min.js.map">
<DependentUpon>ai.min.js</DependentUpon>
</Content>
<None Include="web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</None>
<None Include="web.Release.config">
<DependentUpon>web.config</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<Reference Include="AjaxMin, Version=5.5.5091.22824, Culture=neutral, PublicKeyToken=21ef50ce11b5d80f, processorArchitecture=MSIL">

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

@ -20,6 +20,11 @@ module Microsoft.ApplicationInsights {
*/
endpointUrl: () => string;
/**
* The JSON format (normal vs line delimited). True means line delimited JSON.
*/
emitLineDelimitedJson: () => boolean;
/**
* The maximum size of a batch in bytes
*/
@ -136,7 +141,9 @@ module Microsoft.ApplicationInsights {
if (this._buffer.length) {
// compose an array of payloads
var batch = "[" + this._buffer.join(",") + "]";
var batch = this._config.emitLineDelimitedJson() ?
this._buffer.join("\n"):
"[" + this._buffer.join(",") + "]";
// invoke send
this._sender(batch);

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

@ -37,8 +37,8 @@ module Microsoft.ApplicationInsights.Telemetry.Common {
// validation truncated the length. We need to add uniqueness
if (field.length !== origLength) {
var i = 0;
var uniqueField = field.substring(0, DataSanitizer.MAX_NAME_LENGTH - 3) + DataSanitizer.padNumber(i);
var i = 0;
var uniqueField = field;
while (map[uniqueField] !== undefined) {
i++;
uniqueField = field.substring(0, DataSanitizer.MAX_NAME_LENGTH - 3) + DataSanitizer.padNumber(i);
@ -75,6 +75,7 @@ module Microsoft.ApplicationInsights.Telemetry.Common {
public static sanitizeString(value) {
if (value) {
value = Util.trim(value);
if (value.toString().length > DataSanitizer.MAX_STRING_LENGTH) {
value = value.substring(0, DataSanitizer.MAX_STRING_LENGTH);
_InternalLogging.throwInternalUserActionable(
@ -129,8 +130,8 @@ module Microsoft.ApplicationInsights.Telemetry.Common {
if (properties) {
var tempProps = {};
for (var prop in properties) {
prop = DataSanitizer.sanitizeKeyAndAddUniqueness(prop, tempProps);
var value = DataSanitizer.sanitizeString(properties[prop]);
prop = DataSanitizer.sanitizeKeyAndAddUniqueness(prop, tempProps);
tempProps[prop] = value;
}
properties = tempProps;

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

@ -10,6 +10,14 @@
Util.document.cookie = name + "=" + value + ";path=/";
}
public static stringToBoolOrDefault(str: any): boolean {
if (!str) {
return false;
}
return str.toString().toLowerCase() === "true";
}
/**
* helper method to access userId and sessionId cookie
*/
@ -34,7 +42,8 @@
/**
* helper method to trim strings (IE8 does not implement String.prototype.trim)
*/
public static trim(str: string): string {
public static trim(str: any): string {
if (typeof str !== "string") return str;
return str.replace(/^\s+|\s+$/g, "");
}

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

@ -11,6 +11,7 @@ module Microsoft.ApplicationInsights {
export interface IConfig {
instrumentationKey: string;
endpointUrl: string;
emitLineDelimitedJson: boolean;
accountId: string;
appUserId: string;
sessionRenewalMs: number;
@ -61,9 +62,10 @@ module Microsoft.ApplicationInsights {
sessionRenewalMs: () => this.config.sessionRenewalMs,
sessionExpirationMs: () => this.config.sessionExpirationMs,
endpointUrl: () => this.config.endpointUrl,
emitLineDelimitedJson: () => this.config.emitLineDelimitedJson,
maxBatchSizeInBytes: () => this.config.maxBatchSizeInBytes,
maxBatchInterval: () => this.config.maxBatchInterval,
disableTelemetry: () => this.config.disableTelemetry
disableTelemetry: () => this.config.disableTelemetry
}
this.context = new ApplicationInsights.TelemetryContext(configGetters);

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

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>

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

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>

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

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>

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

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.JavaScript", "NuGet.JavaScript\NuGet.JavaScript.csproj", "{7C2662E9-96D3-473A-B0DD-55A80343A237}"
ProjectSection(ProjectDependencies) = postProject
@ -25,6 +25,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavaScriptSDK.Tests", "Java
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{6437E05C-5120-4E44-B696-61F19B0FD73A}"
ProjectSection(SolutionItems) = preProject
.nuget\packages.config = .nuget\packages.config
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NuGet.TypeScript", "NuGet.TypeScript\NuGet.TypeScript.csproj", "{314B90F5-0E04-456A-AF38-914F520C3BF3}"
ProjectSection(ProjectDependencies) = postProject