@microsoft/applicationinsights-dependencies-js 3.4.0-nightlybeta3.2505-35 → 3.4.0-nightlybeta3.2507-23

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/es5/applicationinsights-dependencies-js.cjs.js +870 -322
  2. package/browser/es5/applicationinsights-dependencies-js.cjs.js.map +1 -1
  3. package/browser/es5/applicationinsights-dependencies-js.cjs.min.js +2 -2
  4. package/browser/es5/applicationinsights-dependencies-js.cjs.min.js.map +1 -1
  5. package/browser/es5/applicationinsights-dependencies-js.gbl.js +872 -324
  6. package/browser/es5/applicationinsights-dependencies-js.gbl.js.map +1 -1
  7. package/browser/es5/applicationinsights-dependencies-js.gbl.min.js +2 -2
  8. package/browser/es5/applicationinsights-dependencies-js.gbl.min.js.map +1 -1
  9. package/browser/es5/applicationinsights-dependencies-js.integrity.json +25 -25
  10. package/browser/es5/applicationinsights-dependencies-js.js +872 -324
  11. package/browser/es5/applicationinsights-dependencies-js.js.map +1 -1
  12. package/browser/es5/applicationinsights-dependencies-js.min.js +2 -2
  13. package/browser/es5/applicationinsights-dependencies-js.min.js.map +1 -1
  14. package/dist/es5/applicationinsights-dependencies-js.js +870 -322
  15. package/dist/es5/applicationinsights-dependencies-js.js.map +1 -1
  16. package/dist/es5/applicationinsights-dependencies-js.min.js +2 -2
  17. package/dist/es5/applicationinsights-dependencies-js.min.js.map +1 -1
  18. package/dist-es5/DependencyInitializer.js +1 -1
  19. package/dist-es5/DependencyListener.js +1 -1
  20. package/dist-es5/InternalConstants.js +2 -1
  21. package/dist-es5/InternalConstants.js.map +1 -1
  22. package/dist-es5/__DynamicConstants.js +15 -19
  23. package/dist-es5/__DynamicConstants.js.map +1 -1
  24. package/dist-es5/ajax.js +130 -62
  25. package/dist-es5/ajax.js.map +1 -1
  26. package/dist-es5/ajaxRecord.js +137 -148
  27. package/dist-es5/ajaxRecord.js.map +1 -1
  28. package/dist-es5/applicationinsights-dependencies-js.js +1 -2
  29. package/dist-es5/applicationinsights-dependencies-js.js.map +1 -1
  30. package/package.json +3 -3
  31. package/types/applicationinsights-dependencies-js.d.ts +150 -50
  32. package/types/applicationinsights-dependencies-js.namespaced.d.ts +628 -88
  33. package/dist-es5/ajaxUtils.js +0 -30
  34. package/dist-es5/ajaxUtils.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights XHR dependencies plugin, 3.4.0-nightlybeta3.2505-35
2
+ * Microsoft Application Insights XHR dependencies plugin, 3.4.0-nightlybeta3.2507-23
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -21,7 +21,7 @@ declare namespace ApplicationInsights {
21
21
  trackDependencyData(dependency: IDependencyTelemetry, properties?: {
22
22
  [key: string]: any;
23
23
  }): void;
24
- includeCorrelationHeaders(ajaxData: ajaxRecord, input?: Request | string, init?: RequestInit, xhr?: XMLHttpRequestInstrumented): any;
24
+ includeCorrelationHeaders(ajaxData: IAjaxRecordData, input?: Request | string, init?: RequestInit, xhr?: XMLHttpRequestInstrumented): any;
25
25
  /**
26
26
  * Add an ajax listener which is called just prior to the request being sent and before the correlation headers are added, to allow you
27
27
  * to access the headers and modify the values used to generate the distributed tracing correlation headers.
@@ -51,62 +51,6 @@ declare namespace ApplicationInsights {
51
51
  }): void;
52
52
  }
53
53
 
54
- class ajaxRecord {
55
- completed: boolean;
56
- requestHeadersSize: number;
57
- requestHeaders: any;
58
- responseReceivingDuration: number;
59
- callbackDuration: number;
60
- ajaxTotalDuration: number;
61
- aborted: number;
62
- pageUrl: string;
63
- requestUrl: string;
64
- requestSize: number;
65
- method: string;
66
- perfMark: PerformanceMark;
67
- perfTiming: PerformanceResourceTiming;
68
- perfAttempts?: number;
69
- async?: boolean;
70
- errorStatusText?: boolean;
71
- status: string | number;
72
- requestSentTime: number;
73
- responseStartedTime: number;
74
- responseFinishedTime: number;
75
- callbackFinishedTime: number;
76
- endTime: number;
77
- xhrMonitoringState: XHRMonitoringState;
78
- clientFailure: number;
79
- /**
80
- * The traceId to use for the dependency call
81
- */
82
- traceID: string;
83
- /**
84
- * The spanId to use for the dependency call
85
- */
86
- spanID: string;
87
- /**
88
- * The traceFlags to use for the dependency call
89
- */
90
- traceFlags?: number;
91
- /**
92
- * The trace context to use for reporting the remote dependency call
93
- */
94
- eventTraceCtx: ITraceCtx;
95
- /**
96
- * The listener assigned context values that will be passed to any dependency initializer
97
- */
98
- context?: {
99
- [key: string]: any;
100
- };
101
- constructor(traceId: string, spanId: string, logger: IDiagnosticLogger, traceCtx?: IDistributedTraceContext);
102
- getAbsoluteUrl(): string;
103
- getPathName(): string;
104
- CreateTrackItem(ajaxType: string, enableRequestHeaderTracking: boolean, getResponse: () => IAjaxRecordResponse): IDependencyTelemetry;
105
- getPartAProps(): {
106
- [key: string]: any;
107
- };
108
- }
109
-
110
54
  /**
111
55
  * BaseTelemetryPlugin provides a basic implementation of the ITelemetryPlugin interface so that plugins
112
56
  * can avoid implementation the same set of boiler plate code as well as provide a base
@@ -129,9 +73,12 @@ declare namespace ApplicationInsights {
129
73
  */
