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