@microsoft/applicationinsights-dependencies-js 2.8.10-nightly.2301-28 → 2.8.10-nightly.2302-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.
Files changed (34) hide show
  1. package/browser/applicationinsights-dependencies-js.integrity.json +9 -9
  2. package/browser/applicationinsights-dependencies-js.js +33 -24
  3. package/browser/applicationinsights-dependencies-js.js.map +1 -1
  4. package/browser/applicationinsights-dependencies-js.min.js +2 -2
  5. package/browser/applicationinsights-dependencies-js.min.js.map +1 -1
  6. package/dist/applicationinsights-dependencies-js.api.json +137 -36
  7. package/dist/applicationinsights-dependencies-js.api.md +2 -0
  8. package/dist/applicationinsights-dependencies-js.d.ts +11 -1
  9. package/dist/applicationinsights-dependencies-js.js +33 -24
  10. package/dist/applicationinsights-dependencies-js.js.map +1 -1
  11. package/dist/applicationinsights-dependencies-js.min.js +2 -2
  12. package/dist/applicationinsights-dependencies-js.min.js.map +1 -1
  13. package/dist/applicationinsights-dependencies-js.rollup.d.ts +11 -1
  14. package/dist-esm/DependencyInitializer.js +1 -1
  15. package/dist-esm/DependencyListener.js +1 -1
  16. package/dist-esm/InternalConstants.js +1 -1
  17. package/dist-esm/__DynamicConstants.js +5 -4
  18. package/dist-esm/__DynamicConstants.js.map +1 -1
  19. package/dist-esm/ajax.js +16 -14
  20. package/dist-esm/ajax.js.map +1 -1
  21. package/dist-esm/ajaxRecord.js +18 -12
  22. package/dist-esm/ajaxRecord.js.map +1 -1
  23. package/dist-esm/ajaxUtils.js +1 -1
  24. package/dist-esm/applicationinsights-dependencies-js.js +1 -1
  25. package/package.json +4 -3
  26. package/src/DependencyInitializer.ts +5 -0
  27. package/src/DependencyListener.ts +7 -0
  28. package/src/__DynamicConstants.ts +4 -3
  29. package/src/ajax.ts +15 -13
  30. package/src/ajaxRecord.ts +17 -11
  31. package/types/DependencyInitializer.d.ts +4 -0
  32. package/types/DependencyListener.d.ts +6 -0
  33. package/types/__DynamicConstants.d.ts +1 -0
  34. package/types/tsdoc-metadata.json +1 -1
@@ -23,6 +23,11 @@ export interface IDependencyInitializerDetails {
23
23
  * The context that the application can assigned via the dependency listener(s)
24
24
  */
25
25
  context?: { [key: string]: any };
26
+
27
+ /**
28
+ * [Optional] A flag that indicates whether the client request was manually aborted by the `abort()`
29
+ */
30
+ aborted?: boolean;
26
31
  }
27
32
 
28
33
  /**
@@ -51,6 +51,13 @@ export interface IDependencyListenerDetails {
51
51
  * [Optional] Context that the application can assign that will also be passed to any dependency initializer
52
52
  */
53
53
  context?: { [key: string]: any };
54
+
55
+ /**
56
+ * [Optional] A flag that indicates whether the client request was manually aborted by the `abort()`,
57
+ * as listeners are called just before the request is sent it is unlikely that an application would have
58
+ * called `abort` before `send` this is also available in the dependency initializer.
59
+ */
60
+ aborted?: boolean;
54
61
  }
55
62
 