130
74
  processNext: (env: ITelemetryItem, itemCtx: IProcessTelemetryContext) => void;
131
75
  /**
132
- * Set next extension for telemetry processing
76
+ * Set next extension for telemetry processing, this is now optional as plugins should use the
77
+ * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
78
+ * now for backward compatibility only.
79
+ * @deprecated - Use processNext() function of the passed IProcessTelemetryContext instead
133
80
  */
134
- setNextPlugin: (next: ITelemetryPlugin | ITelemetryPluginChain) => void;
81
+ setNextPlugin?: (next: ITelemetryPlugin | ITelemetryPluginChain) => void;
135
82
  /**
136
83
  * Returns the current diagnostic logger that can be used to log issues, if no logger is currently
137
84
  * assigned a new default one will be created and returned.
@@ -244,17 +191,78 @@ declare namespace ApplicationInsights {
244
191
 
245
192
  const enum eDistributedTracingModes {
246
193
  /**
247
- * (Default) Send Application Insights correlation headers
194
+ * Send only the legacy Application Insights correlation headers
195
+ *
196
+ * Headers Sent:
197
+ * - `Request-Id` (Legacy Application Insights header for older Server side SDKs)
198
+ *
199
+ * Config Decimal Value: `0` (Zero)
248
200
  */
249
201
  AI = 0,
250
202
  /**
251
- * Send both W3C Trace Context headers and back-compatibility Application Insights headers
203
+ * (Default) Send both W3C Trace parent header and back-compatibility Application Insights headers
204
+ * - `Request-Id`
205
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
206
+ *
207
+ * Config Decimal Value: `1` (One)
252
208
  */
253
209
  AI_AND_W3C = 1,
254
210
  /**
255
- * Send W3C Trace Context headers
211
+ * Send Only the W3C Trace parent header
212
+ *
213
+ * Headers Sent:
214
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
215
+ *
216
+ * Config Decimal Value: `2` (Two)
217
+ */
218
+ W3C = 2,
219
+ /**
220
+ * @internal
221
+ * Bitwise mask used to separate the base distributed tracing mode from the additional optional
222
+ * tracing modes.
223
+ * @since 3.4.0
256
224
  */
257
- W3C = 2
225
+ _BaseMask = 15,
226
+ /**
227
+ * @internal
228
+ * Enabling this bit will send the W3C Trace State header, it is not intended to be used directly
229
+ * or on its own. The code may assume that if this bit is set, then the W3C Trace Context headers
230
+ * will also be included.
231
+ *
232
+ * Config Decimal Value: `16` (Sixteen in decimal)
233
+ * @since 3.4.0
234
+ */
235
+ _W3CTraceState = 16,
236
+ /**
237
+ * Send all of the W3C Trace Context headers and the W3C Trace State headers and back-compatibility
238
+ * Application Insights headers.
239
+ *
240
+ * Currently sent headers:
241
+ * - `Request-Id` (Legacy Application Insights header for older Server side SDKs)
242
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
243
+ * - [`tracestate`](https://www.w3.org/TR/trace-context/#tracestate-header)
244
+ *
245
+ * NOTE!: Additional headers may be added as part of a future update should the W3C Trace Context specification be updated
246
+ * to include additional headers.
247
+ *
248
+ * Config Decimal Value: `17` (Seventeen in decimal)
249
+ * @since 3.4.0
250
+ */
251
+ AI_AND_W3C_TRACE = 17,
252
+ /**
253
+ * Send all of the W3C Trace Context headers and the W3C Trace State headers.
254
+ *
255
+ * Currently sent headers:
256
+ * - [`traceparent`](https://www.w3.org/TR/trace-context/#traceparent-header)
257
+ * - [`tracestate`](https://www.w3.org/TR/trace-context/#tracestate-header)
258
+ *
259
+ * NOTE!: Additional headers may be added as part of a future update should the W3C Trace Context specification be updated
260
+ * to include additional headers.
261
+ *
262
+ * Config Decimal Value: `18` (Eighteen in decimal)
263
+ * @since 3.4.0
264
+ */
265
+ W3C_TRACE = 18
258
266
  }
259
267
 
