@microsoft/applicationinsights-dependencies-js 3.0.0-beta.2208-16 → 3.0.0-beta.2209-01
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/applicationinsights-dependencies-js.integrity.json +9 -9
- package/browser/applicationinsights-dependencies-js.js +149 -102
- package/browser/applicationinsights-dependencies-js.js.map +1 -1
- package/browser/applicationinsights-dependencies-js.min.js +2 -2
- package/browser/applicationinsights-dependencies-js.min.js.map +1 -1
- package/dist/applicationinsights-dependencies-js.api.json +667 -30
- package/dist/applicationinsights-dependencies-js.api.md +63 -9
- package/dist/applicationinsights-dependencies-js.d.ts +73 -8
- package/dist/applicationinsights-dependencies-js.js +149 -102
- package/dist/applicationinsights-dependencies-js.js.map +1 -1
- package/dist/applicationinsights-dependencies-js.min.js +2 -2
- package/dist/applicationinsights-dependencies-js.min.js.map +1 -1
- package/dist/applicationinsights-dependencies-js.rollup.d.ts +75 -10
- package/dist-esm/DependencyInitializer.js +6 -0
- package/dist-esm/DependencyInitializer.js.map +1 -0
- package/dist-esm/DependencyListener.js +1 -1
- package/dist-esm/InternalConstants.js +1 -1
- package/dist-esm/__DynamicConstants.js +6 -6
- package/dist-esm/__DynamicConstants.js.map +1 -1
- package/dist-esm/ajax.js +153 -98
- package/dist-esm/ajax.js.map +1 -1
- package/dist-esm/ajaxRecord.js +1 -1
- package/dist-esm/ajaxUtils.js +1 -1
- package/dist-esm/applicationinsights-dependencies-js.js +1 -1
- package/package.json +3 -3
- package/src/DependencyInitializer.ts +44 -0
- package/src/DependencyListener.ts +13 -3
- package/src/__DynamicConstants.ts +5 -5
- package/src/ajax.ts +183 -106
- package/src/ajaxRecord.ts +5 -0
- package/src/applicationinsights-dependencies-js.ts +5 -1
- package/types/DependencyInitializer.d.ts +41 -0
- package/types/DependencyListener.d.ts +14 -3
- package/types/__DynamicConstants.d.ts +4 -4
- package/types/ajax.d.ts +18 -5
- package/types/ajaxRecord.d.ts +6 -0
- package/types/applicationinsights-dependencies-js.d.ts +2 -0
package/src/ajax.ts
CHANGED
|
@@ -15,8 +15,9 @@ import {
|
|
|
15
15
|
eLoggingSeverity, eventOn, generateW3CId, getExceptionName, getGlobal, getIEVersion, getLocation, getPerformance, isFunction,
|
|
16
16
|
isNullOrUndefined, isString, isXhrSupported, mergeEvtNamespace, objForEachKey, strPrototype, strTrim
|
|
17
17
|
} from "@microsoft/applicationinsights-core-js";
|
|
18
|
+
import { DependencyInitializerFunction, IDependencyInitializerDetails, IDependencyInitializerHandler } from "./DependencyInitializer";
|
|
18
19
|
import {
|
|
19
|
-
DependencyListenerFunction, IDependencyListenerContainer, IDependencyListenerDetails, IDependencyListenerHandler
|
|
20
|
+
DependencyListenerFunction, IDependencyHandler, IDependencyListenerContainer, IDependencyListenerDetails, IDependencyListenerHandler
|
|
20
21
|
} from "./DependencyListener";
|
|
21
22
|
import { IAjaxRecordResponse, ajaxRecord } from "./ajaxRecord";
|
|
22
23
|
|
|
@@ -25,12 +26,20 @@ const strDiagLog = "diagLog";
|
|
|
25
26
|
const strAjaxData = "ajaxData";
|
|
26
27
|
const strFetch = "fetch";
|
|
27
28
|
|
|
29
|
+
const ERROR_HEADER = "Failed to monitor XMLHttpRequest";
|
|
30
|
+
const ERROR_PREFIX = ", monitoring data for this ajax call ";
|
|
31
|
+
const ERROR_POSTFIX = ERROR_PREFIX + "may be incorrect.";
|
|
32
|
+
const ERROR_NOT_SENT = ERROR_PREFIX + "won't be sent.";
|
|
33
|
+
const CORRELATION_HEADER_ERROR = "Failed to get Request-Context correlation header as it may be not included in the response or not accessible.";
|
|
34
|
+
const CUSTOM_REQUEST_CONTEXT_ERROR = "Failed to add custom defined request context as configured call back may missing a null check.";
|
|
35
|
+
const FAILED_TO_CALCULATE_DURATION_ERROR = "Failed to calculate the duration of the ";
|
|
36
|
+
|
|
28
37
|
// Using a global value so that to handle same iKey with multiple app insights instances (mostly for testing)
|
|
29
38
|
let _markCount: number = 0;
|
|
30
39
|
|
|
31
|
-
interface
|
|
40
|
+
interface _IInternalDependencyHandler<F> {
|
|
32
41
|
id: number;
|
|
33
|
-
fn:
|
|
42
|
+
fn: F;
|
|
34
43
|
}
|
|
35
44
|
|
|
36
45
|
/** @Ignore */
|
|
@@ -95,9 +104,7 @@ function _supportsAjaxMonitoring(ajaxMonitorInstance:AjaxMonitor): boolean {
|
|
|
95
104
|
function _getFailedAjaxDiagnosticsMessage(xhr: XMLHttpRequestInstrumented): string {
|
|
96
105
|
let result = "";
|
|
97
106
|
try {
|
|
98
|
-
if (
|
|
99
|
-
!isNullOrUndefined(xhr[strAjaxData]) &&
|
|
100
|
-
!isNullOrUndefined(xhr[strAjaxData].requestUrl)) {
|
|
107
|
+
if (xhr && xhr[strAjaxData] && xhr[strAjaxData].requestUrl) {
|
|
101
108
|
result += "(url: '" + xhr[strAjaxData].requestUrl + "')";
|
|
102
109
|
}
|
|
103
110
|
} catch (e) {
|
|
@@ -139,7 +146,47 @@ function _indexOf(value:string, match:string):number {
|
|
|
139
146
|
return -1;
|
|
140
147
|
}
|
|
141
148
|
|
|
142
|
-
function
|
|
149
|
+
function _addHandler<F>(container: _IInternalDependencyHandler<F>[], id: number, theFunc: F): IDependencyHandler {
|
|
150
|
+
let theHandler: _IInternalDependencyHandler<F> = {
|
|
151
|
+
id: id,
|
|
152
|
+
fn: theFunc
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
container.push(theHandler);
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
remove: () => {
|
|
159
|
+
arrForEach(container, (initializer, idx) => {
|
|
160
|
+
if (initializer.id === theHandler.id) {
|
|
161
|
+
container.splice(idx, 1);
|
|
162
|
+
return -1;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function _processDependencyContainer<F extends Function, D>(core: IAppInsightsCore, container: _IInternalDependencyHandler<F>[], details: D, message: string) {
|
|
170
|
+
let result = true;
|
|
171
|
+
arrForEach(container, (theFunc, idx) => {
|
|
172
|
+
try {
|
|
173
|
+
if (theFunc.fn.call(null, details) === false) {
|
|
174
|
+
result = false;
|
|
175
|
+
}
|
|
176
|
+
} catch (e) {
|
|
177
|
+
_throwInternal(
|
|
178
|
+
core && core.logger,
|
|
179
|
+
eLoggingSeverity.CRITICAL,
|
|
180
|
+
_eInternalMessageId.TelemetryInitializerFailed,
|
|
181
|
+
"Dependency " + message + " [#" + idx + "] failed: " + getExceptionName(e),
|
|
182
|
+
{ exception: dumpObj(e) }, true);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function _processDependencyListeners(listeners: _IInternalDependencyHandler<DependencyListenerFunction>[], core: IAppInsightsCore, ajaxData: ajaxRecord, xhr: XMLHttpRequest, input?: Request | string, init?: RequestInit): void {
|
|
143
190
|
var initializersCount = listeners.length;
|
|
144
191
|
if (initializersCount > 0) {
|
|
145
192
|
let details: IDependencyListenerDetails = {
|
|
@@ -149,29 +196,16 @@ function _processDependencyListeners(listeners: _IInternalDependencyListenerHand
|
|
|
149
196
|
init: init,
|
|
150
197
|
traceId: ajaxData.traceID,
|
|
151
198
|
spanId: ajaxData.spanID,
|
|
152
|
-
traceFlags: ajaxData.traceFlags
|
|
199
|
+
traceFlags: ajaxData.traceFlags,
|
|
200
|
+
context: ajaxData.context || {}
|
|
153
201
|
};
|
|
154
202
|
|
|
155
|
-
|
|
156
|
-
var dependencyListener = listeners[i];
|
|
157
|
-
if (dependencyListener && dependencyListener.fn) {
|
|
158
|
-
try {
|
|
159
|
-
dependencyListener.fn.call(null, details);
|
|
160
|
-
} catch (e) {
|
|
161
|
-
let core = details.core;
|
|
162
|
-
_throwInternal(
|
|
163
|
-
core && core.logger,
|
|
164
|
-
eLoggingSeverity.CRITICAL,
|
|
165
|
-
_eInternalMessageId.TelemetryInitializerFailed,
|
|
166
|
-
"Dependency listener [#" + i + "] failed: " + getExceptionName(e),
|
|
167
|
-
{ exception: dumpObj(e) }, true);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
203
|
+
_processDependencyContainer(core, listeners, details, "listener");
|
|
171
204
|
|
|
172
205
|
ajaxData.traceID = details.traceId;
|
|
173
206
|
ajaxData.spanID = details.spanId;
|
|
174
207
|
ajaxData.traceFlags = details.traceFlags;
|
|
208
|
+
ajaxData.context = details.context;
|
|
175
209
|
}
|
|
176
210
|
}
|
|
177
211
|
|
|
@@ -179,13 +213,20 @@ export interface XMLHttpRequestInstrumented extends XMLHttpRequest {
|
|
|
179
213
|
ajaxData: ajaxRecord;
|
|
180
214
|
}
|
|
181
215
|
|
|
216
|
+
const BLOB_CORE = "*.blob.core.";
|
|
217
|
+
|
|
182
218
|
export const DfltAjaxCorrelationHeaderExDomains = deepFreeze([
|
|
183
|
-
"
|
|
184
|
-
"
|
|
185
|
-
"
|
|
186
|
-
"
|
|
219
|
+
BLOB_CORE + "windows.net",
|
|
220
|
+
BLOB_CORE + "chinacloudapi.cn",
|
|
221
|
+
BLOB_CORE + "cloudapi.de",
|
|
222
|
+
BLOB_CORE + "usgovcloudapi.net"
|
|
187
223
|
]);
|
|
188
224
|
|
|
225
|
+
|
|
226
|
+
const _internalExcludeEndpoints = [
|
|
227
|
+
/https:\/\/[^\/]*(\.pipe\.aria|aria\.pipe|events\.data|collector\.azure)\.[^\/]+\/(OneCollector\/1|Collector\/3)\.0/i
|
|
228
|
+
];
|
|
229
|
+
|
|
189
230
|
export interface IDependenciesPlugin extends IDependencyListenerContainer {
|
|
190
231
|
/**
|
|
191
232
|
* Logs dependency call
|
|
@@ -198,46 +239,51 @@ export interface IInstrumentationRequirements extends IDependenciesPlugin {
|
|
|
198
239
|
includeCorrelationHeaders: (ajaxData: ajaxRecord, input?: Request | string, init?: RequestInit, xhr?: XMLHttpRequestInstrumented) => any;
|
|
199
240
|
}
|
|
200
241
|
|
|
201
|
-
|
|
242
|
+
function _getDefaultConfig(): ICorrelationConfig {
|
|
243
|
+
const config: ICorrelationConfig = {
|
|
244
|
+
maxAjaxCallsPerView: 500,
|
|
245
|
+
disableAjaxTracking: false,
|
|
246
|
+
disableFetchTracking: false,
|
|
247
|
+
excludeRequestFromAutoTrackingPatterns: undefined,
|
|
248
|
+
disableCorrelationHeaders: false,
|
|
249
|
+
distributedTracingMode: eDistributedTracingModes.AI_AND_W3C,
|
|
250
|
+
correlationHeaderExcludedDomains: DfltAjaxCorrelationHeaderExDomains,
|
|
251
|
+
correlationHeaderDomains: undefined,
|
|
252
|
+
correlationHeaderExcludePatterns: undefined,
|
|
253
|
+
appId: undefined,
|
|
254
|
+
enableCorsCorrelation: false,
|
|
255
|
+
enableRequestHeaderTracking: false,
|
|
256
|
+
enableResponseHeaderTracking: false,
|
|
257
|
+
enableAjaxErrorStatusText: false,
|
|
258
|
+
enableAjaxPerfTracking: false,
|
|
259
|
+
maxAjaxPerfLookupAttempts: 3,
|
|
260
|
+
ajaxPerfLookupDelay: 25,
|
|
261
|
+
ignoreHeaders:[
|
|
262
|
+
"Authorization",
|
|
263
|
+
"X-API-Key",
|
|
264
|
+
"WWW-Authenticate"],
|
|
265
|
+
addRequestContext: undefined,
|
|
266
|
+
addIntEndpoints: true
|
|
267
|
+
}
|
|
268
|
+
return config;
|
|
269
|
+
}
|
|
202
270
|
|
|
203
|
-
|
|
271
|
+
function _getEmptyConfig(): ICorrelationConfig {
|
|
272
|
+
let emptyConfig = _getDefaultConfig();
|
|
273
|
+
objForEachKey(emptyConfig, (value) => {
|
|
274
|
+
emptyConfig[value] = undefined;
|
|
275
|
+
});
|
|
204
276
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
maxAjaxCallsPerView: 500,
|
|
208
|
-
disableAjaxTracking: false,
|
|
209
|
-
disableFetchTracking: false,
|
|
210
|
-
excludeRequestFromAutoTrackingPatterns: undefined,
|
|
211
|
-
disableCorrelationHeaders: false,
|
|
212
|
-
distributedTracingMode: eDistributedTracingModes.AI_AND_W3C,
|
|
213
|
-
correlationHeaderExcludedDomains: DfltAjaxCorrelationHeaderExDomains,
|
|
214
|
-
correlationHeaderDomains: undefined,
|
|
215
|
-
correlationHeaderExcludePatterns: undefined,
|
|
216
|
-
appId: undefined,
|
|
217
|
-
enableCorsCorrelation: false,
|
|
218
|
-
enableRequestHeaderTracking: false,
|
|
219
|
-
enableResponseHeaderTracking: false,
|
|
220
|
-
enableAjaxErrorStatusText: false,
|
|
221
|
-
enableAjaxPerfTracking: false,
|
|
222
|
-
maxAjaxPerfLookupAttempts: 3,
|
|
223
|
-
ajaxPerfLookupDelay: 25,
|
|
224
|
-
ignoreHeaders:[
|
|
225
|
-
"Authorization",
|
|
226
|
-
"X-API-Key",
|
|
227
|
-
"WWW-Authenticate"],
|
|
228
|
-
addRequestContext: undefined
|
|
229
|
-
}
|
|
230
|
-
return config;
|
|
231
|
-
}
|
|
277
|
+
return emptyConfig;
|
|
278
|
+
}
|
|
232
279
|
|
|
233
|
-
|
|
234
|
-
let emptyConfig = this.getDefaultConfig();
|
|
235
|
-
objForEachKey(emptyConfig, (value) => {
|
|
236
|
-
emptyConfig[value] = undefined;
|
|
237
|
-
});
|
|
280
|
+
export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlugin, IInstrumentationRequirements, IDependencyListenerContainer {
|
|
238
281
|
|
|
239
|
-
|
|
240
|
-
|
|
282
|
+
public static identifier: string = "AjaxDependencyPlugin";
|
|
283
|
+
|
|
284
|
+
public static getDefaultConfig = _getDefaultConfig;
|
|
285
|
+
|
|
286
|
+
public static getEmptyConfig = _getEmptyConfig;
|
|
241
287
|
|
|
242
288
|
public identifier: string = AjaxMonitor.identifier;
|
|
243
289
|
|
|
@@ -262,11 +308,12 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
262
308
|
let _disabledUrls: any;
|
|
263
309
|
let _disableAjaxTracking: boolean;
|
|
264
310
|
let _disableFetchTracking: boolean;
|
|
265
|
-
let _excludeRequestFromAutoTrackingPatterns: string
|
|
311
|
+
let _excludeRequestFromAutoTrackingPatterns: (string | RegExp)[];
|
|
266
312
|
let _addRequestContext: (requestContext?: IRequestContext) => ICustomProperties;
|
|
267
313
|
let _evtNamespace: string | string[];
|
|
268
|
-
let
|
|
269
|
-
let _dependencyListeners:
|
|
314
|
+
let _dependencyHandlerId: number;
|
|
315
|
+
let _dependencyListeners: _IInternalDependencyHandler<DependencyListenerFunction>[];
|
|
316
|
+
let _dependencyInitializers: _IInternalDependencyHandler<DependencyInitializerFunction>[];
|
|
270
317
|
|
|
271
318
|
dynamicProto(AjaxMonitor, this, (_self, _base) => {
|
|
272
319
|
let _addHook = _base._addHook;
|
|
@@ -292,7 +339,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
292
339
|
};
|
|
293
340
|
|
|
294
341
|
_self.trackDependencyData = (dependency: IDependencyTelemetry, properties?: { [key: string]: any }) => {
|
|
295
|
-
_self.
|
|
342
|
+
_reportDependencyInternal(_dependencyInitializers, _self.core, null, dependency, properties);
|
|
296
343
|
}
|
|
297
344
|
|
|
298
345
|
_self.includeCorrelationHeaders = (ajaxData: ajaxRecord, input?: Request | string, init?: RequestInit, xhr?: XMLHttpRequestInstrumented): any => {
|
|
@@ -412,25 +459,11 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
412
459
|
}
|
|
413
460
|
|
|
414
461
|
_self.addDependencyListener = (dependencyListener: DependencyListenerFunction): IDependencyListenerHandler => {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
_dependencyListeners.push(theInitializer);
|
|
421
|
-
|
|
422
|
-
let handler: IDependencyListenerHandler = {
|
|
423
|
-
remove: () => {
|
|
424
|
-
arrForEach(_dependencyListeners, (initializer, idx) => {
|
|
425
|
-
if (initializer.id === theInitializer.id) {
|
|
426
|
-
_dependencyListeners.splice(idx, 1);
|
|
427
|
-
return -1;
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
return handler;
|
|
462
|
+
return _addHandler(_dependencyListeners, _dependencyHandlerId++, dependencyListener);
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
_self.addDependencyInitializer = (dependencyInitializer: DependencyInitializerFunction): IDependencyInitializerHandler => {
|
|
466
|
+
return _addHandler(_dependencyInitializers, _dependencyHandlerId++, dependencyInitializer);
|
|
434
467
|
};
|
|
435
468
|
|
|
436
469
|
function _initDefaults() {
|
|
@@ -456,16 +489,17 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
456
489
|
_excludeRequestFromAutoTrackingPatterns = null;
|
|
457
490
|
_addRequestContext = null;
|
|
458
491
|
_evtNamespace = null;
|
|
459
|
-
|
|
492
|
+
_dependencyHandlerId = 0;
|
|
460
493
|
_dependencyListeners = [];
|
|
494
|
+
_dependencyInitializers = [];
|
|
461
495
|
}
|
|
462
496
|
|
|
463
497
|
function _populateDefaults(config: IConfiguration) {
|
|
464
498
|
let ctx = createProcessTelemetryContext(null, config, _self.core);
|
|
465
499
|
|
|
466
500
|
// Reset to the empty config
|
|
467
|
-
_config =
|
|
468
|
-
const defaultConfig =
|
|
501
|
+
_config = _getEmptyConfig();
|
|
502
|
+
const defaultConfig = _getDefaultConfig();
|
|
469
503
|
objForEachKey(defaultConfig, (field, value) => {
|
|
470
504
|
_config[field] = ctx.getConfig(AjaxMonitor.identifier, field, value);
|
|
471
505
|
});
|
|
@@ -476,9 +510,9 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
476
510
|
_enableAjaxPerfTracking = _config.enableAjaxPerfTracking;
|
|
477
511
|
_maxAjaxCallsPerView = _config.maxAjaxCallsPerView;
|
|
478
512
|
_enableResponseHeaderTracking = _config.enableResponseHeaderTracking;
|
|
479
|
-
_excludeRequestFromAutoTrackingPatterns = _config.excludeRequestFromAutoTrackingPatterns;
|
|
513
|
+
_excludeRequestFromAutoTrackingPatterns = [].concat(_config.excludeRequestFromAutoTrackingPatterns || [], _config.addIntEndpoints !== false ? _internalExcludeEndpoints : []);
|
|
480
514
|
_addRequestContext = _config.addRequestContext;
|
|
481
|
-
|
|
515
|
+
|
|
482
516
|
_isUsingAIHeaders = distributedTracingMode === eDistributedTracingModes.AI || distributedTracingMode === eDistributedTracingModes.AI_AND_W3C;
|
|
483
517
|
_isUsingW3CHeaders = distributedTracingMode === eDistributedTracingModes.AI_AND_W3C || distributedTracingMode === eDistributedTracingModes.W3C;
|
|
484
518
|
|
|
@@ -582,7 +616,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
582
616
|
},
|
|
583
617
|
// Create an error callback to report any hook errors
|
|
584
618
|
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxOpen,
|
|
585
|
-
"Failed to monitor Window.fetch
|
|
619
|
+
"Failed to monitor Window.fetch" + ERROR_POSTFIX)
|
|
586
620
|
}));
|
|
587
621
|
|
|
588
622
|
_fetchInitialized = true;
|
|
@@ -634,7 +668,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
634
668
|
}
|
|
635
669
|
},
|
|
636
670
|
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxOpen,
|
|
637
|
-
|
|
671
|
+
ERROR_HEADER + ".open" + ERROR_POSTFIX)
|
|
638
672
|
});
|
|
639
673
|
|
|
640
674
|
// Instrument send
|
|
@@ -653,7 +687,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
653
687
|
}
|
|
654
688
|
},
|
|
655
689
|
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxSend,
|
|
656
|
-
|
|
690
|
+
ERROR_HEADER + ERROR_POSTFIX)
|
|
657
691
|
});
|
|
658
692
|
|
|
659
693
|
// Instrument abort
|
|
@@ -670,7 +704,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
670
704
|
}
|
|
671
705
|
},
|
|
672
706
|
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxAbort,
|
|
673
|
-
|
|
707
|
+
ERROR_HEADER + ".abort" + ERROR_POSTFIX)
|
|
674
708
|
});
|
|
675
709
|
|
|
676
710
|
// Instrument setRequestHeader
|
|
@@ -685,7 +719,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
685
719
|
}
|
|
686
720
|
},
|
|
687
721
|
hkErr: _createErrorCallbackFunc(_self, _eInternalMessageId.FailedMonitorAjaxSetRequestHeader,
|
|
688
|
-
|
|
722
|
+
ERROR_HEADER + ".setRequestHeader" + ERROR_POSTFIX)
|
|
689
723
|
});
|
|
690
724
|
|
|
691
725
|
_xhrInitialized = true;
|
|
@@ -813,7 +847,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
813
847
|
if (!exceptionText || _indexOf(exceptionText.toLowerCase(), "c00c023f") === -1) {
|
|
814
848
|
_throwInternalCritical(_self,
|
|
815
849
|
_eInternalMessageId.FailedMonitorAjaxRSC,
|
|
816
|
-
|
|
850
|
+
ERROR_HEADER + " 'readystatechange' event handler" + ERROR_POSTFIX,
|
|
817
851
|
{
|
|
818
852
|
ajaxDiagnosticsMessage: _getFailedAjaxDiagnosticsMessage(xhr),
|
|
819
853
|
exception: exceptionText
|
|
@@ -851,7 +885,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
851
885
|
|
|
852
886
|
_throwInternalWarning(_self,
|
|
853
887
|
_eInternalMessageId.FailedMonitorAjaxDur,
|
|
854
|
-
|
|
888
|
+
FAILED_TO_CALCULATE_DURATION_ERROR + "ajax call" + ERROR_NOT_SENT,
|
|
855
889
|
errorProps
|
|
856
890
|
);
|
|
857
891
|
}
|
|
@@ -899,14 +933,16 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
899
933
|
} catch (e) {
|
|
900
934
|
_throwInternalWarning(_self,
|
|
901
935
|
_eInternalMessageId.FailedAddingCustomDefinedRequestContext,
|
|
902
|
-
|
|
936
|
+
CUSTOM_REQUEST_CONTEXT_ERROR);
|
|
903
937
|
}
|
|
904
938
|
|
|
905
939
|
if (dependency) {
|
|
906
940
|
if (properties !== undefined) {
|
|
907
941
|
dependency.properties = {...dependency.properties, ...properties};
|
|
908
942
|
}
|
|
909
|
-
|
|
943
|
+
|
|
944
|
+
let sysProperties = ajaxData.getPartAProps();
|
|
945
|
+
_reportDependencyInternal(_dependencyInitializers, _self.core, ajaxData, dependency, null, sysProperties);
|
|
910
946
|
} else {
|
|
911
947
|
_reportXhrError(null, {
|
|
912
948
|
requestSentTime: ajaxData.requestSentTime,
|
|
@@ -939,7 +975,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
939
975
|
} catch (e) {
|
|
940
976
|
_throwInternalWarning(_self,
|
|
941
977
|
_eInternalMessageId.FailedMonitorAjaxGetCorrelationHeader,
|
|
942
|
-
|
|
978
|
+
CORRELATION_HEADER_ERROR,
|
|
943
979
|
{
|
|
944
980
|
ajaxDiagnosticsMessage: _getFailedAjaxDiagnosticsMessage(xhr),
|
|
945
981
|
exception: dumpObj(e)
|
|
@@ -1101,7 +1137,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
1101
1137
|
|
|
1102
1138
|
_throwInternalWarning(_self,
|
|
1103
1139
|
msgId,
|
|
1104
|
-
|
|
1140
|
+
FAILED_TO_CALCULATE_DURATION_ERROR + "fetch call" + ERROR_NOT_SENT,
|
|
1105
1141
|
errorProps
|
|
1106
1142
|
);
|
|
1107
1143
|
}
|
|
@@ -1119,14 +1155,16 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
1119
1155
|
} catch (e) {
|
|
1120
1156
|
_throwInternalWarning(_self,
|
|
1121
1157
|
_eInternalMessageId.FailedAddingCustomDefinedRequestContext,
|
|
1122
|
-
|
|
1158
|
+
CUSTOM_REQUEST_CONTEXT_ERROR);
|
|
1123
1159
|
}
|
|
1124
1160
|
|
|
1125
1161
|
if (dependency) {
|
|
1126
1162
|
if (properties !== undefined) {
|
|
1127
1163
|
dependency.properties = {...dependency.properties, ...properties};
|
|
1128
1164
|
}
|
|
1129
|
-
|
|
1165
|
+
|
|
1166
|
+
let sysProperties = ajaxData.getPartAProps();
|
|
1167
|
+
_reportDependencyInternal(_dependencyInitializers, _self.core, ajaxData, dependency, null, sysProperties);
|
|
1130
1168
|
} else {
|
|
1131
1169
|
_reportFetchError(_eInternalMessageId.FailedMonitorAjaxDur, null,
|
|
1132
1170
|
{
|
|
@@ -1147,7 +1185,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
1147
1185
|
} catch (e) {
|
|
1148
1186
|
_throwInternalWarning(_self,
|
|
1149
1187
|
_eInternalMessageId.FailedMonitorAjaxGetCorrelationHeader,
|
|
1150
|
-
|
|
1188
|
+
CORRELATION_HEADER_ERROR,
|
|
1151
1189
|
{
|
|
1152
1190
|
fetchDiagnosticsMessage: _getFailedFetchDiagnosticsMessage(response),
|
|
1153
1191
|
exception: dumpObj(e)
|
|
@@ -1155,6 +1193,33 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
1155
1193
|
}
|
|
1156
1194
|
}
|
|
1157
1195
|
}
|
|
1196
|
+
|
|
1197
|
+
function _reportDependencyInternal(
|
|
1198
|
+
initializers: _IInternalDependencyHandler<DependencyInitializerFunction>[],
|
|
1199
|
+
core: IAppInsightsCore,
|
|
1200
|
+
ajaxData: ajaxRecord,
|
|
1201
|
+
dependency: IDependencyTelemetry,
|
|
1202
|
+
properties?: { [key: string]: any },
|
|
1203
|
+
systemProperties?: { [key: string]: any }
|
|
1204
|
+
) {
|
|
1205
|
+
|
|
1206
|
+
let result = true;
|
|
1207
|
+
var initializersCount = initializers.length;
|
|
1208
|
+
if (initializersCount > 0) {
|
|
1209
|
+
let details: IDependencyInitializerDetails = {
|
|
1210
|
+
item: dependency,
|
|
1211
|
+
properties: properties,
|
|
1212
|
+
sysProperties: systemProperties,
|
|
1213
|
+
context: ajaxData ? ajaxData.context : null
|
|
1214
|
+
};
|
|
1215
|
+
|
|
1216
|
+
result = _processDependencyContainer(core, initializers, details, "initializer");
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
if (result) {
|
|
1220
|
+
_self.trackDependencyDataInternal(dependency, properties, systemProperties);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1158
1223
|
});
|
|
1159
1224
|
}
|
|
1160
1225
|
|
|
@@ -1189,6 +1254,18 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
|
|
|
1189
1254
|
return null;
|
|
1190
1255
|
}
|
|
1191
1256
|
|
|
1257
|
+
/**
|
|
1258
|
+
* Add an dependency telemetry initializer callback function to allow populating additional properties or drop the request.
|
|
1259
|
+
* It is called after the dependency call has completed and any available performance details are available. A dependency
|
|
1260
|
+
* initializer is similar to the TelemetryInitializer function but it allows you to block the reporting of the dependency
|
|
1261
|
+
* request so that it doesn't count against the `maxAjaxCallsPerView`.
|
|
1262
|
+
* @param dependencyInitializer - The Dependency Telemetry Initializer function
|
|
1263
|
+
* @returns - A IDependencyInitializerHandler to enable the initializer to be removed
|
|
1264
|
+
*/
|
|
1265
|
+
public addDependencyInitializer(dependencyInitializer: DependencyInitializerFunction): IDependencyInitializerHandler {
|
|
1266
|
+
return null;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1192
1269
|
/**
|
|
1193
1270
|
* Protected function to allow sub classes the chance to add additional properties to the dependency event
|
|
1194
1271
|
* before it's sent. This function calls track, so sub-classes must call this function after they have
|
package/src/ajaxRecord.ts
CHANGED
|
@@ -263,6 +263,11 @@ export class ajaxRecord {
|
|
|
263
263
|
*/
|
|
264
264
|
public eventTraceCtx: ITraceCtx;
|
|
265
265
|
|
|
266
|
+
/**
|
|
267
|
+
* The listener assigned context values that will be passed to any dependency initializer
|
|
268
|
+
*/
|
|
269
|
+
public context?: { [key: string]: any };
|
|
270
|
+
|
|
266
271
|
constructor(traceId: string, spanId: string, logger: IDiagnosticLogger, traceCtx?: IDistributedTraceContext) {
|
|
267
272
|
let self = this;
|
|
268
273
|
let _logger: IDiagnosticLogger = logger;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
2
|
// Licensed under the MIT License.
|
|
3
3
|
|
|
4
|
-
export {
|
|
4
|
+
export {
|
|
5
|
+
AjaxMonitor as AjaxPlugin, IDependenciesPlugin, XMLHttpRequestInstrumented, IInstrumentationRequirements, DfltAjaxCorrelationHeaderExDomains
|
|
6
|
+
} from "./ajax";
|
|
5
7
|
export { ajaxRecord } from "./ajaxRecord";
|
|
8
|
+
export { IDependencyHandler, IDependencyListenerHandler, IDependencyListenerDetails, DependencyListenerFunction } from "./DependencyListener";
|
|
9
|
+
export { IDependencyInitializerHandler, IDependencyInitializerDetails, DependencyInitializerFunction } from "./DependencyInitializer";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { IDependencyTelemetry } from "@microsoft/applicationinsights-common";
|
|
2
|
+
import { IDependencyHandler } from "./DependencyListener";
|
|
3
|
+
export interface IDependencyInitializerDetails {
|
|
4
|
+
/**
|
|
5
|
+
* The DependencyTelemetry event that will be passed to the `trackDependencyDataInternal` function.
|
|
6
|
+
*/
|
|
7
|
+
item: IDependencyTelemetry;
|
|
8
|
+
/**
|
|
9
|
+
* Additional properties to be added to the event
|
|
10
|
+
*/
|
|
11
|
+
properties?: {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Additional system properties to be added to the event.
|
|
16
|
+
*/
|
|
17
|
+
sysProperties?: {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The context that the application can assigned via the dependency listener(s)
|
|
22
|
+
*/
|
|
23
|
+
context?: {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The initializer function that will be called, if it returns false the event will be dropped and not reported
|
|
29
|
+
* or counted against the `maxAjaxCallsPerView`.
|
|
30
|
+
*/
|
|
31
|
+
export declare type DependencyInitializerFunction = (item: IDependencyInitializerDetails) => boolean | void;
|
|
32
|
+
export interface IDependencyInitializerHandler extends IDependencyHandler {
|
|
33
|
+
}
|
|
34
|
+
export interface IDependencyInitializerContainer {
|
|
35
|
+
/**
|
|
36
|
+
* Add a dependency telemetry processor to decorate or drop telemetry events.
|
|
37
|
+
* @param dependencyInitializer - The Telemetry Initializer function
|
|
38
|
+
* @returns - A ITelemetryInitializerHandler to enable the initializer to be removed
|
|
39
|
+
*/
|
|
40
|
+
addDependencyInitializer(dependencyInitializer: DependencyInitializerFunction): IDependencyInitializerHandler | void;
|
|
41
|
+
}
|
|
@@ -33,14 +33,25 @@ export interface IDependencyListenerDetails {
|
|
|
33
33
|
spanId?: string;
|
|
34
34
|
/**
|
|
35
35
|
* An integer representation of the W3C TraceContext trace-flags.
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
* https://www.w3.org/TR/trace-context/#trace-flags
|
|
37
|
+
*/
|
|
38
38
|
traceFlags?: number;
|
|
39
|
+
/**
|
|
40
|
+
* [Optional] Context that the application can assign that will also be passed to any dependency initializer
|
|
41
|
+
*/
|
|
42
|
+
context?: {
|
|
43
|
+
[key: string]: any;
|
|
44
|
+
};
|
|
39
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* The function that will get called when the ajax request is about to occur.
|
|
48
|
+
*/
|
|
40
49
|
export declare type DependencyListenerFunction = (dependencyDetails: IDependencyListenerDetails) => void;
|
|
41
|
-
export interface
|
|
50
|
+
export interface IDependencyHandler {
|
|
42
51
|
remove(): void;
|
|
43
52
|
}
|
|
53
|
+
export interface IDependencyListenerHandler extends IDependencyHandler {
|
|
54
|
+
}
|
|
44
55
|
export interface IDependencyListenerContainer {
|
|
45
56
|
/**
|
|
46
57
|
* Add an ajax listener which is called just prior to the request being sent and before the correlation headers are added, to allow you
|
|
@@ -4,17 +4,17 @@ export declare const _DYN_LENGTH = "length";
|
|
|
4
4
|
export declare const _DYN_TRACE_ID = "traceID";
|
|
5
5
|
export declare const _DYN_SPAN_ID = "spanID";
|
|
6
6
|
export declare const _DYN_TRACE_FLAGS = "traceFlags";
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const _DYN_CONTEXT = "context";
|
|
8
8
|
export declare const _DYN_TRACE_ID0 = "traceId";
|
|
9
9
|
export declare const _DYN_SPAN_ID1 = "spanId";
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const _DYN_INCLUDE_CORRELATION_3 = "includeCorrelationHeaders";
|
|
10
|
+
export declare const _DYN_CORE = "core";
|
|
11
|
+
export declare const _DYN_INCLUDE_CORRELATION_2 = "includeCorrelationHeaders";
|
|
13
12
|
export declare const _DYN_GET_ABSOLUTE_URL = "getAbsoluteUrl";
|
|
14
13
|
export declare const _DYN_HEADERS = "headers";
|
|
15
14
|
export declare const _DYN_REQUEST_HEADERS = "requestHeaders";
|
|
16
15
|
export declare const _DYN_APP_ID = "appId";
|
|
17
16
|
export declare const _DYN_SET_REQUEST_HEADER = "setRequestHeader";
|
|
17
|
+
export declare const _DYN_TRACK_DEPENDENCY_DAT3 = "trackDependencyDataInternal";
|
|
18
18
|
export declare const _DYN_DISTRIBUTED_TRACING_4 = "distributedTracingMode";
|
|
19
19
|
export declare const _DYN_START_TIME = "startTime";
|
|
20
20
|
export declare const _DYN_TO_LOWER_CASE = "toLowerCase";
|