@microsoft/applicationinsights-channel-js 3.0.0-beta.2303-10 → 3.0.0-beta.2304-07
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/es5/applicationinsights-channel-js.3.0.0-beta.2304-07.cjs.js +5768 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-beta.2304-07.cjs.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-beta.2304-07.cjs.min.js +6 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-beta.2304-07.cjs.min.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-beta.2304-07.gbl.js +5772 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-beta.2304-07.gbl.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-beta.2304-07.gbl.min.js +6 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-beta.2304-07.gbl.min.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-beta.2304-07.integrity.json +66 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-beta.2304-07.js +5774 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-beta.2304-07.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-beta.2304-07.min.js +6 -0
- package/browser/es5/applicationinsights-channel-js.3.0.0-beta.2304-07.min.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.cjs.js +5768 -0
- package/browser/es5/applicationinsights-channel-js.3.cjs.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.cjs.min.js +6 -0
- package/browser/es5/applicationinsights-channel-js.3.cjs.min.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.gbl.js +5772 -0
- package/browser/es5/applicationinsights-channel-js.3.gbl.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.gbl.min.js +6 -0
- package/browser/es5/applicationinsights-channel-js.3.gbl.min.js.map +1 -0
- package/{dist/applicationinsights-channel-js.js → browser/es5/applicationinsights-channel-js.3.js} +901 -850
- package/browser/es5/applicationinsights-channel-js.3.js.map +1 -0
- package/browser/es5/applicationinsights-channel-js.3.min.js +6 -0
- package/browser/es5/applicationinsights-channel-js.3.min.js.map +1 -0
- package/{browser → dist/es5}/applicationinsights-channel-js.js +900 -849
- package/dist/es5/applicationinsights-channel-js.js.map +1 -0
- package/dist/es5/applicationinsights-channel-js.min.js +6 -0
- package/dist/es5/applicationinsights-channel-js.min.js.map +1 -0
- package/{dist-esm → dist-es5}/EnvelopeCreator.js +2 -2
- package/{dist-esm → dist-es5}/EnvelopeCreator.js.map +1 -1
- package/{dist-esm → dist-es5}/Interfaces.js +1 -1
- package/{dist-esm → dist-es5}/InternalConstants.js +1 -1
- package/{dist-esm → dist-es5}/Offline.js +8 -7
- package/dist-es5/Offline.js.map +1 -0
- package/{dist-esm → dist-es5}/SendBuffer.js +1 -1
- package/{dist-esm → dist-es5}/Sender.js +6 -4
- package/dist-es5/Sender.js.map +1 -0
- package/{dist-esm → dist-es5}/Serializer.js +1 -1
- package/{dist-esm → dist-es5}/TelemetryProcessors/Sample.js +1 -1
- package/{dist-esm → dist-es5}/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.js +1 -1
- package/{dist-esm → dist-es5}/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.js +1 -1
- package/{dist-esm → dist-es5}/__DynamicConstants.js +2 -1
- package/dist-es5/__DynamicConstants.js.map +1 -0
- package/{dist-esm → dist-es5}/applicationinsights-channel-js.js +1 -1
- package/package.json +17 -16
- package/tsconfig.json +5 -4
- package/types/applicationinsights-channel-js.d.ts +284 -1
- package/{dist/applicationinsights-channel-js.d.ts → types/applicationinsights-channel-js.namespaced.d.ts} +1 -1
- package/browser/applicationinsights-channel-js.integrity.json +0 -26
- package/browser/applicationinsights-channel-js.js.map +0 -1
- package/browser/applicationinsights-channel-js.min.js +0 -6
- package/browser/applicationinsights-channel-js.min.js.map +0 -1
- package/dist/applicationinsights-channel-js.api.json +0 -1357
- package/dist/applicationinsights-channel-js.api.md +0 -60
- package/dist/applicationinsights-channel-js.js.map +0 -1
- package/dist/applicationinsights-channel-js.min.js +0 -6
- package/dist/applicationinsights-channel-js.min.js.map +0 -1
- package/dist/applicationinsights-channel-js.rollup.d.ts +0 -285
- package/dist-esm/Offline.js.map +0 -1
- package/dist-esm/Sender.js.map +0 -1
- package/dist-esm/__DynamicConstants.js.map +0 -1
- package/src/EnvelopeCreator.ts +0 -351
- package/src/Interfaces.ts +0 -114
- package/src/InternalConstants.ts +0 -11
- package/src/Offline.ts +0 -106
- package/src/SendBuffer.ts +0 -396
- package/src/Sender.ts +0 -1256
- package/src/Serializer.ts +0 -177
- package/src/TelemetryProcessors/Sample.ts +0 -49
- package/src/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.ts +0 -37
- package/src/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.ts +0 -35
- package/src/__DynamicConstants.ts +0 -64
- package/src/applicationinsights-channel-js.ts +0 -1
- package/types/EnvelopeCreator.d.ts +0 -12
- package/types/Interfaces.d.ts +0 -95
- package/types/InternalConstants.d.ts +0 -1
- package/types/Offline.d.ts +0 -10
- package/types/SendBuffer.d.ts +0 -73
- package/types/Sender.d.ts +0 -84
- package/types/Serializer.d.ts +0 -9
- package/types/TelemetryProcessors/Sample.d.ts +0 -12
- package/types/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.d.ts +0 -5
- package/types/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.d.ts +0 -5
- package/types/__DynamicConstants.d.ts +0 -52
- package/types/tsdoc-metadata.json +0 -11
- /package/{dist-esm → dist-es5}/Interfaces.js.map +0 -0
- /package/{dist-esm → dist-es5}/InternalConstants.js.map +0 -0
- /package/{dist-esm → dist-es5}/SendBuffer.js.map +0 -0
- /package/{dist-esm → dist-es5}/Serializer.js.map +0 -0
- /package/{dist-esm → dist-es5}/TelemetryProcessors/Sample.js.map +0 -0
- /package/{dist-esm → dist-es5}/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.js.map +0 -0
- /package/{dist-esm → dist-es5}/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.js.map +0 -0
- /package/{dist-esm → dist-es5}/applicationinsights-channel-js.js.map +0 -0
package/src/EnvelopeCreator.ts
DELETED
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CtxTagKeys, Data, Envelope, Event, Exception, HttpMethod, IDependencyTelemetry, IEnvelope, IExceptionInternal,
|
|
3
|
-
IPageViewPerformanceTelemetry, IPageViewTelemetryInternal, IWeb, Metric, PageView, PageViewPerformance, RemoteDependencyData, SampleRate,
|
|
4
|
-
Trace, dataSanitizeString
|
|
5
|
-
} from "@microsoft/applicationinsights-common";
|
|
6
|
-
import {
|
|
7
|
-
IDiagnosticLogger, ITelemetryItem, _eInternalMessageId, _throwInternal, _warnToConsole, eLoggingSeverity, getJSON, hasJSON,
|
|
8
|
-
isNullOrUndefined, isNumber, isString, isTruthy, objForEachKey, optimizeObject, setValue, toISOString
|
|
9
|
-
} from "@microsoft/applicationinsights-core-js";
|
|
10
|
-
import { STR_DURATION } from "./InternalConstants";
|
|
11
|
-
|
|
12
|
-
// these two constants are used to filter out properties not needed when trying to extract custom properties and measurements from the incoming payload
|
|
13
|
-
const strBaseType = "baseType";
|
|
14
|
-
const strBaseData = "baseData";
|
|
15
|
-
const strProperties = "properties";
|
|
16
|
-
const strTrue = "true";
|
|
17
|
-
|
|
18
|
-
function _setValueIf<T>(target:T, field:keyof T, value:any) {
|
|
19
|
-
return setValue(target, field, value, isTruthy);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/*
|
|
23
|
-
* Maps Part A data from CS 4.0
|
|
24
|
-
*/
|
|
25
|
-
function _extractPartAExtensions(logger: IDiagnosticLogger, item: ITelemetryItem, env: IEnvelope) {
|
|
26
|
-
// todo: switch to keys from common in this method
|
|
27
|
-
let envTags = env.tags = env.tags || {};
|
|
28
|
-
let itmExt = item.ext = item.ext || {};
|
|
29
|
-
let itmTags = item.tags = item.tags || [];
|
|
30
|
-
|
|
31
|
-
let extUser = itmExt.user;
|
|
32
|
-
if (extUser) {
|
|
33
|
-
_setValueIf(envTags, CtxTagKeys.userAuthUserId, extUser.authId);
|
|
34
|
-
_setValueIf(envTags, CtxTagKeys.userId, extUser.id || extUser.localId);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let extApp = itmExt.app;
|
|
38
|
-
if (extApp) {
|
|
39
|
-
_setValueIf(envTags, CtxTagKeys.sessionId, extApp.sesId);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let extDevice = itmExt.device;
|
|
43
|
-
if (extDevice) {
|
|
44
|
-
_setValueIf(envTags, CtxTagKeys.deviceId, extDevice.id || extDevice.localId);
|
|
45
|
-
_setValueIf(envTags, CtxTagKeys.deviceType, extDevice.deviceClass);
|
|
46
|
-
_setValueIf(envTags, CtxTagKeys.deviceIp, extDevice.ip);
|
|
47
|
-
_setValueIf(envTags, CtxTagKeys.deviceModel, extDevice.model);
|
|
48
|
-
_setValueIf(envTags, CtxTagKeys.deviceType, extDevice.deviceType);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const web: IWeb = item.ext.web as IWeb;
|
|
52
|
-
if (web) {
|
|
53
|
-
_setValueIf(envTags, CtxTagKeys.deviceLanguage, web.browserLang);
|
|
54
|
-
_setValueIf(envTags, CtxTagKeys.deviceBrowserVersion, web.browserVer);
|
|
55
|
-
_setValueIf(envTags, CtxTagKeys.deviceBrowser, web.browser);
|
|
56
|
-
|
|
57
|
-
let envData = env.data = env.data || {};
|
|
58
|
-
let envBaseData = envData[strBaseData] = envData[strBaseData] || {};
|
|
59
|
-
let envProps = envBaseData[strProperties] = envBaseData[strProperties] || {};
|
|
60
|
-
|
|
61
|
-
_setValueIf(envProps, "domain", web.domain);
|
|
62
|
-
_setValueIf(envProps, "isManual", web.isManual ? strTrue : null);
|
|
63
|
-
_setValueIf(envProps, "screenRes", web.screenRes);
|
|
64
|
-
_setValueIf(envProps, "userConsent", web.userConsent ? strTrue : null);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
let extOs = itmExt.os;
|
|
68
|
-
if (extOs) {
|
|
69
|
-
_setValueIf(envTags, CtxTagKeys.deviceOS, extOs.name);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// No support for mapping Trace.traceState to 2.0 as it is currently empty
|
|
73
|
-
|
|
74
|
-
let extTrace = itmExt.trace;
|
|
75
|
-
if (extTrace) {
|
|
76
|
-
_setValueIf(envTags, CtxTagKeys.operationParentId, extTrace.parentID);
|
|
77
|
-
_setValueIf(envTags, CtxTagKeys.operationName, dataSanitizeString(logger, extTrace.name));
|
|
78
|
-
_setValueIf(envTags, CtxTagKeys.operationId, extTrace.traceID);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Sample 4.0 schema
|
|
82
|
-
// {
|
|
83
|
-
// "time" : "2018-09-05T22:51:22.4936Z",
|
|
84
|
-
// "name" : "MetricWithNamespace",
|
|
85
|
-
// "iKey" : "ABC-5a4cbd20-e601-4ef5-a3c6-5d6577e4398e",
|
|
86
|
-
// "ext": { "cloud": {
|
|
87
|
-
// "role": "WATSON3",
|
|
88
|
-
// "roleInstance": "CO4AEAP00000260"
|
|
89
|
-
// },
|
|
90
|
-
// "device": {}, "correlation": {} },
|
|
91
|
-
// "tags": [
|
|
92
|
-
// { "amazon.region" : "east2" },
|
|
93
|
-
// { "os.expid" : "wp:02df239" }
|
|
94
|
-
// ]
|
|
95
|
-
// }
|
|
96
|
-
|
|
97
|
-
const tgs = {};
|
|
98
|
-
// deals with tags.push({object})
|
|
99
|
-
for(let i = itmTags.length - 1; i >= 0; i--){
|
|
100
|
-
const tg = itmTags[i];
|
|
101
|
-
objForEachKey(tg, (key, value) => {
|
|
102
|
-
tgs[key] = value;
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
itmTags.splice(i, 1);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// deals with tags[key]=value (and handles hasOwnProperty)
|
|
109
|
-
objForEachKey(itmTags, (tg, value) => {
|
|
110
|
-
tgs[tg] = value;
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
let theTags = { ...envTags, ...tgs };
|
|
114
|
-
if(!theTags[CtxTagKeys.internalSdkVersion]) {
|
|
115
|
-
// Append a version in case it is not already set
|
|
116
|
-
theTags[CtxTagKeys.internalSdkVersion] = `javascript:${EnvelopeCreator.Version}`;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
env.tags = optimizeObject(theTags);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function _extractPropsAndMeasurements(data: { [key: string]: any }, properties: { [key: string]: any }, measurements: { [key: string]: any }) {
|
|
123
|
-
if (!isNullOrUndefined(data)) {
|
|
124
|
-
objForEachKey(data, (key, value) => {
|
|
125
|
-
if (isNumber(value)) {
|
|
126
|
-
measurements[key] = value;
|
|
127
|
-
} else if (isString(value)) {
|
|
128
|
-
properties[key] = value;
|
|
129
|
-
} else if (hasJSON()) {
|
|
130
|
-
properties[key] = getJSON().stringify(value);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function _convertPropsUndefinedToCustomDefinedValue(properties: { [key: string]: any }, customUndefinedValue: any) {
|
|
137
|
-
if (!isNullOrUndefined(properties)) {
|
|
138
|
-
objForEachKey(properties, (key, value) => {
|
|
139
|
-
properties[key] = value || customUndefinedValue;
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// TODO: Do we want this to take logger as arg or use this._logger as nonstatic?
|
|
145
|
-
function _createEnvelope<T>(logger: IDiagnosticLogger, envelopeType: string, telemetryItem: ITelemetryItem, data: Data<T>): IEnvelope {
|
|
146
|
-
const envelope = new Envelope(logger, data, envelopeType);
|
|
147
|
-
|
|
148
|
-
_setValueIf(envelope, "sampleRate", telemetryItem[SampleRate]);
|
|
149
|
-
if ((telemetryItem[strBaseData] || {}).startTime) {
|
|
150
|
-
envelope.time = toISOString(telemetryItem[strBaseData].startTime);
|
|
151
|
-
}
|
|
152
|
-
envelope.iKey = telemetryItem.iKey;
|
|
153
|
-
const iKeyNoDashes = telemetryItem.iKey.replace(/-/g, "");
|
|
154
|
-
envelope.name = envelope.name.replace("{0}", iKeyNoDashes);
|
|
155
|
-
|
|
156
|
-
// extract all extensions from ctx
|
|
157
|
-
_extractPartAExtensions(logger, telemetryItem, envelope);
|
|
158
|
-
|
|
159
|
-
// loop through the envelope tags (extension of Part A) and pick out the ones that should go in outgoing envelope tags
|
|
160
|
-
telemetryItem.tags = telemetryItem.tags || [];
|
|
161
|
-
|
|
162
|
-
return optimizeObject(envelope);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function EnvelopeCreatorInit(logger: IDiagnosticLogger, telemetryItem: ITelemetryItem) {
|
|
166
|
-
if (isNullOrUndefined(telemetryItem[strBaseData])) {
|
|
167
|
-
_throwInternal(logger,
|
|
168
|
-
eLoggingSeverity.CRITICAL,
|
|
169
|
-
_eInternalMessageId.TelemetryEnvelopeInvalid, "telemetryItem.baseData cannot be null.");
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export const EnvelopeCreator = {
|
|
174
|
-
Version: "#version#"
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
export function DependencyEnvelopeCreator(logger: IDiagnosticLogger, telemetryItem: ITelemetryItem, customUndefinedValue?: any): IEnvelope {
|
|
178
|
-
EnvelopeCreatorInit(logger, telemetryItem);
|
|
179
|
-
|
|
180
|
-
const customMeasurements = telemetryItem[strBaseData].measurements || {};
|
|
181
|
-
const customProperties = telemetryItem[strBaseData][strProperties] || {};
|
|
182
|
-
_extractPropsAndMeasurements(telemetryItem.data, customProperties, customMeasurements);
|
|
183
|
-
if (!isNullOrUndefined(customUndefinedValue)) {
|
|
184
|
-
_convertPropsUndefinedToCustomDefinedValue(customProperties, customUndefinedValue);
|
|
185
|
-
}
|
|
186
|
-
const bd = telemetryItem[strBaseData] as IDependencyTelemetry;
|
|
187
|
-
if (isNullOrUndefined(bd)) {
|
|
188
|
-
_warnToConsole(logger, "Invalid input for dependency data");
|
|
189
|
-
return null;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const method = bd[strProperties] && bd[strProperties][HttpMethod] ? bd[strProperties][HttpMethod] : "GET";
|
|
193
|
-
const remoteDepData = new RemoteDependencyData(logger, bd.id, bd.target, bd.name, bd.duration, bd.success, bd.responseCode, method, bd.type, bd.correlationContext, customProperties, customMeasurements);
|
|
194
|
-
const data = new Data<RemoteDependencyData>(RemoteDependencyData.dataType, remoteDepData);
|
|
195
|
-
return _createEnvelope<RemoteDependencyData>(logger, RemoteDependencyData.envelopeType, telemetryItem, data);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export function EventEnvelopeCreator(logger: IDiagnosticLogger, telemetryItem: ITelemetryItem, customUndefinedValue?: any): IEnvelope {
|
|
199
|
-
EnvelopeCreatorInit(logger, telemetryItem);
|
|
200
|
-
|
|
201
|
-
let customProperties = {};
|
|
202
|
-
let customMeasurements = {};
|
|
203
|
-
if (telemetryItem[strBaseType] !== Event.dataType) {
|
|
204
|
-
customProperties["baseTypeSource"] = telemetryItem[strBaseType]; // save the passed in base type as a property
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (telemetryItem[strBaseType] === Event.dataType) { // take collection
|
|
208
|
-
customProperties = telemetryItem[strBaseData][strProperties] || {};
|
|
209
|
-
customMeasurements = telemetryItem[strBaseData].measurements || {};
|
|
210
|
-
} else { // if its not a known type, convert to custom event
|
|
211
|
-
if (telemetryItem[strBaseData]) {
|
|
212
|
-
_extractPropsAndMeasurements(telemetryItem[strBaseData], customProperties, customMeasurements);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// Extract root level properties from part C telemetryItem.data
|
|
217
|
-
_extractPropsAndMeasurements(telemetryItem.data, customProperties, customMeasurements);
|
|
218
|
-
if (!isNullOrUndefined(customUndefinedValue)) {
|
|
219
|
-
_convertPropsUndefinedToCustomDefinedValue(customProperties, customUndefinedValue);
|
|
220
|
-
}
|
|
221
|
-
const eventName = telemetryItem[strBaseData].name;
|
|
222
|
-
const eventData = new Event(logger, eventName, customProperties, customMeasurements);
|
|
223
|
-
const data = new Data<Event>(Event.dataType, eventData);
|
|
224
|
-
return _createEnvelope<Event>(logger, Event.envelopeType, telemetryItem, data);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
export function ExceptionEnvelopeCreator(logger: IDiagnosticLogger, telemetryItem: ITelemetryItem, customUndefinedValue?: any): IEnvelope {
|
|
228
|
-
EnvelopeCreatorInit(logger, telemetryItem);
|
|
229
|
-
|
|
230
|
-
// Extract root level properties from part C telemetryItem.data
|
|
231
|
-
const customMeasurements = telemetryItem[strBaseData].measurements || {};
|
|
232
|
-
const customProperties = telemetryItem[strBaseData][strProperties] || {};
|
|
233
|
-
_extractPropsAndMeasurements(telemetryItem.data, customProperties, customMeasurements);
|
|
234
|
-
if (!isNullOrUndefined(customUndefinedValue)) {
|
|
235
|
-
_convertPropsUndefinedToCustomDefinedValue(customProperties, customUndefinedValue);
|
|
236
|
-
}
|
|
237
|
-
const bd = telemetryItem[strBaseData] as IExceptionInternal;
|
|
238
|
-
const exData = Exception.CreateFromInterface(logger, bd, customProperties, customMeasurements);
|
|
239
|
-
const data = new Data<Exception>(Exception.dataType, exData);
|
|
240
|
-
return _createEnvelope<Exception>(logger, Exception.envelopeType, telemetryItem, data);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export function MetricEnvelopeCreator(logger: IDiagnosticLogger, telemetryItem: ITelemetryItem, customUndefinedValue?: any): IEnvelope {
|
|
244
|
-
EnvelopeCreatorInit(logger, telemetryItem);
|
|
245
|
-
|
|
246
|
-
const baseData = telemetryItem[strBaseData];
|
|
247
|
-
const props = baseData[strProperties] || {};
|
|
248
|
-
const measurements = baseData.measurements || {};
|
|
249
|
-
_extractPropsAndMeasurements(telemetryItem.data, props, measurements);
|
|
250
|
-
if (!isNullOrUndefined(customUndefinedValue)) {
|
|
251
|
-
_convertPropsUndefinedToCustomDefinedValue(props, customUndefinedValue);
|
|
252
|
-
}
|
|
253
|
-
const baseMetricData = new Metric(logger, baseData.name, baseData.average, baseData.sampleCount, baseData.min, baseData.max, baseData.stdDev, props, measurements);
|
|
254
|
-
const data = new Data<Metric>(Metric.dataType, baseMetricData);
|
|
255
|
-
return _createEnvelope<Metric>(logger, Metric.envelopeType, telemetryItem, data);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export function PageViewEnvelopeCreator(logger: IDiagnosticLogger, telemetryItem: ITelemetryItem, customUndefinedValue?: any): IEnvelope {
|
|
259
|
-
EnvelopeCreatorInit(logger, telemetryItem);
|
|
260
|
-
|
|
261
|
-
// Since duration is not part of the domain properties in Common Schema, extract it from part C
|
|
262
|
-
let duration;
|
|
263
|
-
let baseData = telemetryItem[strBaseData];
|
|
264
|
-
if (!isNullOrUndefined(baseData) &&
|
|
265
|
-
!isNullOrUndefined(baseData[strProperties]) &&
|
|
266
|
-
!isNullOrUndefined(baseData[strProperties][STR_DURATION])) { // from part B properties
|
|
267
|
-
duration = baseData[strProperties][STR_DURATION];
|
|
268
|
-
delete baseData[strProperties][STR_DURATION];
|
|
269
|
-
} else if (!isNullOrUndefined(telemetryItem.data) &&
|
|
270
|
-
!isNullOrUndefined(telemetryItem.data[STR_DURATION])) { // from custom properties
|
|
271
|
-
duration = telemetryItem.data[STR_DURATION];
|
|
272
|
-
delete telemetryItem.data[STR_DURATION];
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const bd = telemetryItem[strBaseData] as IPageViewTelemetryInternal;
|
|
276
|
-
|
|
277
|
-
// special case: pageview.id is grabbed from current operation id. Analytics plugin is decoupled from properties plugin, so this is done here instead. This can be made a default telemetry intializer instead if needed to be decoupled from channel
|
|
278
|
-
let currentContextId;
|
|
279
|
-
if (((telemetryItem.ext || {}).trace || {}).traceID) {
|
|
280
|
-
currentContextId = telemetryItem.ext.trace.traceID;
|
|
281
|
-
}
|
|
282
|
-
const id = bd.id || currentContextId;
|
|
283
|
-
const name = bd.name;
|
|
284
|
-
const url = bd.uri;
|
|
285
|
-
const properties = bd[strProperties] || {};
|
|
286
|
-
const measurements = bd.measurements || {};
|
|
287
|
-
|
|
288
|
-
// refUri is a field that Breeze still does not recognize as part of Part B. For now, put it in Part C until it supports it as a domain property
|
|
289
|
-
if (!isNullOrUndefined(bd.refUri)) {
|
|
290
|
-
properties["refUri"] = bd.refUri;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// pageType is a field that Breeze still does not recognize as part of Part B. For now, put it in Part C until it supports it as a domain property
|
|
294
|
-
if (!isNullOrUndefined(bd.pageType)) {
|
|
295
|
-
properties["pageType"] = bd.pageType;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// isLoggedIn is a field that Breeze still does not recognize as part of Part B. For now, put it in Part C until it supports it as a domain property
|
|
299
|
-
if (!isNullOrUndefined(bd.isLoggedIn)) {
|
|
300
|
-
properties["isLoggedIn"] = bd.isLoggedIn.toString();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// pageTags is a field that Breeze still does not recognize as part of Part B. For now, put it in Part C until it supports it as a domain property
|
|
304
|
-
if (!isNullOrUndefined(bd[strProperties])) {
|
|
305
|
-
const pageTags = bd[strProperties];
|
|
306
|
-
objForEachKey(pageTags, (key, value) => {
|
|
307
|
-
properties[key] = value;
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
_extractPropsAndMeasurements(telemetryItem.data, properties, measurements);
|
|
312
|
-
if (!isNullOrUndefined(customUndefinedValue)) {
|
|
313
|
-
_convertPropsUndefinedToCustomDefinedValue(properties, customUndefinedValue);
|
|
314
|
-
}
|
|
315
|
-
const pageViewData = new PageView(logger, name, url, duration, properties, measurements, id);
|
|
316
|
-
const data = new Data<PageView>(PageView.dataType, pageViewData);
|
|
317
|
-
return _createEnvelope<PageView>(logger, PageView.envelopeType, telemetryItem, data);
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
export function PageViewPerformanceEnvelopeCreator(logger: IDiagnosticLogger, telemetryItem: ITelemetryItem, customUndefinedValue?: any): IEnvelope {
|
|
321
|
-
EnvelopeCreatorInit(logger, telemetryItem);
|
|
322
|
-
|
|
323
|
-
const bd = telemetryItem[strBaseData] as IPageViewPerformanceTelemetry;
|
|
324
|
-
const name = bd.name;
|
|
325
|
-
const url = bd.uri || (bd as any).url;
|
|
326
|
-
const properties = bd[strProperties] || {};
|
|
327
|
-
const measurements = bd.measurements || {};
|
|
328
|
-
_extractPropsAndMeasurements(telemetryItem.data, properties, measurements);
|
|
329
|
-
if (!isNullOrUndefined(customUndefinedValue)) {
|
|
330
|
-
_convertPropsUndefinedToCustomDefinedValue(properties, customUndefinedValue);
|
|
331
|
-
}
|
|
332
|
-
const baseData = new PageViewPerformance(logger, name, url, undefined, properties, measurements, bd);
|
|
333
|
-
const data = new Data<PageViewPerformance>(PageViewPerformance.dataType, baseData);
|
|
334
|
-
return _createEnvelope<PageViewPerformance>(logger, PageViewPerformance.envelopeType, telemetryItem, data);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
export function TraceEnvelopeCreator(logger: IDiagnosticLogger, telemetryItem: ITelemetryItem, customUndefinedValue?: any): IEnvelope {
|
|
338
|
-
EnvelopeCreatorInit(logger, telemetryItem);
|
|
339
|
-
|
|
340
|
-
const message = telemetryItem[strBaseData].message;
|
|
341
|
-
const severityLevel = telemetryItem[strBaseData].severityLevel;
|
|
342
|
-
const props = telemetryItem[strBaseData][strProperties] || {};
|
|
343
|
-
const measurements = telemetryItem[strBaseData].measurements || {};
|
|
344
|
-
_extractPropsAndMeasurements(telemetryItem.data, props, measurements);
|
|
345
|
-
if (!isNullOrUndefined(customUndefinedValue)) {
|
|
346
|
-
_convertPropsUndefinedToCustomDefinedValue(props, customUndefinedValue);
|
|
347
|
-
}
|
|
348
|
-
const baseData = new Trace(logger, message, severityLevel, props, measurements);
|
|
349
|
-
const data = new Data<Trace>(Trace.dataType, baseData);
|
|
350
|
-
return _createEnvelope<Trace>(logger, Trace.envelopeType, telemetryItem, data);
|
|
351
|
-
}
|
package/src/Interfaces.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
export interface ISenderConfig {
|
|
2
|
-
/**
|
|
3
|
-
* The url to which payloads will be sent
|
|
4
|
-
*/
|
|
5
|
-
endpointUrl: string;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The JSON format (normal vs line delimited). True means line delimited JSON.
|
|
9
|
-
*/
|
|
10
|
-
emitLineDelimitedJson: boolean;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The maximum size of a batch in bytes
|
|
14
|
-
*/
|
|
15
|
-
maxBatchSizeInBytes: number;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The maximum interval allowed between calls to batchInvoke
|
|
19
|
-
*/
|
|
20
|
-
maxBatchInterval: number;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The master off switch. Do not send any data if set to TRUE
|
|
24
|
-
*/
|
|
25
|
-
disableTelemetry: boolean;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Store a copy of a send buffer in the session storage
|
|
29
|
-
*/
|
|
30
|
-
enableSessionStorageBuffer: boolean;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Is retry handler disabled.
|
|
34
|
-
* If enabled, retry on 206 (partial success), 408 (timeout), 429 (too many requests), 500 (internal server error) and 503 (service unavailable).
|
|
35
|
-
*/
|
|
36
|
-
isRetryDisabled: boolean;
|
|
37
|
-
|
|
38
|
-
isBeaconApiDisabled: boolean;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Don't use XMLHttpRequest or XDomainRequest (for IE < 9) by default instead attempt to use fetch() or sendBeacon.
|
|
42
|
-
* If no other transport is available it will still use XMLHttpRequest
|
|
43
|
-
*/
|
|
44
|
-
disableXhr: boolean;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* If fetch keepalive is supported do not use it for sending events during unload, it may still fallback to fetch() without keepalive
|
|
48
|
-
*/
|
|
49
|
-
onunloadDisableFetch: boolean;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Is beacon disabled on page unload.
|
|
53
|
-
* If enabled, flush events through beaconSender.
|
|
54
|
-
*/
|
|
55
|
-
onunloadDisableBeacon: boolean;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* (Optional) Override the instrumentation key that this channel instance sends to
|
|
59
|
-
*/
|
|
60
|
-
instrumentationKey: string;
|
|
61
|
-
|
|
62
|
-
namePrefix: string;
|
|
63
|
-
|
|
64
|
-
samplingPercentage: number;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* (Optional) The ability for the user to provide extra headers
|
|
68
|
-
*/
|
|
69
|
-
customHeaders: [{header: string, value: string}];
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* (Optional) Provide user an option to convert undefined field to user defined value.
|
|
73
|
-
*/
|
|
74
|
-
convertUndefined: any
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* (Optional) The number of events that can be kept in memory before the SDK starts to drop events. By default, this is 10,000.
|
|
78
|
-
*/
|
|
79
|
-
eventsLimitInMem: number;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export interface IBackendResponse {
|
|
83
|
-
/**
|
|
84
|
-
* Number of items received by the backend
|
|
85
|
-
*/
|
|
86
|
-
readonly itemsReceived: number;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Number of items succesfuly accepted by the backend
|
|
90
|
-
*/
|
|
91
|
-
readonly itemsAccepted: number;
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* List of errors for items which were not accepted
|
|
95
|
-
*/
|
|
96
|
-
readonly errors: IResponseError[];
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* App id returned by the backend - not necessary returned, but we don't need it with each response.
|
|
100
|
-
*/
|
|
101
|
-
readonly appId?: string;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface XDomainRequest extends XMLHttpRequestEventTarget {
|
|
105
|
-
readonly responseText: string;
|
|
106
|
-
send(payload: string): void;
|
|
107
|
-
open(method: string, url: string): void;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export interface IResponseError {
|
|
111
|
-
readonly index: number;
|
|
112
|
-
readonly statusCode: number;
|
|
113
|
-
readonly message: string;
|
|
114
|
-
}
|
package/src/InternalConstants.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
// ###################################################################################################################################################
|
|
5
|
-
// Note: DON'T Export these const from the package as we are still targeting IE/ES5 this will export a mutable variables that someone could change ###
|
|
6
|
-
// ###################################################################################################################################################
|
|
7
|
-
|
|
8
|
-
// Generally you should only put values that are used more than 2 times and then only if not already exposed as a constant (such as SdkCoreNames)
|
|
9
|
-
// as when using "short" named values from here they will be will be minified smaller than the SdkCoreNames[eSdkCoreNames.xxxx] value.
|
|
10
|
-
|
|
11
|
-
export const STR_DURATION = "duration";
|
package/src/Offline.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createUniqueNamespace, eventOff, eventOn, getDocument, getNavigator, getWindow, isNullOrUndefined, isUndefined, mergeEvtNamespace
|
|
3
|
-
} from "@microsoft/applicationinsights-core-js";
|
|
4
|
-
|
|
5
|
-
export interface IOfflineListener {
|
|
6
|
-
isOnline: () => boolean;
|
|
7
|
-
isListening: () => boolean;
|
|
8
|
-
unload: () => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function _disableEvents(target: any, evtNamespace: string | string[]) {
|
|
12
|
-
eventOff(target, null, null, evtNamespace);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Create a new OfflineListener instance to monitor browser online / offline events
|
|
17
|
-
* @param parentEvtNamespace - The parent event namespace to append to any specific events for this instance
|
|
18
|
-
*/
|
|
19
|
-
export function createOfflineListener(parentEvtNamespace?: string | string[]): IOfflineListener {
|
|
20
|
-
let _document = getDocument();
|
|
21
|
-
var _navigator = getNavigator(); // Gets the window.navigator or workerNavigator depending on the global
|
|
22
|
-
let _isListening: boolean = false;
|
|
23
|
-
let _onlineStatus: boolean = true;
|
|
24
|
-
let _evtNamespace = mergeEvtNamespace(createUniqueNamespace("OfflineListener"), parentEvtNamespace);
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
if (_enableEvents(getWindow())) {
|
|
28
|
-
_isListening = true;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (_document) {
|
|
32
|
-
// Also attach to the document.body or document
|
|
33
|
-
let target:any = _document.body || _document;
|
|
34
|
-
|
|
35
|
-
if (target.ononline) {
|
|
36
|
-
if (_enableEvents(target)) {
|
|
37
|
-
_isListening = true;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (_isListening) {
|
|
43
|
-
// We are listening to events so lets set the current status rather than assuming we are online #1538
|
|
44
|
-
if (_navigator && !isNullOrUndefined(_navigator.onLine)) { // navigator.onLine is undefined in react-native
|
|
45
|
-
_onlineStatus = _navigator.onLine;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
} catch (e) {
|
|
49
|
-
// this makes react-native less angry
|
|
50
|
-
_isListening = false;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function _enableEvents(target: any): boolean {
|
|
54
|
-
let enabled = false;
|
|
55
|
-
if (target) {
|
|
56
|
-
enabled = eventOn(target, "online", _setOnline, _evtNamespace);
|
|
57
|
-
if (enabled) {
|
|
58
|
-
eventOn(target, "offline", _setOffline, _evtNamespace);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return enabled;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function _setOnline() {
|
|
66
|
-
_onlineStatus = true;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function _setOffline() {
|
|
70
|
-
_onlineStatus = false;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function _isOnline(): boolean {
|
|
74
|
-
let result = true;
|
|
75
|
-
if (_isListening) {
|
|
76
|
-
result = _onlineStatus
|
|
77
|
-
} else if (_navigator && !isNullOrUndefined(_navigator.onLine)) { // navigator.onLine is undefined in react-native
|
|
78
|
-
result = _navigator.onLine;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function _unload() {
|
|
85
|
-
let win = getWindow();
|
|
86
|
-
if (win && _isListening) {
|
|
87
|
-
_disableEvents(win, _evtNamespace);
|
|
88
|
-
|
|
89
|
-
if (_document) {
|
|
90
|
-
// Also attach to the document.body or document
|
|
91
|
-
let target:any = _document.body || _document;
|
|
92
|
-
if (!isUndefined(target.ononline)) {
|
|
93
|
-
_disableEvents(target, _evtNamespace);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
_isListening = false;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
isOnline: _isOnline,
|
|
103
|
-
isListening: () => _isListening,
|
|
104
|
-
unload: _unload
|
|
105
|
-
};
|
|
106
|
-
}
|