260
268
  const enum _eInternalMessageId {
@@ -387,6 +395,30 @@ declare namespace ApplicationInsights {
387
395
 
388
396
  type EnumValue<E = any> = EnumCls<E>;
389
397
 
398
+ /**
399
+ * Controls how the SDK should look for trace headers (traceparent/tracestate) from the initial page load
400
+ * The values are bitwise OR'd together to allow for multiple values to be set at once.
401
+ * @since 3.4.0
402
+ */
403
+ const enum eTraceHeadersMode {
404
+ /**
405
+ * Don't look for any trace headers
406
+ */
407
+ None = 0,
408
+ /**
409
+ * Look for traceparent header/meta tag
410
+ */
411
+ TraceParent = 1,
412
+ /**
413
+ * Look for tracestate header/meta tag
414
+ */
415
+ TraceState = 2,
416
+ /**
417
+ * Look for both traceparent and tracestate headers/meta tags
418
+ */
419
+ All = 3
420
+ }
421
+
390
422
  const enum FeatureOptInMode {
391
423
  /**
392
424
  * not set, completely depends on cdn cfg
@@ -407,6 +439,157 @@ declare namespace ApplicationInsights {
407
439
  */
408
440
  type FinallyPromiseHandler = (() => void) | undefined | null;
409
441
 
442
+ /**
443
+ * Interface for ajax data passed to includeCorrelationHeaders function.
444
+ * Contains the public properties and methods needed for correlation header processing.
445
+ *
446
+ * @public
447
+ */
448
+ interface IAjaxRecordData {
449
+ /**
450
+ * Gets the absolute URL for the request
451
+ * @returns The absolute URL string or null
452
+ */
453
+ getAbsoluteUrl(): string | null;
454
+ /**
455
+ * Gets the sanitized path name for the request URL
456
+ * @returns The sanitized path name string or null
457
+ */
458
+ getPathName(): string | null;
459
+ /**
460
+ * The distributed trace context for the request containing trace ID, span ID, and trace flags
461
+ */
462
+ readonly traceCtx: IDistributedTraceContext;
463
+ /**
464
+ * Object containing request headers that have been set for this request
465
+ */
466
+ requestHeaders: {
467
+ [key: string]: string;
468
+ };
469
+ /**
470
+ * Indicates whether the request was aborted (0 = not aborted, 1 = aborted)
471
+ */
472
+ aborted: number;
473
+ /**
474
+ * Optional context object that can be set by dependency listeners
475
+ */
476
+ context?: {
477
+ [key: string]: any;
478
+ };
479
+ }
480
+
481
+ /**
482
+ * Internal interface that extends the public IAjaxRecordData with additional properties and methods
483
+ * used internally by the AJAX monitoring implementation.
484
+ *
485
+ * @internal
486
+ */
487
+ interface IAjaxRecordInternal extends IAjaxRecordData {
488
+ /**
489
+ * Indicates if the ajax call has completed
490
+ */
491
+ completed: boolean;
492
+ /**
493
+ * Size of the request headers in bytes
494
+ */
495
+ requestHeadersSize: number;
496
+ /**
497
+ * Duration of receiving the response in milliseconds
498
+ */
499
+ responseReceivingDuration: number;
500
+ /**
501
+ * Duration of the callback execution in milliseconds
502
+ */
503
+ callbackDuration: number;
504
+ /**
505
+ * Total duration of the ajax call in milliseconds
506
+ */
507
+ ajaxTotalDuration: number;
508
+ /**
509
+ * URL of the page that initiated the request
510
+ */
511
+ pageUrl: string;
512
+ /**
513
+ * The URL of the request
514
+ */
515
+ requestUrl: string;
516
+ /**
517
+ * Size of the request in bytes
518
+ */
519
+ requestSize: number;
520
+ /**
521
+ * HTTP method used for the request
522
+ */
523
+ method: string;
524
+ /**
525
+ * Performance mark associated with this request
526
+ */
527
+ perfMark: PerformanceMark;
528
+ /**
529
+ * Performance timing data from the Resource Timing API
530
+ */
531
+ perfTiming: PerformanceResourceTiming;
532
+ /**
533
+ * Number of attempts to find performance data
534
+ */
535
+ perfAttempts?: number;
536
+ /**
537
+ * Indicates if the request was made asynchronously
538
+ */
539
+ async?: boolean;
540
+ /**
541
+ * Should the Error Status text be included in the response
542
+ */
543
+ errorStatusText?: boolean;
544
+ /**
545
+ * HTTP status code of the response
546
+ */
547
+ status: string | number;
548
+ /**
549
+ * Timestamp when the request was sent
550
+ */
551
+ requestSentTime: number;
552
+ /**
553
+ * Timestamp when the first byte was received
554
+ */
555
+ responseStartedTime: number;
556
+ /**
557
+ * Timestamp when the last byte was received
558
+ */
559
+ responseFinishedTime: number;
560
+ /**
561
+ * Timestamp when the onreadystatechange callback finished
562
+ */
563
+ callbackFinishedTime: number;
564
+ /**
565
+ * Timestamp when the ajax call ended
566
+ */
567
+ endTime: number;
568
+ /**
569
+ * State tracking object for XHR monitoring
570
+ */
571
+ xhrMonitoringState: IXHRMonitoringState;
572
+ /**
573
+ * Indicates if a JavaScript exception occurred in xhr.onreadystatechange code (1 if occurred, 0 otherwise)
574
+ */
575
+ clientFailure: number;
576
+ /**
577
+ * Creates a telemetry item for tracking this ajax request
578
+ * @param ajaxType - Type of the ajax request
579
+ * @param enableRequestHeaderTracking - Whether to include request headers in telemetry
580
+ * @param getResponse - Function to get response data
581
+ * @returns Dependency telemetry item or null
582
+ */
583
+ CreateTrackItem(ajaxType: string, enableRequestHeaderTracking: boolean, getResponse: () => IAjaxRecordResponse): IDependencyTelemetry;
584
+ /**
585
+ * Gets Part A properties for telemetry
586
+ * @returns Object containing Part A properties or null
587
+ */
588
+ getPartAProps(): {
589
+ [key: string]: any;
590
+ };
591
+ }
592
+
410
593
  interface IAjaxRecordResponse {
411
594
  statusText: string;
412
595
  headerMap: Object;
@@ -538,7 +721,7 @@ declare namespace ApplicationInsights {
538
721
  */
539
722
  flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
540
723
  /**
541
- * Gets the current distributed trace context for this instance if available
724
+ * Gets the current distributed trace active context for this instance
542
725
  * @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
543
726
  */
544
727
  getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
@@ -587,9 +770,12 @@ declare namespace ApplicationInsights {
587
770
  */
588
771
  getCfg: () => IConfiguration;
589
772
  /**
590
- * Gets the named extension config
773
+ * Gets the named extension configuration
774
+ * @param identifier - The named extension identifier
775
+ * @param defaultValue - The default value(s) to return if no defined config exists
776
+ * @param rootOnly - If true, only the look for the configuration in the top level and not in the "extensionConfig"
591
777
  */
592
- getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>) => T;
778
+ getExtCfg: <T>(identifier: string, defaultValue?: IConfigDefaults<T>, rootOnly?: boolean) => T;
593
779
  /**
594
780
  * Gets the named config from either the named identifier extension or core config if neither exist then the
595
781
  * default value is returned
@@ -1210,7 +1396,7 @@ declare namespace ApplicationInsights {
1210
1396
  * }
1211
1397
  * ```
1212
1398
  *
1213
- * For more details, see the [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html).
1399
+ * For more details, see the [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/PageUnloadEvents.html).
1214
1400
  */
1215
1401
  disablePageUnloadEvents?: string[];
1216
1402
  /**
@@ -1225,7 +1411,7 @@ declare namespace ApplicationInsights {
1225
1411
  * }
1226
1412
  * ```
1227
1413
  *
1228
- * For more details, see the [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/docs/PageUnloadEvents.html).
1414
+ * For more details, see the [Page Unload Events documentation](https://microsoft.github.io/ApplicationInsights-JS/PageUnloadEvents.html).
1229
1415
  */
1230
1416
  disablePageShowEvents?: string[];
1231
1417
  /**
@@ -1267,6 +1453,25 @@ declare namespace ApplicationInsights {
1267
1453
  * @since 3.3.2
1268
1454
  */
1269
1455
  expCfg?: IExceptionConfig;
1456
+ /**
1457
+ * [Optional] A flag to enable or disable the use of the field redaction for urls.
1458
+ * @defaultValue true
1459
+ */
1460
+ redactUrls?: boolean;
1461
+ /**
1462
+ * [Optional] Additional query parameters to redact beyond the default set.
1463
+ * Use this to specify custom parameters that contain sensitive information.
1464
+ * These will be combined with the default parameters that are redacted.
1465
+ * @defaultValue ["sig", "Signature", "AWSAccessKeyId", "X-Goog-Signature"]
1466
+ * @example ["sig", "Signature", "AWSAccessKeyId", "X-Goog-Signature","auth_token", "api_key", "private_data"]
1467
+ */
1468
+ redactQueryParams?: string[];
1469
+ /**
1470
+ * [Optional] Controls if the SDK should look for the `traceparent` and/or `tracestate` values from
1471
+ * the service timing headers or meta tags from the initial page load.
1472
+ * @defaultValue eTraceHeadersMode.All
1473
+ */
1474
+ traceHdrMode?: eTraceHeadersMode;
1270
1475
  }
1271
1476
 
1272
1477
  interface ICookieMgr {
@@ -1377,6 +1582,180 @@ declare namespace ApplicationInsights {
1377
1582
  delCookie?: (name: string, cookieValue: string) => void;
1378
1583
  }
1379
1584
 
1585
+ interface ICorrelationConfig {
1586
+ enableCorsCorrelation: boolean;
1587
+ /**
1588
+ * [Optional] Domains to be excluded from correlation headers.
1589
+ * To override or discard the default, add an array with all domains to be excluded or
1590
+ * an empty array to the configuration.
1591
+ *
1592
+ * @example
1593
+ * ```ts
1594
+ * import { ApplicationInsights } from '@microsoft/applicationinsights-web';
1595
+ * const appInsights = new ApplicationInsights({
1596
+ * config: {
1597
+ * connectionString: 'InstrumentationKey=YOUR_INSTRUMENTATION_KEY_GOES_HERE',
1598
+ * extensionConfig: {
1599
+ * AjaxDependencyPlugin: {
1600
+ * // Both arrays of strings are used to match the request URL against the
1601
+ * // current host and the request URL to determine if correlation headers
1602
+ * // The strings are converted to RegExp objects by translating
1603
+ * // - `.` to `\\.` (to match a literal dot)
1604
+ * // - `*` to `.*` (to match any character)
1605
+ * // - `\` to `\\` (to match a literal slash)
1606
+ * // All other characters are ignored and passed to the RegExp constructor
1607
+ * correlationHeaderExcludedDomains: ["test", "*.azure.com", "ignore.microsoft.com"],
1608
+ * correlationHeaderDomains: ["azure.com", "prefix.bing.com", "*.microsoft.com", "example.com"]
1609
+ * }
1610
+ * }
1611
+ * });
1612
+ * appInsights.loadAppInsights();
1613
+ * appInsights.trackPageView(); // Manually call trackPageView to establish the current user/session/pageview
1614
+ * ```
1615
+ */
1616
+ correlationHeaderExcludedDomains: string[];
1617
+ /**
1618
+ * [Optional] Domains to be included in correlation headers.
1619
+ * To override or discard the default, add an array with all domains to be included or
1620
+ * an empty array to the configuration.
1621
+ *
1622
+ * @example
1623
+ * ```ts
1624
+ * import { ApplicationInsights } from '@microsoft/applicationinsights-web';
1625
+ * const appInsights = new ApplicationInsights({
1626
+ * config: {
1627
+ * connectionString: 'InstrumentationKey=YOUR_INSTRUMENTATION_KEY_GOES_HERE',
1628
+ * extensionConfig: {
1629
+ * AjaxDependencyPlugin: {
1630
+ * // Values MUST be RegExp objects
1631
+ * correlationHeaderExcludePatterns: [/*\.azure.com/, /prefix.bing.com/, /.*\.microsoft.com/, /example.com/]
1632
+ * }
1633
+ * }
1634
+ * });
1635
+ * appInsights.loadAppInsights();
1636
+ * appInsights.trackPageView(); // Manually call trackPageView to establish the current user/session/pageview
1637
+ * ```
1638
+ */
1639
+ correlationHeaderExcludePatterns?: RegExp[];
1640
+ disableCorrelationHeaders: boolean;
1641
+ /**
1642
+ * The distributed tracing mode to use for this configuration.
1643
+ * Defaults to AI_AND_W3C.
1644
+ * This is used to determine which headers are sent with requests and how the
1645
+ * telemetry is correlated across services.
1646
+ * @default AI_AND_W3C
1647
+ * @see {@link DistributedTracingModes}
1648
+ */
1649
+ distributedTracingMode: DistributedTracingModes;
1650
+ maxAjaxCallsPerView: number;
1651
+ disableAjaxTracking: boolean;
1652
+ disableFetchTracking: boolean;
1653
+ appId?: string;
1654
+ enableRequestHeaderTracking?: boolean;
1655
+ enableResponseHeaderTracking?: boolean;
1656
+ enableAjaxErrorStatusText?: boolean;
1657
+ /**
1658
+ * Flag to enable looking up and including additional browser window.performance timings
1659
+ * in the reported ajax (XHR and fetch) reported metrics.
1660
+ * Defaults to false.
1661
+ */
1662
+ enableAjaxPerfTracking?: boolean;
1663
+ /**
1664
+ * The maximum number of times to look for the window.performance timings (if available), this
1665
+ * is required as not all browsers populate the window.performance before reporting the
1666
+ * end of the XHR request and for fetch requests this is added after its complete
1667
+ * Defaults to 3
1668
+ */
1669
+ maxAjaxPerfLookupAttempts?: number;
1670
+ /**
1671
+ * The amount of time to wait before re-attempting to find the windows.performance timings
1672
+ * for an ajax request, time is in milliseconds and is passed directly to setTimeout()
1673
+ * Defaults to 25.
1674
+ */
1675
+ ajaxPerfLookupDelay?: number;
1676
+ /**
1677
+ * [Optional] Domains to be excluded from correlation headers.
1678
+ * To override or discard the default, add an array with all domains to be excluded or
1679
+ * an empty array to the configuration.
1680
+ *
1681
+ * @example
1682
+ * ```ts
1683
+ * import { ApplicationInsights } from '@microsoft/applicationinsights-web';
1684
+ * const appInsights = new ApplicationInsights({
1685
+ * config: {
1686
+ * connectionString: 'InstrumentationKey=YOUR_INSTRUMENTATION_KEY_GOES_HERE',
1687
+ * extensionConfig: {
1688
+ * AjaxDependencyPlugin: {
1689
+ * // Both arrays of strings are used to match the request URL against the
1690
+ * // current host and the request URL to determine if correlation headers
1691
+ * // The strings are converted to RegExp objects by translating
1692
+ * // - `.` to `\\.` (to match a literal dot)
1693
+ * // - `*` to `.*` (to match any character)
1694
+ * // - `\` to `\\` (to match a literal slash)
1695
+ * // All other characters are ignored and passed to the RegExp constructor
1696
+ * correlationHeaderExcludedDomains: ["test", "*.azure.com", "ignore.microsoft.com"],
1697
+ * correlationHeaderDomains: ["azure.com", "prefix.bing.com", "*.microsoft.com", "example.com"]
1698
+ * }
1699
+ * }
1700
+ * });
1701
+ * appInsights.loadAppInsights();
1702
+ * appInsights.trackPageView(); // Manually call trackPageView to establish the current user/session/pageview
1703
+ * ```
1704
+ */
1705
+ correlationHeaderDomains?: string[];
1706
+ /**
1707
+ * [Optional] Response and request headers to be excluded from AJAX & Fetch tracking data.
1708
+ * To override or discard the default, add an array with all headers to be excluded or
1709
+ * an empty array to the configuration.
1710
+ *
1711
+ * For example: `["Authorization", "X-API-Key", "WWW-Authenticate"]`
1712
+ *
1713
+ * @example
1714
+ * ```js
1715
+ * import { ApplicationInsights } from '@microsoft/applicationinsights-web';
1716
+ * import { AjaxPlugin } from '@microsoft/applicationinsights-dependencies-js';
1717
+ *
1718
+ * const dependencyPlugin = new AjaxPlugin();
1719
+ * const appInsights = new ApplicationInsights({
1720
+ * config: {
1721
+ * connectionString: 'InstrumentationKey=YOUR_INSTRUMENTATION_KEY_GOES_HERE',
1722
+ * extensions: [dependencyPlugin],
1723
+ * extensionConfig: {
1724
+ * AjaxDependencyPlugin: {
1725
+ * ignoreHeaders: [
1726
+ * "Authorization",
1727
+ * "X-API-Key",
1728
+ * "WWW-Authenticate"
1729
+ * ]
1730
+ * }
1731
+ * }
1732
+ * }
1733
+ * });
1734
+ * appInsights.loadAppInsights();
1735
+ * appInsights.trackPageView(); // Manually call trackPageView to establish the current user/session/pageview
1736
+ * ```
1737
+ */
1738
+ ignoreHeaders?: string[];
1739
+ /**
1740
+ * Provide a way to exclude specific route from automatic tracking for XMLHttpRequest or Fetch request.
1741
+ * For an ajax / fetch request that the request url matches with the regex patterns, auto tracking is turned off.
1742
+ * Default is undefined.
1743
+ */
1744
+ excludeRequestFromAutoTrackingPatterns?: string[] | RegExp[];
1745
+ /**
1746
+ * Provide a way to enrich dependencies logs with context at the beginning of api call.
1747
+ * Default is undefined.
1748
+ */
1749
+ addRequestContext?: (requestContext?: IRequestContext) => ICustomProperties;
1750
+ /**
1751
+ * [Optional] Flag to indicate whether the internal looking endpoints should be automatically
1752
+ * added to the `excludeRequestFromAutoTrackingPatterns` collection. (defaults to true).
1753
+ * This flag exists as the provided regex is generic and may unexpectedly match a domain that
1754
+ * should not be excluded.
1755
+ */
1756
+ addIntEndpoints?: boolean;
1757
+ }
1758
+
1380
1759
  interface ICustomProperties {
1381
1760
  [key: string]: any;
1382
1761
  }
@@ -1473,6 +1852,12 @@ declare namespace ApplicationInsights {
1473
1852
  * https://www.w3.org/TR/trace-context/#trace-flags
1474
1853
  */
1475
1854
  traceFlags?: number;
1855
+ /**
1856
+ * The W3C TraceState object that contains the trace state information, this is mutable and changes made to this
1857
+ * instance will be reflected in the distributed trace context. You cannot overwrite the traceState, but you can
1858
+ * modify the values within the traceState.
1859
+ */
1860
+ readonly traceState?: IW3cTraceState;
1476
1861
  /**
1477
1862
  * [Optional] Context that the application can assign that will also be passed to any dependency initializer
1478
1863
  */
@@ -1573,8 +1958,13 @@ declare namespace ApplicationInsights {
1573
1958
  */
1574
1959
  getName(): string;
1575
1960
  /**
1576
- * Sets the current name of the page
1961
+ * Sets the current name of the page, also updates the name for any parent context.
1962
+ * This is used to identify the page in the telemetry data.
1963
+ * @remarks This function updates the current and ALL parent contexts with the new name,
1964
+ * to just update the name of the current context, use the `pageName` property.
1577
1965
  * @param pageName - The name of the page
1966
+ * @deprecated Use the `pageName` property to avoid the side effect of changing the page name of all
1967
+ * parent contexts.
1578
1968
  */
1579
1969
  setName(pageName: string): void;
1580
1970
  /**
@@ -1587,6 +1977,12 @@ declare namespace ApplicationInsights {
1587
1977
  * Set the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
1588
1978
  * Must be conform to the W3C TraceContext specification, in a hex representation of 16-byte array.
1589
1979
  * A.k.a. trace-id, TraceID or Distributed TraceID https://www.w3.org/TR/trace-context/#trace-id
1980
+ *
1981
+ * @remarks Sets the traceId for the current context AND all parent contexts, if you want to set the traceId
1982
+ * for the current context only, use the `traceId` property.
1983
+ * @param newValue - The traceId to set
1984
+ * @deprecated Use the `traceId` property to avoid the side effect of changing the traceId of all
1985
+ * parent contexts.
1590
1986
  */
1591
1987
  setTraceId(newValue: string): void;
1592
1988
  /**
@@ -1598,6 +1994,12 @@ declare namespace ApplicationInsights {
1598
1994
  * Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
1599
1995
  * Also know as the parentId, used to link requests together
1600
1996
  * https://www.w3.org/TR/trace-context/#parent-id
1997
+ *
1998
+ * @remarks Sets the spanId for the current context AND all parent contexts, if you want to set the spanId for
1999
+ * the current context only, use the `spanId` property.
2000
+ * @param newValue - The spanId to set
2001
+ * @deprecated Use the `spanId` property to avoid the side effect of changing the spanId of all
2002
+ * parent contexts.
1601
2003
  */
1602
2004
  setSpanId(newValue: string): void;
1603
2005
  /**
@@ -1606,9 +2008,80 @@ declare namespace ApplicationInsights {
1606
2008
  getTraceFlags(): number | undefined;
1607
2009
  /**
1608
2010
  * https://www.w3.org/TR/trace-context/#trace-flags
2011
+ * @remarks Sets the trace flags for the current context and ALL parent contexts, if you want to set the trace
2012
+ * flags for the current context only, use the `traceFlags` property.
1609
2013
  * @param newValue - An integer representation of the W3C TraceContext trace-flags.
2014
+ * @deprecated Use the `traceFlags` property to avoid the side effect of changing the traceFlags of all
2015
+ * parent contexts.
1610
2016
  */
1611
2017
  setTraceFlags(newValue?: number): void;
2018
+ /**
2019
+ * Returns the current name of the page
2020
+ * @remarks This function updates the current context only, to update the name of the current and ALL parent contexts,
2021
+ * use the `setName` method.
2022
+ * @default undefined
2023
+ * @since 3.4.0
2024
+ */
2025
+ pageName: string;
2026
+ /**
2027
+ * The current ID of the trace that this span belongs to. It is worldwide unique
2028
+ * with practically sufficient probability by being made as 16 randomly
2029
+ * generated bytes, encoded as a 32 lowercase hex characters corresponding to
2030
+ * 128 bits.
2031
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
2032
+ * if you need to update the current and ALL parent contexts, use the `setTraceId` method.
2033
+ * @since 3.4.0
2034
+ */
2035
+ traceId: string;
2036
+ /**
2037
+ * The ID of the Span. It is globally unique with practically sufficient
2038
+ * probability by being made as 8 randomly generated bytes, encoded as a 16
2039
+ * lowercase hex characters corresponding to 64 bits.
2040
+ * If you update this value, it will only update for the current context, not the parent context.
2041
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
2042
+ * if you need to update the current and ALL parent contexts, use the `setSpanId` method.
2043
+ * @since 3.4.0
2044
+ */
2045
+ spanId: string;
2046
+ /**
2047
+ * Returns true if the current context was initialized (propagated) from a remote parent.
2048
+ * @since 3.4.0
2049
+ * @default false
2050
+ * @returns True if the context was propagated from a remote parent
2051
+ */
2052
+ readonly isRemote: boolean;
2053
+ /**
2054
+ * Trace flags to propagate.
2055
+ *
2056
+ * It is represented as 1 byte (bitmap). Bit to represent whether trace is
2057
+ * sampled or not. When set, the least significant bit documents that the
2058
+ * caller may have recorded trace data. A caller who does not record trace
2059
+ * data out-of-band leaves this flag unset.
2060
+ *
2061
+ * see {@link eW3CTraceFlags} for valid flag values.
2062
+ *
2063
+ * @remarks If you update this value, it will only update for the current context, not the parent context,
2064
+ * if you need to update the current and ALL parent contexts, use the `setTraceFlags` method.
2065
+ * @since 3.4.0
2066
+ */
2067
+ traceFlags?: number;
2068
+ /**
2069
+ * Returns the current trace state which will be used to propgate context across different services.
2070
+ * Updating (adding / removing keys) of the trace state will modify the current context.
2071
+ * @remarks Unlike the OpenTelemetry {@link TraceState}, this value is a mutable object, so you can
2072
+ * modify it directly you do not need to reassign the new value to this property.
2073
+ * @since 3.4.0
2074
+ */
2075
+ readonly traceState: IW3cTraceState;
2076
+ /**
2077
+ * Provides access to the parent context of the current context.
2078
+ * @remarks This is a read-only property, you cannot modify the parent context directly, you can only
2079
+ * modify the current context. If you need to modify the parent context, you need to do it through the
2080
+ * current context using the `setTraceId`, `setSpanId`, `setTraceFlags` and `setName` methods.
2081
+ * @default null
2082
+ * @since 3.4.0
2083
+ */
2084
+ readonly parentCtx?: IDistributedTraceContext | null;
1612
2085
  }
1613
2086
 
1614
2087
  /**
@@ -1697,7 +2170,7 @@ declare namespace ApplicationInsights {
1697
2170
  }
1698
2171
 
1699
2172
  interface IInstrumentationRequirements extends IDependenciesPlugin {
1700
- [_DYN_INCLUDE_CORRELATION_0]: (ajaxData: ajaxRecord, input?: Request | string, init?: RequestInit, xhr?: XMLHttpRequestInstrumented) => any;
2173
+ [_DYN_INCLUDE_CORRELATION_0]: (ajaxData: IAjaxRecordData, input?: Request | string, init?: RequestInit, xhr?: XMLHttpRequestInstrumented) => any;
1701
2174
  }
1702
2175
 
1703
2176
  /**
@@ -2404,9 +2877,10 @@ declare namespace ApplicationInsights {
2404
2877
  */
2405
2878
  interface ITelemetryPlugin extends ITelemetryProcessor, IPlugin {
2406
2879
  /**
2407
- * Set next extension for telemetry processing, this is not optional as plugins should use the
2880
+ * Set next extension for telemetry processing, this is now optional as plugins should use the
2408
2881
  * processNext() function of the passed IProcessTelemetryContext instead. It is being kept for
2409
2882
  * now for backward compatibility only.
2883
+ * @deprecated - Use processNext() function of the passed IProcessTelemetryContext instead
2410
2884
  */
2411
2885
  setNextPlugin?: (next: ITelemetryPlugin | ITelemetryPluginChain) => void;
2412
2886
  /**
@@ -2669,12 +3143,6 @@ declare namespace ApplicationInsights {
2669
3143
  enabled: boolean;
2670
3144
  }
2671
3145
 
2672
- interface ITraceCtx {
2673
- traceId: string;
2674
- spanId: string;
2675
- traceFlags: number;
2676
- }
2677
-
2678
3146
  /**
2679
3147
  * An interface which provides automatic removal during unloading of the component
2680
3148
  */
@@ -2694,6 +3162,76 @@ declare namespace ApplicationInsights {
2694
3162
  run: (logger?: IDiagnosticLogger) => void;
2695
3163
  }
2696
3164
 
3165
+ /**
3166
+ * Represents a mutable [W3C trace state list](https://www.w3.org/TR/trace-context/#tracestate-header), this is a
3167
+ * list of key/value pairs that are used to pass trace state information between different tracing systems. The
3168
+ * list is ordered and the order is important as it determines the processing order.
3169
+ *
3170
+ * Importantly instances of this type are mutable, change made to an instance via {@link IW3cTraceState.set} or
3171
+ * {@link IW3cTraceState.del} will be reflected on the instance and any child instances that use it as a parent.
3172
+ * However, any parent instance associated with an instance will not be modified by operations on that particular
3173
+ * instance.
3174
+ *
3175
+ * @since 3.4.0
3176
+ */
3177
+ interface IW3cTraceState {
3178
+ /**
3179
+ * Returns a readonly array of the current keys associated with the trace state, keys are returned in the
3180
+ * required processing order and if this instance has a parent the keys from the parent will be included
3181
+ * unless they have been removed (deleted) from the child instance.
3182
+ * Once created any modifications to the parent will also be reflected in the child, this is different from
3183
+ * the OpenTelemetry implementation which creates a new instance for each call.
3184
+ * @returns A readonly array of the current keys associated with the trace state
3185
+ */
3186
+ readonly keys: string[];
3187
+ /**
3188
+ * Check if the trace state list is empty, meaning it has no keys or values.
3189
+ * This exists to allow for quick checks without needing to create a new array of keys.
3190
+ * @since 3.4.0
3191
+ * @returns true if the trace state list is empty, false otherwise
3192
+ */
3193
+ readonly isEmpty: boolean;
3194
+ /**
3195
+ * Get the value for the specified key that is associated with this instance, either directly or from the parent.
3196
+ * @param key - The key to lookup
3197
+ * @returns The value for the key, or undefined if not found
3198
+ */
3199
+ get(key: string): string | undefined;
3200
+ /**
3201
+ * Set the value for the specified key for this instance, returning its new location within the list.
3202
+ * - 0 is the front of the list
3203
+ * - -1 not set because the key/value pair is invalid
3204
+ * If the key already exists it will be removed from its current location and added to the front of the list. And
3205
+ * if the key was in the parent this will override the value inherited from the parent, more importantly it will
3206
+ * not modify the parent value.
3207
+ * @param key - The key to set
3208
+ * @param value - The value to set
3209
+ * @returns 0 if successful, -1 if not
3210
+ */
3211
+ set(key: string, value: string): number;
3212
+ /**
3213
+ * Delete the specified key from this instance, if the key was in the parent it will be removed (hidden) from
3214
+ * this instance but will still be available directly from the parent.
3215
+ * @param key - The key to delete
3216
+ */
3217
+ del(key: string): void;
3218
+ /**
3219
+ * Format the trace state list into a strings where each string can be used as a header value.
3220
+ * This will return an empty array if the trace state list is empty.
3221
+ * @param maxHeaders - The maximum number of entries to include in the output, once the limit is reached no more entries will be included
3222
+ * @param maxKeys - The maximum number of keys to include in the output, once the limit is reached no more keys will be included
3223
+ * @param maxLen - The maximum length of each header value, once the limit is reached a new header value will be created
3224
+ * @returns An array of strings that can be used for the header values, if the trace state list is empty an empty array will be returned
3225
+ */
3226
+ hdrs(maxHeaders?: number, maxKeys?: number, maxLen?: number): string[];
3227
+ /**
3228
+ * Create a new instance of IW3cTraceState which is a child of this instance, meaning it will inherit the keys
3229
+ * and values from this instance but any changes made to the child will not affect this instance.
3230
+ * @returns A new instance of IW3cTraceState which is a child of this instance
3231
+ */
3232
+ child(): IW3cTraceState;
3233
+ }
3234
+
2697
3235
  interface IWatchDetails<T = IConfiguration> {
2698
3236
  /**
2699
3237
  * The current config object
@@ -2728,6 +3266,17 @@ declare namespace ApplicationInsights {
2728
3266
  rdOnly: <C, V = any>(target: C, name: string) => V;
2729
3267
  }
2730
3268
 
3269
+ /**
3270
+ * Interface defining the XHR monitoring state properties
3271
+ */
3272
+ interface IXHRMonitoringState {
3273
+ openDone: boolean;
3274
+ setRequestHeaderDone: boolean;
3275
+ sendDone: boolean;
3276
+ abortDone: boolean;
3277
+ stateChangeAttached: boolean;
3278
+ }
3279
+
2731
3280
  const LoggingSeverity: EnumValue<typeof eLoggingSeverity>;
2732
3281
 
2733
3282
  type LoggingSeverity = number | eLoggingSeverity;
@@ -2846,15 +3395,6 @@ declare namespace ApplicationInsights {
2846
3395
 
2847
3396
  type WatcherFunction<T = IConfiguration> = (details: IWatchDetails<T>) => void;
2848
3397
 
2849
- class XHRMonitoringState {
2850
- openDone: boolean;
2851
- setRequestHeaderDone: boolean;
2852
- sendDone: boolean;
2853
- abortDone: boolean;
2854
- stateChangeAttached: boolean;
2855
- constructor();
2856
- }
2857
-
2858
3398
  interface XMLHttpRequestData {
2859
3399
  /**
2860
3400
  * The "Shared" XHR headers, avoids causing multiple instances
@@ -2867,7 +3407,7 @@ declare namespace ApplicationInsights {
2867
3407
  * The individual tracking data for each AI instance
2868
3408
  */
2869
3409
  i: {
2870
- [key: string]: ajaxRecord;
3410
+ [key: string]: IAjaxRecordInternal;
2871
3411
  };
2872
3412
  }
2873
3413