56
63
  /**
@@ -17,6 +17,7 @@ export const _DYN_TRACE_ID = "traceID"; // Count: 9
17
17
  export const _DYN_SPAN_ID = "spanID"; // Count: 8
18
18
  export const _DYN_TRACE_FLAGS = "traceFlags"; // Count: 13
19
19
  export const _DYN_CONTEXT = "context"; // Count: 7
20
+ export const _DYN_ABORTED = "aborted"; // Count: 7
20
21
  export const _DYN_TRACE_ID0 = "traceId"; // Count: 5
21
22
  export const _DYN_SPAN_ID1 = "spanId"; // Count: 5
22
23
  export const _DYN_CORE = "core"; // Count: 8
@@ -40,8 +41,8 @@ export const _DYN_EXCLUDE_REQUEST_FROM11 = "excludeRequestFromAutoTrackingPatter
40
41
  export const _DYN_ADD_REQUEST_CONTEXT = "addRequestContext"; // Count: 2
41
42
  export const _DYN_DISABLE_AJAX_TRACKIN12 = "disableAjaxTracking"; // Count: 2
42
43
  export const _DYN_DISABLE_FETCH_TRACKI13 = "disableFetchTracking"; // Count: 2
43
- export const _DYN_STATUS = "status"; // Count: 10
44
- export const _DYN_STATUS_TEXT = "statusText"; // Count: 8
44
+ export const _DYN_STATUS = "status"; // Count: 11
45
+ export const _DYN_STATUS_TEXT = "statusText"; // Count: 9
45
46
  export const _DYN_HEADER_MAP = "headerMap"; // Count: 8
46
47
  export const _DYN_OPEN_DONE = "openDone"; // Count: 3
47
48
  export const _DYN_SEND_DONE = "sendDone"; // Count: 3
@@ -52,7 +53,7 @@ export const _DYN_GET_TRACE_FLAGS = "getTraceFlags"; // Count: 3
52
53
  export const _DYN_METHOD = "method"; // Count: 10
53
54
  export const _DYN_ERROR_STATUS_TEXT = "errorStatusText"; // Count: 3
54
55
  export const _DYN_STATE_CHANGE_ATTACHE14 = "stateChangeAttached"; // Count: 2
55
- export const _DYN_RESPONSE_TEXT = "responseText"; // Count: 5
56
+ export const _DYN_RESPONSE_TEXT = "responseText"; // Count: 6
56
57
  export const _DYN_RESPONSE_FINISHED_TI15 = "responseFinishedTime"; // Count: 7
57
58
  export const _DYN__CREATE_TRACK_ITEM = "CreateTrackItem"; // Count: 3
58
59
  export const _DYN_RESPONSE = "response"; // Count: 4
package/src/ajax.ts CHANGED
@@ -23,7 +23,7 @@ import { IAjaxRecordResponse, ajaxRecord } from "./ajaxRecord";
23
23
  const AJAX_MONITOR_PREFIX = "ai.ajxmn.";
24
24
  const strDiagLog = "diagLog";
25
25
  const strAjaxData = "ajaxData";
26
- const strFetch = "fetch";
26
+ const STR_FETCH = "fetch";
27
27
 
28
28
  const ERROR_HEADER = "Failed to monitor XMLHttpRequest";
29
29
  const ERROR_PREFIX = ", monitoring data for this ajax call ";
@@ -47,11 +47,11 @@ function _supportsFetch(): (input: RequestInfo, init?: RequestInit) => Promise<R
47
47
  if (!_global ||
48
48
  isNullOrUndefined((_global as any).Request) ||
49
49
  isNullOrUndefined((_global as any).Request[strPrototype]) ||
50
- isNullOrUndefined(_global[strFetch])) {
50
+ isNullOrUndefined(_global[STR_FETCH])) {
51
51
  return null;
52
52
  }
53
53
 
54
- return _global[strFetch];
54
+ return _global[STR_FETCH];
55
55
  }
56
56
 
57
57
  /**
@@ -196,7 +196,8 @@ function _processDependencyListeners(listeners: _IInternalDependencyHandler<Depe
196
196
  traceId: ajaxData.traceID,
197
197
  spanId: ajaxData.spanID,
198
198
  traceFlags: ajaxData.traceFlags,
199
- context: ajaxData.context || {}
199
+ context: ajaxData.context || {},
200
+ aborted: !!ajaxData.aborted
200
201
  };
201
202
 
202
203
  _processDependencyContainer(core, listeners, details, "listener");
@@ -559,7 +560,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
559
560
  let global = getGlobal();
560
561
  let isPolyfill = (fetch as any).polyfill;
561
562
  if (!_disableFetchTracking && !_fetchInitialized) {
562
- _addHook(InstrumentFunc(global, strFetch, {
563
+ _addHook(InstrumentFunc(global, STR_FETCH, {
563
564
  ns: _evtNamespace,
564
565
  // Add request hook
565
566
  req: (callDetails: IInstrumentCallDetails, input, init) => {
@@ -585,12 +586,12 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
585
586
  callDetails.rslt = callDetails.rslt.then((response: any) => {
586
587
  _reportFetchMetrics(callDetails, (response||{}).status, input, response, fetchData, () => {
587
588
  let ajaxResponse:IAjaxRecordResponse = {
588
- statusText: response.statusText,
589
+ statusText: (response||{}).statusText,
589
590
  headerMap: null,
590
591
  correlationContext: _getFetchCorrelationContext(response)
591
592
  };
592
593
 
593
- if (_enableResponseHeaderTracking) {
594
+ if (_enableResponseHeaderTracking && response) {
594
595
  const responseHeaderMap = {};
595
596
  response.headers.forEach((value: string, name: string) => { // @skip-minify
596
597
  if (_canIncludeHeaders(name)) {
@@ -607,7 +608,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
607
608
  return response;
608
609
  })
609
610
  .catch((reason: any) => {
610
- _reportFetchMetrics(callDetails, 0, input, null, fetchData, null, { error: reason.message });
611
+ _reportFetchMetrics(callDetails, 0, input, null, fetchData, null, { error: reason.message || dumpObj(reason) });
611
612
  throw reason;
612
613
  });
613
614
  }
@@ -626,7 +627,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
626
627
  // Note: Polyfill implementations that don't support the "poyyfill" tag are not supported
627
628
  // the workaround is to add a polyfill property to your fetch implementation before initializing
628
629
  // App Insights
629
- _addHook(InstrumentFunc(global, strFetch, {
630
+ _addHook(InstrumentFunc(global, STR_FETCH, {
630
631
  ns: _evtNamespace,
631
632
  req: (callDetails: IInstrumentCallDetails, input, init) => {
632
633
  // Just call so that we record any disabled URL
@@ -638,7 +639,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
638
639
  if (isPolyfill) {
639
640
  // retag the instrumented fetch with the same polyfill settings this is mostly for testing
640
641
  // But also supports multiple App Insights usages
641
- (global[strFetch] as any).polyfill = isPolyfill;
642
+ (global[STR_FETCH] as any).polyfill = isPolyfill;
642
643
  }
643
644
  }
644
645
 
@@ -1097,7 +1098,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
1097
1098
 
1098
1099
  ajaxData.requestHeaders = requestHeaders;
1099
1100
 
1100
- _createMarkId("fetch", ajaxData);
1101
+ _createMarkId(STR_FETCH, ajaxData);
1101
1102
 
1102
1103
  return ajaxData;
1103
1104
  }
@@ -1143,7 +1144,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
1143
1144
  ajaxData.responseFinishedTime = dateTimeUtilsNow();
1144
1145
  ajaxData.status = status;
1145
1146
 
1146
- _findPerfResourceEntry("fetch", ajaxData, () => {
1147
+ _findPerfResourceEntry(STR_FETCH, ajaxData, () => {
1147
1148
  const dependency = ajaxData.CreateTrackItem("Fetch", _enableRequestHeaderTracking, getResponse);
1148
1149
 
1149
1150
  let properties;
@@ -1209,7 +1210,8 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
1209
1210
  item: dependency,
1210
1211
  properties: properties,
1211
1212
  sysProperties: systemProperties,
1212
- context: ajaxData ? ajaxData.context : null
1213
+ context: ajaxData ? ajaxData.context : null,
1214
+ aborted: ajaxData ? !!ajaxData.aborted : false
1213
1215
  };
1214
1216
 
1215
1217
  result = _processDependencyContainer(core, initializers, details, "initializer");
package/src/ajaxRecord.ts CHANGED
@@ -240,7 +240,7 @@ export class ajaxRecord {
240
240
 
241
241
  public xhrMonitoringState: XHRMonitoringState;
242
242
 
243
- // <summary>Determines whether or not JavaScript exception occured in xhr.onreadystatechange code. 1 if occured, otherwise 0.</summary>
243
+ // <summary>Determines whether or not JavaScript exception occurred in xhr.onreadystatechange code. 1 if occurred, otherwise 0.</summary>
244
244
  public clientFailure: number;
245
245
 
246
246
  /**
@@ -339,6 +339,11 @@ export class ajaxRecord {
339
339
  [STR_PROPERTIES]: { HttpMethod: self.method }
340
340
  } as IDependencyTelemetry;
341
341
 
342
+ let props = dependency[STR_PROPERTIES];
343
+ if (self.aborted) {
344
+ props.aborted = true;
345
+ }
346
+
342
347
  if (self.requestSentTime) {
343
348
  // Set the correct dependency start time
344
349
  dependency.startTime = new Date();
@@ -350,7 +355,6 @@ export class ajaxRecord {
350
355
 
351
356
  if (enableRequestHeaderTracking) {
352
357
  if (objKeys(self.requestHeaders).length > 0) {
353
- let props = dependency.properties = dependency.properties || {};
354
358
  props.requestHeaders = self.requestHeaders;
355
359
  }
356
360
  }
@@ -367,19 +371,21 @@ export class ajaxRecord {
367
371
 
368
372
  if (response.headerMap) {
369
373
  if (objKeys(response.headerMap).length > 0) {
370
- let props = dependency.properties = dependency.properties || {};
371
374
  props.responseHeaders = response.headerMap;
372
375
  }
373
376
  }
374
377
 
375
- if (self.errorStatusText && self.status >= 400) {
376
- const responseType = response.type;
377
- let props = dependency.properties = dependency.properties || {};
378
- if (responseType === "" || responseType === "text") {
379
- props.responseText = response.responseText ? response.statusText + " - " + response[strResponseText] : response.statusText;
380
- }
381
- if (responseType === "json") {
382
- props.responseText = response.response ? response.statusText + " - " + JSON.stringify(response.response) : response.statusText;
378
+ if (self.errorStatusText) {
379
+ if (self.status >= 400) {
380
+ const responseType = response.type;
381
+ if (responseType === "" || responseType === "text") {
382
+ props.responseText = response.responseText ? response.statusText + " - " + response[strResponseText] : response.statusText;
383
+ }
384
+ if (responseType === "json") {
385
+ props.responseText = response.response ? response.statusText + " - " + JSON.stringify(response.response) : response.statusText;
386
+ }
387
+ } else if (self.status === 0) {
388
+ props.responseText = response.statusText || "";
383
389
  }
384
390
  }
385
391
  }
@@ -23,6 +23,10 @@ export interface IDependencyInitializerDetails {
23
23
  context?: {
24
24
  [key: string]: any;
25
25
  };
26
+ /**
27
+ * [Optional] A flag that indicates whether the client request was manually aborted by the `abort()`
28
+ */
29
+ aborted?: boolean;
26
30
  }
27
31
  /**
28
32
  * The initializer function that will be called, if it returns false the event will be dropped and not reported
@@ -42,6 +42,12 @@ export interface IDependencyListenerDetails {
42
42
  context?: {
43
43
  [key: string]: any;
44
44
  };
45
+ /**
46
+ * [Optional] A flag that indicates whether the client request was manually aborted by the `abort()`,
47
+ * as listeners are called just before the request is sent it is unlikely that an application would have
48
+ * called `abort` before `send` this is also available in the dependency initializer.
49
+ */
50
+ aborted?: boolean;
45
51
  }
46
52
  /**
47
53
  * The function that will get called when the ajax request is about to occur.
@@ -5,6 +5,7 @@ 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
7
  export declare const _DYN_CONTEXT = "context";
8
+ export declare const _DYN_ABORTED = "aborted";
8
9
  export declare const _DYN_TRACE_ID0 = "traceId";
9
10
  export declare const _DYN_SPAN_ID1 = "spanId";
10
11
  export declare const _DYN_CORE = "core";
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.33.7"
8
+ "packageVersion": "7.34.2"
9
9
  }
10
10
  ]
11
11
  }