Skip to content

Commit

Permalink
Release 1.0.0-beta.11 (#746)
Browse files Browse the repository at this point in the history
* reenable Request-Context header in fetch requests

* rename ikey to iKey from ITelemetryItem

* rename timestamp to time from ITelemetryItem

* add updateSnippetDefinitions

* Bump dependency versions to latest for 1.0.0-beta.11
  • Loading branch information
markwolff committed Jan 9, 2019
1 parent 729aa2c commit 7b7b8ca
Show file tree
Hide file tree
Showing 16 changed files with 326 additions and 304 deletions.
12 changes: 6 additions & 6 deletions AISKU/package.json
@@ -1,6 +1,6 @@
{
"name": "@microsoft/applicationinsights-web",
"version": "1.0.0-beta.10",
"version": "1.0.0-beta.11",
"description": "Microsoft Application Insights Javascript SDK API 1.0 beta",
"main": "dist/applicationinsights-web.js",
"module": "dist-esm/applicationinsights-web.js",
Expand All @@ -22,10 +22,10 @@
},
"dependencies": {
"@microsoft/applicationinsights-analytics-js": "^1.0.0-beta.12",
"@microsoft/applicationinsights-channel-js": "^1.0.0-beta.11",
"@microsoft/applicationinsights-common": "^1.0.0-beta.13",
"@microsoft/applicationinsights-core-js": "^1.0.0-beta.3",
"@microsoft/applicationinsights-dependencies-js": "^1.0.0-beta.11",
"@microsoft/applicationinsights-properties-js": "^1.0.0-beta.8"
"@microsoft/applicationinsights-channel-js": "^1.0.0-beta.12",
"@microsoft/applicationinsights-common": "^1.0.0-beta.14",
"@microsoft/applicationinsights-core-js": "^1.0.0-beta.5",
"@microsoft/applicationinsights-dependencies-js": "^1.0.0-beta.12",
"@microsoft/applicationinsights-properties-js": "^1.0.0-beta.9"
}
}
7 changes: 4 additions & 3 deletions AISKU/src/ApplicationInsightsContainer.ts
Expand Up @@ -3,14 +3,15 @@ import { Initialization as ApplicationInsights, Snippet, IApplicationInsights }

export class ApplicationInsightsContainer {

public static getAppInsights(snippet: Snippet, version: number) : IApplicationInsights | IAppInsightsDeprecated {
public static getAppInsights(snippet: Snippet, version: number = 2.0) : IApplicationInsights | IAppInsightsDeprecated {
let initialization = new ApplicationInsights(snippet);
let legacyMode = version === 2.0 ? false : true;
initialization.updateSnippetDefinitions(snippet);
initialization.loadAppInsights(legacyMode);

// Two target scenarios:
// 1. Customer runs v1 snippet + runtime. If customer updates just cdn location to new SDK, it will run in compat mode so old apis work
// 2. Customer updates to new snippet (that uses cdn location to new SDK. This is same as a new customer onboarding
// 2. Customer updates to new snippet (that uses cdn location to new SDK. This is same as a new customer onboarding
// and all api signatures are expected to map to new SDK. Note new snippet specifies version

if (version === 2.0) {
Expand All @@ -19,4 +20,4 @@ export class ApplicationInsightsContainer {
return new AppInsightsDeprecated(snippet, initialization); // target scenario old snippet + updated endpoint
}
}
}
}
42 changes: 21 additions & 21 deletions AISKU/src/ApplicationInsightsDeprecated.ts
@@ -1,6 +1,6 @@
import { IConfig, PageViewPerformance, SeverityLevel, Util,
IPageViewTelemetry, ITraceTelemetry, IMetricTelemetry,
IAutoExceptionTelemetry, IDependencyTelemetry, IExceptionTelemetry,
import { IConfig, PageViewPerformance, SeverityLevel, Util,
IPageViewTelemetry, ITraceTelemetry, IMetricTelemetry,
IAutoExceptionTelemetry, IDependencyTelemetry, IExceptionTelemetry,
IEventTelemetry, IEnvelope, ProcessLegacy, HttpMethod } from "@microsoft/applicationinsights-common";
import { Snippet, IApplicationInsights } from "./Initialization";
import { ITelemetryItem, IDiagnosticLogger, IConfiguration } from "@microsoft/applicationinsights-core-js";
Expand All @@ -24,19 +24,19 @@ export class AppInsightsDeprecated implements IAppInsightsDeprecated {

// Add initializer to current processing only if there is any old telemetry initializer
if (!this._hasLegacyInitializers) {

this.appInsightsNew.addTelemetryInitializer(item => {
this._processLegacyInitializers(item); // setup call back for each legacy processor
})

this._hasLegacyInitializers = true;
}

this._queue.push(callBack);
}

private _processLegacyInitializers(item: ITelemetryItem): ITelemetryItem {

// instead of mapping new to legacy and then back again and repeating in channel, attach callback for channel to call
item.tags[ProcessLegacy] = this._queue;
return item;
Expand Down Expand Up @@ -74,13 +74,13 @@ export class AppInsightsDeprecated implements IAppInsightsDeprecated {

trackDependency(id: string, method: string, absoluteUrl: string, pathName: string, totalTime: number, success: boolean, resultCode: number) {
this.appInsightsNew.trackDependencyData(
<IDependencyTelemetry>{
id: id,
absoluteUrl: absoluteUrl,
type: pathName,
<IDependencyTelemetry>{
id: id,
absoluteUrl: absoluteUrl,
type: pathName,
duration: totalTime,
properties: { HttpMethod: method },
success: success,
success: success,
responseCode: resultCode
});
}
Expand Down Expand Up @@ -110,12 +110,12 @@ export class AppInsightsDeprecated implements IAppInsightsDeprecated {
clearAuthenticatedUserContext() {
this.appInsightsNew.clearAuthenticatedUserContext();
}

_onerror(message: string, url: string, lineNumber: number, columnNumber: number, error: Error) {
this.appInsightsNew._onerror(<IAutoExceptionTelemetry>{ message: message, url: url, lineNumber: lineNumber, columnNumber: columnNumber, error: error });
}


startTrackEvent(name: string) {
this.appInsightsNew.startTrackEvent(name);
}
Expand Down Expand Up @@ -186,11 +186,11 @@ export class AppInsightsDeprecated implements IAppInsightsDeprecated {

config.disableAjaxTracking = Util.stringToBoolOrDefault(config.disableAjaxTracking);
config.maxAjaxCallsPerView = !isNaN(config.maxAjaxCallsPerView) ? config.maxAjaxCallsPerView : 500;

config.isBeaconApiDisabled = Util.stringToBoolOrDefault(config.isBeaconApiDisabled, true);
config.disableCorrelationHeaders = Util.stringToBoolOrDefault(config.disableCorrelationHeaders);
config.correlationHeaderExcludedDomains = config.correlationHeaderExcludedDomains || [
"*.blob.core.windows.net",
"*.blob.core.windows.net",
"*.blob.core.chinacloudapi.cn",
"*.blob.core.cloudapi.de",
"*.blob.core.usgovcloudapi.net"];
Expand Down Expand Up @@ -352,11 +352,11 @@ export interface IAppInsightsDeprecated {
}

export interface ITelemetryContext {

/**
* Adds a telemetry initializer to the collection. Telemetry initializers will be called one by one,
* in the order they were added, before the telemetry item is pushed for sending.
* Adds a telemetry initializer to the collection. Telemetry initializers will be called one by one,
* in the order they were added, before the telemetry item is pushed for sending.
* If one of the telemetry initializers returns false or throws an error then the telemetry item will not be sent.
*/
addTelemetryInitializer(telemetryInitializer: (IEnvelope) => boolean | void);
}
addTelemetryInitializer(telemetryInitializer: (envelope: IEnvelope) => boolean | void);
}
10 changes: 2 additions & 8 deletions AISKU/src/Init.ts
Expand Up @@ -20,17 +20,11 @@ try {
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 ) {

var initialization = ApplicationInsightsContainer.getAppInsights(snippet, snippet.version);

// apply full appInsights to the global instance that was initialized in the snippet
for (var field in initialization) {
snippet[field] = initialization[field];
}
ApplicationInsightsContainer.getAppInsights(snippet, snippet.version);
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions AISKU/src/Initialization.ts
Expand Up @@ -267,6 +267,22 @@ export class Initialization implements IApplicationInsights {
return this;
}

/**
* Overwrite the lazy loaded fields of global window snippet to contain the
* actual initialized API methods
* @param {Snippet} snippet
* @memberof Initialization
*/
public updateSnippetDefinitions(snippet: Snippet) {
// apply full appInsights to the global instance
// Note: This must be called before loadAppInsights is called
for (var field in this) {
if (typeof field === 'string') {
snippet[field as string] = this[field];
}
}

}

/**
* Call any functions that were queued before the main script was loaded
Expand Down
8 changes: 4 additions & 4 deletions AISKULight/package.json
@@ -1,6 +1,6 @@
{
"name": "@microsoft/applicationinsights-web-basic",
"version": "1.0.0-beta.12",
"version": "1.0.0-beta.13",
"description": "Microsoft Application Insights Javascript SDK core and channel",
"main": "dist/applicationinsights-web-basic.js",
"module": "dist-esm/index.js",
Expand All @@ -22,8 +22,8 @@
"typescript": "2.5.3"
},
"dependencies": {
"@microsoft/applicationinsights-common": "^1.0.0-beta.13",
"@microsoft/applicationinsights-channel-js": "^1.0.0-beta.11",
"@microsoft/applicationinsights-core-js": "^1.0.0-beta.3"
"@microsoft/applicationinsights-common": "^1.0.0-beta.14",
"@microsoft/applicationinsights-channel-js": "^1.0.0-beta.12",
"@microsoft/applicationinsights-core-js": "^1.0.0-beta.5"
}
}
2 changes: 1 addition & 1 deletion API-reference.md
Expand Up @@ -157,7 +157,7 @@ Log an exception you have caught. (Exceptions caught by the browser are also log
Parameter | Description
---|---
`exception` | An Error from a catch clause.
`handledAt` | Defaults to "unhandled".
`handledAt` | Deprecated. This argument is ignored. Please pass `null`.
`properties` | Map of string to string: Additional data used to [filter exceptions](https://azure.microsoft.com/documentation/articles/app-insights-api-custom-events-metrics/#properties) in the portal. Defaults to empty.
`measurements` | Map of string to number: Metrics associated with this page, displayed in Metrics Explorer on the portal. Defaults to empty.
`severityLevel` | Supported values: [SeverityLevel.ts](https://github.com/Microsoft/ApplicationInsights-JS/blob/master/JavaScript/JavaScriptSDK.Interfaces/Contracts/Generated/SeverityLevel.ts)
Expand Down
4 changes: 2 additions & 2 deletions AppInsightsCommon/package.json
@@ -1,6 +1,6 @@
{
"name": "@microsoft/applicationinsights-common",
"version": "1.0.0-beta.13",
"version": "1.0.0-beta.14",
"description": "Microsoft Application Insights Common JavaScript Library",
"main": "./dist/applicationinsights-common.js",
"module": "./dist-esm/applicationinsights-common.js",
Expand Down Expand Up @@ -28,7 +28,7 @@
"typescript": "2.5.3"
},
"dependencies": {
"@microsoft/applicationinsights-core-js": "^1.0.0-beta.3"
"@microsoft/applicationinsights-core-js": "^1.0.0-beta.5"
},
"license": "MIT"
}
18 changes: 9 additions & 9 deletions AppInsightsCommon/src/TelemetryItemCreator.ts
Expand Up @@ -39,8 +39,8 @@ export class TelemetryItemCreator {

let telemetryItem: ITelemetryItem = {
name: envelopeName,
timestamp: new Date(),
instrumentationKey: "", // this will be set in TelemetryContext
time: new Date().toISOString(),
iKey: "", // this will be set in TelemetryContext
ctx: systemProperties ? systemProperties : {}, // part A
tags: [],
data: {
Expand Down Expand Up @@ -79,10 +79,10 @@ export class TelemetryItemCreator {

let dependencyTelemetry = <IDependencyTelemetry>(env.data.baseType);
telemetryItem = TelemetryItemCreator.create<IDependencyTelemetry>(
dependencyTelemetry,
RemoteDependencyData.dataType,
dependencyTelemetry,
RemoteDependencyData.dataType,
RemoteDependencyData.envelopeType,
logger,
logger,
customProperties);
}

Expand Down Expand Up @@ -216,18 +216,18 @@ export class TelemetryItemCreator {
}



if (env.tags[CtxTagKeys.operationRootId]) {
item.tags[CtxTagKeys.operationRootId] = env.tags[CtxTagKeys.operationRootId];
keysFound.push(CtxTagKeys.operationRootId);
}


if (env.tags[CtxTagKeys.operationSyntheticSource]) {
item.tags[CtxTagKeys.operationSyntheticSource] = env.tags[CtxTagKeys.operationSyntheticSource];
keysFound.push(CtxTagKeys.operationSyntheticSource);
}

if (env.tags[CtxTagKeys.operationParentId]) {
item.tags[CtxTagKeys.operationParentId] = env.tags[CtxTagKeys.operationParentId];
keysFound.push(CtxTagKeys.operationParentId);
Expand All @@ -249,4 +249,4 @@ export class TelemetryItemCreator {
}
})
}
}
}
2 changes: 1 addition & 1 deletion ApplicationInsights/Tests/ApplicationInsights.tests.ts
Expand Up @@ -114,7 +114,7 @@ export class ApplicationInsightsTests extends TestClass {
var test = (action, expectedEnvelopeType, expectedDataType, test?: () => void) => {
action();
envelope = this.getFirstResult(action, trackStub);
Assert.equal(iKey, envelope.instrumentationKey, "envelope iKey");
Assert.equal(iKey, envelope.iKey, "envelope iKey");
Assert.equal(expectedEnvelopeType.replace("{0}", iKeyNoDash), envelope.name, "envelope name");
Assert.equal(expectedDataType, envelope.baseType, "data type name");
if (typeof test === 'function') {test();}
Expand Down
6 changes: 3 additions & 3 deletions ApplicationInsights/package.json
@@ -1,6 +1,6 @@
{
"name": "@microsoft/applicationinsights-analytics-js",
"version": "1.0.0-beta.11",
"version": "1.0.0-beta.12",
"description": "Microsoft Application Insights Javascript SDK apis",
"main": "dist/applicationinsights-analytics-js.js",
"module": "dist-esm/applicationinsights-analytics-js.js",
Expand All @@ -23,8 +23,8 @@
"rollup-plugin-uglify": "^6.0.0"
},
"dependencies": {
"@microsoft/applicationinsights-core-js": "^1.0.0-beta.3",
"@microsoft/applicationinsights-common": "^1.0.0-beta.13"
"@microsoft/applicationinsights-core-js": "^1.0.0-beta.5",
"@microsoft/applicationinsights-common": "^1.0.0-beta.14"
},
"license": "MIT"
}
6 changes: 3 additions & 3 deletions ApplicationInsights/src/JavaScriptSDK/ApplicationInsights.ts
Expand Up @@ -482,13 +482,13 @@ export class ApplicationInsights implements IAppInsights, ITelemetryPlugin, IApp


this._eventTracking = new Timing(this._logger, "trackEvent");
this._eventTracking.action =
this._eventTracking.action =
(name?: string, url?: string, duration?: number, properties?: Object, measurements?: Object) => {
if (!measurements) {
measurements = {};
}

measurements["duration"] = duration ; // ToDo: fix once IEventTelemetry is updated
measurements["duration"] = duration ; // ToDo: fix once IEventTelemetry is updated
this.trackEvent(<IEventTelemetry>{ name: name });
}

Expand Down Expand Up @@ -581,7 +581,7 @@ export class ApplicationInsights implements IAppInsights, ITelemetryPlugin, IApp

// Mutate telemetryItem inplace to add boilerplate iKey & name info
private _setTelemetryNameAndIKey(telemetryItem: ITelemetryItem): void {
telemetryItem.instrumentationKey = this._globalconfig.instrumentationKey;
telemetryItem.iKey = this._globalconfig.instrumentationKey;

var iKeyNoDashes = this._globalconfig.instrumentationKey.replace(/-/g, "");
telemetryItem.name = telemetryItem.name.replace("{0}", iKeyNoDashes);
Expand Down

0 comments on commit 7b7b8ca

Please sign in to comment.