@microsoft/applicationinsights-common 2.8.0-nightly.2204-04 → 2.8.0-nightly.2204-07

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/browser/applicationinsights-common.integrity.json +9 -9
  2. package/browser/applicationinsights-common.js +566 -504
  3. package/browser/applicationinsights-common.js.map +1 -1
  4. package/browser/applicationinsights-common.min.js +2 -2
  5. package/browser/applicationinsights-common.min.js.map +1 -1
  6. package/dist/applicationinsights-common.api.json +1206 -399
  7. package/dist/applicationinsights-common.api.md +105 -28
  8. package/dist/applicationinsights-common.d.ts +169 -31
  9. package/dist/applicationinsights-common.js +566 -504
  10. package/dist/applicationinsights-common.js.map +1 -1
  11. package/dist/applicationinsights-common.min.js +2 -2
  12. package/dist/applicationinsights-common.min.js.map +1 -1
  13. package/dist/applicationinsights-common.rollup.d.ts +169 -31
  14. package/dist-esm/ConnectionStringParser.js +1 -1
  15. package/dist-esm/Constants.js +1 -1
  16. package/dist-esm/DomHelperFuncs.js +1 -1
  17. package/dist-esm/Enums.js +1 -1
  18. package/dist-esm/HelperFuncs.js +1 -1
  19. package/dist-esm/Interfaces/ConnectionString.js +1 -1
  20. package/dist-esm/Interfaces/Context/IApplication.js +1 -1
  21. package/dist-esm/Interfaces/Context/IDevice.js +1 -1
  22. package/dist-esm/Interfaces/Context/IInternal.js +1 -1
  23. package/dist-esm/Interfaces/Context/ILocation.js +1 -1
  24. package/dist-esm/Interfaces/Context/IOperatingSystem.js +1 -1
  25. package/dist-esm/Interfaces/Context/ISample.js +1 -1
  26. package/dist-esm/Interfaces/Context/ISession.js +1 -1
  27. package/dist-esm/Interfaces/Context/ITelemetryTrace.js +1 -1
  28. package/dist-esm/Interfaces/Context/IUser.js +1 -1
  29. package/dist-esm/Interfaces/Context/IWeb.js +1 -1
  30. package/dist-esm/Interfaces/Contracts/AvailabilityData.js +1 -1
  31. package/dist-esm/Interfaces/Contracts/ContextTagKeys.js +1 -1
  32. package/dist-esm/Interfaces/Contracts/DataPointType.js +1 -1
  33. package/dist-esm/Interfaces/Contracts/DependencyKind.js +1 -1
  34. package/dist-esm/Interfaces/Contracts/DependencySourceType.js +1 -1
  35. package/dist-esm/Interfaces/Contracts/IBase.js +1 -1
  36. package/dist-esm/Interfaces/Contracts/IData.js +1 -1
  37. package/dist-esm/Interfaces/Contracts/IDataPoint.js +1 -1
  38. package/dist-esm/Interfaces/Contracts/IDomain.js +1 -1
  39. package/dist-esm/Interfaces/Contracts/IEnvelope.js +1 -1
  40. package/dist-esm/Interfaces/Contracts/IEventData.js +1 -1
  41. package/dist-esm/Interfaces/Contracts/IExceptionData.js +1 -1
  42. package/dist-esm/Interfaces/Contracts/IExceptionDetails.js +1 -1
  43. package/dist-esm/Interfaces/Contracts/IMessageData.js +1 -1
  44. package/dist-esm/Interfaces/Contracts/IMetricData.js +1 -1
  45. package/dist-esm/Interfaces/Contracts/IPageViewData.js +1 -1
  46. package/dist-esm/Interfaces/Contracts/IPageViewPerfData.js +1 -1
  47. package/dist-esm/Interfaces/Contracts/IRemoteDependencyData.js +1 -1
  48. package/dist-esm/Interfaces/Contracts/IStackFrame.js +1 -1
  49. package/dist-esm/Interfaces/Contracts/RequestData.js +1 -1
  50. package/dist-esm/Interfaces/Contracts/SeverityLevel.js +9 -10
  51. package/dist-esm/Interfaces/Contracts/SeverityLevel.js.map +1 -1
  52. package/dist-esm/Interfaces/IAppInsights.js +1 -1
  53. package/dist-esm/Interfaces/IChannelControlsAI.js +1 -1
  54. package/dist-esm/Interfaces/IConfig.js +1 -1
  55. package/dist-esm/Interfaces/ICorrelationConfig.js +1 -1
  56. package/dist-esm/Interfaces/IDependencyTelemetry.js +1 -1
  57. package/dist-esm/Interfaces/IEventTelemetry.js +1 -1
  58. package/dist-esm/Interfaces/IExceptionTelemetry.js +1 -1
  59. package/dist-esm/Interfaces/IMetricTelemetry.js +1 -1
  60. package/dist-esm/Interfaces/IPageViewPerformanceTelemetry.js +1 -1
  61. package/dist-esm/Interfaces/IPageViewTelemetry.js +1 -1
  62. package/dist-esm/Interfaces/IPartC.js +1 -1
  63. package/dist-esm/Interfaces/IPropertiesPlugin.js +1 -1
  64. package/dist-esm/Interfaces/IRequestContext.js +1 -1
  65. package/dist-esm/Interfaces/ITelemetryContext.js +1 -1
  66. package/dist-esm/Interfaces/ITraceParent.js +8 -0
  67. package/dist-esm/Interfaces/ITraceParent.js.map +1 -0
  68. package/dist-esm/Interfaces/ITraceTelemetry.js +1 -1
  69. package/dist-esm/Interfaces/PartAExtensions.js +1 -1
  70. package/dist-esm/Interfaces/Telemetry/IEnvelope.js +1 -1
  71. package/dist-esm/Interfaces/Telemetry/ISerializable.js +1 -1
  72. package/dist-esm/RequestResponseHeaders.js +13 -12
  73. package/dist-esm/RequestResponseHeaders.js.map +1 -1
  74. package/dist-esm/StorageHelperFuncs.js +12 -12
  75. package/dist-esm/StorageHelperFuncs.js.map +1 -1
  76. package/dist-esm/Telemetry/Common/Data.js +1 -1
  77. package/dist-esm/Telemetry/Common/DataPoint.js +1 -1
  78. package/dist-esm/Telemetry/Common/DataSanitizer.js +9 -9
  79. package/dist-esm/Telemetry/Common/DataSanitizer.js.map +1 -1
  80. package/dist-esm/Telemetry/Common/Envelope.js +1 -1
  81. package/dist-esm/Telemetry/Event.js +1 -1
  82. package/dist-esm/Telemetry/Exception.js +1 -1
  83. package/dist-esm/Telemetry/Metric.js +1 -1
  84. package/dist-esm/Telemetry/PageView.js +1 -1
  85. package/dist-esm/Telemetry/PageViewPerformance.js +1 -1
  86. package/dist-esm/Telemetry/RemoteDependencyData.js +1 -1
  87. package/dist-esm/Telemetry/Trace.js +1 -1
  88. package/dist-esm/TelemetryItemCreator.js +42 -32
  89. package/dist-esm/TelemetryItemCreator.js.map +1 -1
  90. package/dist-esm/UrlHelperFuncs.js +1 -1
  91. package/dist-esm/Util.js +2 -2
  92. package/dist-esm/Util.js.map +1 -1
  93. package/dist-esm/W3cTraceParent.js +192 -0
  94. package/dist-esm/W3cTraceParent.js.map +1 -0
  95. package/dist-esm/applicationinsights-common.js +3 -2
  96. package/dist-esm/applicationinsights-common.js.map +1 -1
  97. package/package.json +2 -2
  98. package/src/Enums.ts +2 -3
  99. package/src/Interfaces/Contracts/SeverityLevel.ts +15 -2
  100. package/src/Interfaces/IConfig.ts +2 -9
  101. package/src/Interfaces/ITraceParent.ts +38 -0
  102. package/src/RequestResponseHeaders.ts +38 -2
  103. package/src/StorageHelperFuncs.ts +11 -11
  104. package/src/Telemetry/Common/DataSanitizer.ts +10 -10
  105. package/src/Telemetry/PageViewPerformance.ts +1 -1
  106. package/src/TelemetryItemCreator.ts +56 -44
  107. package/src/Util.ts +3 -3
  108. package/src/W3cTraceParent.ts +219 -0
  109. package/src/applicationinsights-common.ts +8 -3
  110. package/types/Enums.d.ts +2 -9
  111. package/types/Interfaces/Contracts/SeverityLevel.d.ts +6 -1
  112. package/types/Interfaces/IConfig.d.ts +3 -9
  113. package/types/Interfaces/ITraceParent.d.ts +32 -0
  114. package/types/RequestResponseHeaders.d.ts +31 -1
  115. package/types/Telemetry/Common/DataSanitizer.d.ts +3 -3
  116. package/types/TelemetryItemCreator.d.ts +15 -5
  117. package/types/W3cTraceParent.d.ts +59 -0
  118. package/types/applicationinsights-common.d.ts +5 -3
@@ -1,7 +1,7 @@
1
1
  // Copyright (c) Microsoft Corporation. All rights reserved.
2
2
  // Licensed under the MIT License.
3
3
 
4
- import { IDiagnosticLogger, eLoggingSeverity, _InternalMessageId, hasJSON, getJSON, objForEachKey, isObject, strTrim, _throwInternal } from "@microsoft/applicationinsights-core-js";
4
+ import { IDiagnosticLogger, eLoggingSeverity, _eInternalMessageId, hasJSON, getJSON, objForEachKey, isObject, strTrim, _throwInternal } from "@microsoft/applicationinsights-core-js";
5
5
 
6
6
  export const enum DataSanitizerValues {
7
7
  /**
@@ -68,7 +68,7 @@ export function dataSanitizeKey(logger: IDiagnosticLogger, name: any) {
68
68
  nameTrunc = name.substring(0, DataSanitizerValues.MAX_NAME_LENGTH);
69
69
  _throwInternal(logger,
70
70
  eLoggingSeverity.WARNING,
71
- _InternalMessageId.NameTooLong,
71
+ _eInternalMessageId.NameTooLong,
72
72
  "name is too long. It has been truncated to " + DataSanitizerValues.MAX_NAME_LENGTH + " characters.",
73
73
  { name }, true);
74
74
  }
@@ -86,7 +86,7 @@ export function dataSanitizeString(logger: IDiagnosticLogger, value: any, maxLen
86
86
  valueTrunc = value.toString().substring(0, maxLength);
87
87
  _throwInternal(logger,
88
88
  eLoggingSeverity.WARNING,
89
- _InternalMessageId.StringValueTooLong,
89
+ _eInternalMessageId.StringValueTooLong,
90
90
  "string value is too long. It has been truncated to " + maxLength + " characters.",
91
91
  { value }, true);
92
92
  }
@@ -96,7 +96,7 @@ export function dataSanitizeString(logger: IDiagnosticLogger, value: any, maxLen
96
96
  }
97
97
 
98
98
  export function dataSanitizeUrl(logger: IDiagnosticLogger, url: any) {
99
- return dataSanitizeInput(logger, url, DataSanitizerValues.MAX_URL_LENGTH, _InternalMessageId.UrlTooLong);
99
+ return dataSanitizeInput(logger, url, DataSanitizerValues.MAX_URL_LENGTH, _eInternalMessageId.UrlTooLong);
100
100
  }
101
101
 
102
102
  export function dataSanitizeMessage(logger: IDiagnosticLogger, message: any) {
@@ -105,7 +105,7 @@ export function dataSanitizeMessage(logger: IDiagnosticLogger, message: any) {
105
105
  if (message.length > DataSanitizerValues.MAX_MESSAGE_LENGTH) {
106
106
  messageTrunc = message.substring(0, DataSanitizerValues.MAX_MESSAGE_LENGTH);
107
107
  _throwInternal(logger,
108
- eLoggingSeverity.WARNING, _InternalMessageId.MessageTruncated,
108
+ eLoggingSeverity.WARNING, _eInternalMessageId.MessageTruncated,
109
109
  "message is too long, it has been truncated to " + DataSanitizerValues.MAX_MESSAGE_LENGTH + " characters.",
110
110
  { message },
111
111
  true);
@@ -123,7 +123,7 @@ export function dataSanitizeException(logger: IDiagnosticLogger, exception: any)
123
123
  if (value.length > DataSanitizerValues.MAX_EXCEPTION_LENGTH) {
124
124
  exceptionTrunc = value.substring(0, DataSanitizerValues.MAX_EXCEPTION_LENGTH);
125
125
  _throwInternal(logger,
126
- eLoggingSeverity.WARNING, _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + DataSanitizerValues.MAX_EXCEPTION_LENGTH + " characters.",
126
+ eLoggingSeverity.WARNING, _eInternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + DataSanitizerValues.MAX_EXCEPTION_LENGTH + " characters.",
127
127
  { exception }, true);
128
128
  }
129
129
  }
@@ -140,7 +140,7 @@ export function dataSanitizeProperties(logger: IDiagnosticLogger, properties: an
140
140
  try {
141
141
  value = getJSON().stringify(value);
142
142
  } catch (e) {
143
- _throwInternal(logger,eLoggingSeverity.WARNING, _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e}, true);
143
+ _throwInternal(logger,eLoggingSeverity.WARNING, _eInternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e}, true);
144
144
  }
145
145
  }
146
146
  value = dataSanitizeString(logger, value, DataSanitizerValues.MAX_PROPERTY_LENGTH);
@@ -168,10 +168,10 @@ export function dataSanitizeMeasurements(logger: IDiagnosticLogger, measurements
168
168
  }
169
169
 
170
170
  export function dataSanitizeId(logger: IDiagnosticLogger, id: string): string {
171
- return id ? dataSanitizeInput(logger, id, DataSanitizerValues.MAX_ID_LENGTH, _InternalMessageId.IdTooLong).toString() : id;
171
+ return id ? dataSanitizeInput(logger, id, DataSanitizerValues.MAX_ID_LENGTH, _eInternalMessageId.IdTooLong).toString() : id;
172
172
  }
173
173
 
174
- export function dataSanitizeInput(logger: IDiagnosticLogger, input: any, maxLength: number, _msgId: _InternalMessageId) {
174
+ export function dataSanitizeInput(logger: IDiagnosticLogger, input: any, maxLength: number, _msgId: _eInternalMessageId) {
175
175
  let inputTrunc : String;
176
176
  if (input) {
177
177
  input = strTrim(input);
@@ -248,7 +248,7 @@ export interface IDataSanitizer {
248
248
 
249
249
  sanitizeId: (logger: IDiagnosticLogger, id: string) => string;
250
250
 
251
- sanitizeInput: (logger: IDiagnosticLogger, input: any, maxLength: number, _msgId: _InternalMessageId) => any;
251
+ sanitizeInput: (logger: IDiagnosticLogger, input: any, maxLength: number, _msgId: _eInternalMessageId) => any;
252
252
 
253
253
  padNumber: (num: number) => string;
254
254
 
@@ -5,7 +5,7 @@ import { IPageViewPerfData } from "../Interfaces/Contracts/IPageViewPerfData";
5
5
  import { FieldType } from "../Enums";
6
6
  import { ISerializable } from "../Interfaces/Telemetry/ISerializable";
7
7
  import { dataSanitizeMeasurements, dataSanitizeProperties, dataSanitizeString, dataSanitizeUrl } from "./Common/DataSanitizer";
8
- import { IDiagnosticLogger, _InternalMessageId } from "@microsoft/applicationinsights-core-js";
8
+ import { IDiagnosticLogger } from "@microsoft/applicationinsights-core-js";
9
9
  import { IPageViewPerformanceTelemetry } from "../Interfaces/IPageViewPerformanceTelemetry";
10
10
  import { strNotSpecified } from "../Constants";
11
11
 
@@ -2,11 +2,64 @@
2
2
  // Licensed under the MIT License.
3
3
 
4
4
  import { dataSanitizeString } from "./Telemetry/Common/DataSanitizer";
5
- import { ITelemetryItem, IDiagnosticLogger, objForEachKey, isNullOrUndefined, toISOString } from "@microsoft/applicationinsights-core-js";
5
+ import { ITelemetryItem, IDiagnosticLogger, objForEachKey, isNullOrUndefined, toISOString, throwError } from "@microsoft/applicationinsights-core-js";
6
6
  import { strNotSpecified, strIkey } from "./Constants";
7
7
 
8
- export class TelemetryItemCreator {
9
8
 
9
+ /**
10
+ * Create a telemetry item that the 1DS channel understands
11
+ * @param item domain specific properties; part B
12
+ * @param baseType telemetry item type. ie PageViewData
13
+ * @param envelopeName name of the envelope. ie Microsoft.ApplicationInsights.<instrumentation key>.PageView
14
+ * @param customProperties user defined custom properties; part C
15
+ * @param systemProperties system properties that are added to the context; part A
16
+ * @returns ITelemetryItem that is sent to channel
17
+ */
18
+
19
+ export function createTelemetryItem<T>(item: T,
20
+ baseType: string,
21
+ envelopeName: string,
22
+ logger: IDiagnosticLogger,
23
+ customProperties?: { [key: string]: any },
24
+ systemProperties?: { [key: string]: any }): ITelemetryItem {
25
+
26
+ envelopeName = dataSanitizeString(logger, envelopeName) || strNotSpecified;
27
+
28
+ if (isNullOrUndefined(item) ||
29
+ isNullOrUndefined(baseType) ||
30
+ isNullOrUndefined(envelopeName)) {
31
+ throwError("Input doesn't contain all required fields");
32
+ }
33
+
34
+ let iKey = "";
35
+ if (item[strIkey]) {
36
+ iKey = item[strIkey];
37
+ delete item[strIkey];
38
+ }
39
+
40
+ const telemetryItem: ITelemetryItem = {
41
+ name: envelopeName,
42
+ time: toISOString(new Date()),
43
+ iKey: iKey, // this will be set in TelemetryContext
44
+ ext: systemProperties ? systemProperties : {}, // part A
45
+ tags: [],
46
+ data: {
47
+ },
48
+ baseType,
49
+ baseData: item // Part B
50
+ };
51
+
52
+ // Part C
53
+ if (!isNullOrUndefined(customProperties)) {
54
+ objForEachKey(customProperties, (prop, value) => {
55
+ telemetryItem.data[prop] = value;
56
+ });
57
+ }
58
+
59
+ return telemetryItem;
60
+ }
61
+
62
+ export class TelemetryItemCreator {
10
63
  /**
11
64
  * Create a telemetry item that the 1DS channel understands
12
65
  * @param item domain specific properties; part B
@@ -17,46 +70,5 @@ export class TelemetryItemCreator {
17
70
  * @returns ITelemetryItem that is sent to channel
18
71
  */
19
72
 
20
- public static create<T>(item: T,
21
- baseType: string,
22
- envelopeName: string,
23
- logger: IDiagnosticLogger,
24
- customProperties?: { [key: string]: any },
25
- systemProperties?: { [key: string]: any }): ITelemetryItem {
26
-
27
- envelopeName = dataSanitizeString(logger, envelopeName) || strNotSpecified;
28
-
29
- if (isNullOrUndefined(item) ||
30
- isNullOrUndefined(baseType) ||
31
- isNullOrUndefined(envelopeName)) {
32
- throw Error("Input doesn't contain all required fields");
33
- }
34
-
35
- let iKey = "";
36
- if (item[strIkey]) {
37
- iKey = item[strIkey];
38
- delete item[strIkey];
39
- }
40
-
41
- const telemetryItem: ITelemetryItem = {
42
- name: envelopeName,
43
- time: toISOString(new Date()),
44
- iKey: iKey, // this will be set in TelemetryContext
45
- ext: systemProperties ? systemProperties : {}, // part A
46
- tags: [],
47
- data: {
48
- },
49
- baseType,
50
- baseData: item // Part B
51
- };
52
-
53
- // Part C
54
- if (!isNullOrUndefined(customProperties)) {
55
- objForEachKey(customProperties, (prop, value) => {
56
- telemetryItem.data[prop] = value;
57
- });
58
- }
59
-
60
- return telemetryItem;
61
- }
73
+ public static create = createTelemetryItem;
62
74
  }
package/src/Util.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Licensed under the MIT License.
3
3
 
4
4
  import {
5
- _InternalMessageId, IDiagnosticLogger, IPlugin, getPerformance,
5
+ IDiagnosticLogger, IPlugin, getPerformance,
6
6
  getExceptionName as coreGetExceptionName, dumpObj,
7
7
  isNullOrUndefined, strTrim, random32, isArray, isError, isDate,
8
8
  newId, generateW3CId, toISOString, arrForEach, getIEVersion, attachEvent,
@@ -11,7 +11,7 @@ import {
11
11
  setCookie as coreSetCookie, deleteCookie as coreDeleteCookie,
12
12
  isBeaconsSupported
13
13
  } from "@microsoft/applicationinsights-core-js";
14
- import { RequestHeaders } from "./RequestResponseHeaders";
14
+ import { eRequestHeaders, RequestHeaders } from "./RequestResponseHeaders";
15
15
  import { dataSanitizeString } from "./Telemetry/Common/DataSanitizer";
16
16
  import { ICorrelationConfig } from "./Interfaces/ICorrelationConfig";
17
17
  import { createDomEvent } from "./DomHelperFuncs";
@@ -393,7 +393,7 @@ export const CorrelationIdHelper: ICorrelationIdHelper = {
393
393
  */
394
394
  getCorrelationContext(responseHeader: string) {
395
395
  if (responseHeader) {
396
- const correlationId = CorrelationIdHelper.getCorrelationContextValue(responseHeader, RequestHeaders.requestContextTargetKey);
396
+ const correlationId = CorrelationIdHelper.getCorrelationContextValue(responseHeader, RequestHeaders[eRequestHeaders.requestContextTargetKey]);
397
397
  if (correlationId && correlationId !== CorrelationIdHelper.correlationIdPrefix) {
398
398
  return correlationId;
399
399
  }
@@ -0,0 +1,219 @@
1
+ import { generateW3CId, getDocument, getPerformance, isArray, isString, strTrim } from "@microsoft/applicationinsights-core-js";
2
+ import { ITraceParent } from "./Interfaces/ITraceParent";
3
+
4
+ // using {0,16} for leading and trailing whitespace just to constrain the possible runtime of a random string
5
+ const TRACE_PARENT_REGEX = /^([\da-f]{2})-([\da-f]{32})-([\da-f]{16})-([\da-f]{2})(-[^\s]*)?$/;
6
+ const DEFAULT_VERSION = "00";
7
+ const INVALID_VERSION = "ff";
8
+ const INVALID_TRACE_ID = "00000000000000000000000000000000";
9
+ const INVALID_SPAN_ID = "0000000000000000";
10
+ const SAMPLED_FLAG = 0x01;
11
+
12
+ function _isValid(value: string, len: number, invalidValue?: string): boolean {
13
+ if (value && value.length === len && value !== invalidValue) {
14
+ return !!value.match(/^[\da-f]*$/);
15
+ }
16
+
17
+ return false;
18
+ }
19
+
20
+ function _formatValue(value: string, len: number, defValue: string): string {
21
+ if (_isValid(value, len)) {
22
+ return value;
23
+ }
24
+
25
+ return defValue;
26
+ }
27
+
28
+ function _formatFlags(value: number): string {
29
+ if (isNaN(value) || value < 0 || value > 255) {
30
+ value = 0x01;
31
+ }
32
+
33
+ let result = value.toString(16);
34
+ while (result.length < 2) {
35
+ result = "0" + result;
36
+ }
37
+
38
+ return result;
39
+ }
40
+
41
+ function _getTraceParentValue(values: any) {
42
+ if (values) {
43
+ for (var i = 0; i < values.length; i++) {
44
+ var value = values[i] as any;
45
+ if (value.name) {
46
+ if(value.name === "traceparent") {
47
+ return value;
48
+ }
49
+ }
50
+ }
51
+ }
52
+
53
+ return {};
54
+ }
55
+
56
+ /**
57
+ * Create a new ITraceParent instance using the provided values.
58
+ * @param traceId - The traceId to use, when invalid a new random W3C id will be generated.
59
+ * @param spanId - The parent/span id to use, a new random value will be generated if it is invalid.
60
+ * @param flags - The traceFlags to use, defaults to zero (0) if not supplied or invalid
61
+ * @param version - The version to used, defaults to version "01" if not supplied or invalid.
62
+ * @returns
63
+ */
64
+ export function createTraceParent(traceId?: string, spanId?: string, flags?: number, version?: string): ITraceParent {
65
+
66
+ return {
67
+ version: _isValid(version, 2, INVALID_VERSION) ? version : DEFAULT_VERSION,
68
+ traceId: isValidTraceId(traceId) ? traceId : generateW3CId(),
69
+ spanId: isValidSpanId(spanId) ? spanId : generateW3CId().substr(0, 16),
70
+ traceFlags: flags >= 0 && flags <= 0xFF ? flags : 1
71
+ };
72
+ }
73
+
74
+ /**
75
+ * Attempt to parse the provided string as a W3C TraceParent header value (https://www.w3.org/TR/trace-context/#traceparent-header)
76
+ *
77
+ * @param value
78
+ * @returns
79
+ */
80
+ export function parseTraceParent(value: string): ITraceParent {
81
+ if (!value) {
82
+ // Don't pass a null/undefined or empty string
83
+ return null;
84
+ }
85
+
86
+ if (isArray(value)) {
87
+ // The value may have been encoded on the page into an array so handle this automatically
88
+ value = value[0] || "";
89
+ }
90
+
91
+ if (!value || !isString(value) || value.length > 8192) {
92
+ // limit potential processing based on total length
93
+ return null;
94
+ }
95
+
96
+ // See https://www.w3.org/TR/trace-context/#versioning-of-traceparent
97
+ const match = TRACE_PARENT_REGEX.exec(strTrim(value));
98
+ if (!match || // No match
99
+ match[1] === INVALID_VERSION || // version ff is forbidden
100
+ match[2] === INVALID_TRACE_ID || // All zeros is considered to be invalid
101
+ match[3] === INVALID_SPAN_ID) { // All zeros is considered to be invalid
102
+ return null;
103
+ }
104
+
105
+ return {
106
+ version: match[1],
107
+ traceId: match[2],
108
+ spanId: match[3],
109
+ traceFlags: parseInt(match[4], 16)
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Is the provided W3c Trace Id a valid string representation, it must be a 32-character string
115
+ * of lowercase hexadecimal characters for example, 4bf92f3577b34da6a3ce929d0e0e4736.
116
+ * If all characters as zero (00000000000000000000000000000000) it will be considered an invalid value.
117
+ * @param value - The W3c trace Id to be validated
118
+ * @returns true if valid otherwise false
119
+ */
120
+ export function isValidTraceId(value: string): boolean {
121
+ return _isValid(value, 32, INVALID_TRACE_ID);
122
+ }
123
+
124
+ /**
125
+ * Is the provided W3c span id (aka. parent id) a valid string representation, it must be a 16-character
126
+ * string of lowercase hexadecimal characters, for example, 00f067aa0ba902b7.
127
+ * If all characters are zero (0000000000000000) this is considered an invalid value.
128
+ * @param value - The W3c span id to be validated
129
+ * @returns true if valid otherwise false
130
+ */
131
+ export function isValidSpanId(value: string): boolean {
132
+ return _isValid(value, 16, INVALID_SPAN_ID);
133
+ }
134
+
135
+ /**
136
+ * Validates that the provided ITraceParent instance conforms to the currently supported specifications
137
+ * @param value
138
+ * @returns
139
+ */
140
+ export function isValidTraceParent(value: ITraceParent) {
141
+ if (!value ||
142
+ !_isValid(value.version, 2, INVALID_VERSION) ||
143
+ !_isValid(value.traceId, 32, INVALID_TRACE_ID) ||
144
+ !_isValid(value.spanId, 16, INVALID_SPAN_ID) ||
145
+ !_isValid(_formatFlags(value.traceFlags), 2)) {
146
+
147
+ // Each known field must contain a valid value
148
+ return false;
149
+ }
150
+
151
+ return true;
152
+ }
153
+
154
+ /**
155
+ * Is the parsed traceParent indicating that the trace is currently sampled.
156
+ * @param value - The parsed traceParent value
157
+ * @returns
158
+ */
159
+ export function isSampledFlag(value: ITraceParent) {
160
+ if (isValidTraceParent(value)) {
161
+ return (value.traceFlags & SAMPLED_FLAG) === SAMPLED_FLAG;
162
+ }
163
+
164
+ return false;
165
+ }
166
+
167
+ /**
168
+ * Format the ITraceParent value as a string using the supported and know version formats.
169
+ * So even if the passed traceParent is a later version the string value returned from this
170
+ * function will convert it to only the known version formats.
171
+ * This currently only supports version "00" and invalid "ff"
172
+ * @param value - The parsed traceParent value
173
+ * @returns
174
+ */
175
+ export function formatTraceParent(value: ITraceParent) {
176
+ if (value) {
177
+ // Special Note: This only supports formatting as version 00, future versions should encode any known supported version
178
+ // So parsing a future version will populate the correct version value but reformatting will reduce it to version 00.
179
+ let flags = _formatFlags(value.traceFlags);
180
+ if (!_isValid(flags, 2)) {
181
+ flags = "01";
182
+ }
183
+
184
+ let version = value.version || DEFAULT_VERSION;
185
+ if (version !== "00" && version !== "ff") {
186
+ // Reduce version to "00"
187
+ version = DEFAULT_VERSION;
188
+ }
189
+
190
+ // Format as version 00
191
+ return `${version}-${_formatValue(value.traceId, 32, INVALID_TRACE_ID)}-${_formatValue(value.spanId, 16, INVALID_SPAN_ID)}-${flags}`;
192
+ }
193
+
194
+ return "";
195
+ }
196
+
197
+ /**
198
+ * Helper function to fetch the passed traceparent from the page, looking for it as a meta-tag or a Server-Timing header.
199
+ * @returns
200
+ */
201
+ export function findW3cTraceParent(): ITraceParent {
202
+ let traceParent: ITraceParent;
203
+ let doc = getDocument();
204
+ if (doc) {
205
+ // Look for a meta-tag called "traceparent"
206
+ traceParent = parseTraceParent(_getTraceParentValue(doc.querySelectorAll("meta")).content);
207
+ }
208
+
209
+ if (!traceParent) {
210
+ let perf = getPerformance();
211
+ if (perf) {
212
+ // Try looking for a server-timing header
213
+ let navPerf = perf.getEntriesByType("navigation") || [];
214
+ traceParent = parseTraceParent(_getTraceParentValue((navPerf.length > 0 ? navPerf[0] : {} as any).serverTiming).description);
215
+ }
216
+ }
217
+
218
+ return traceParent;
219
+ }
@@ -7,7 +7,7 @@ export {
7
7
  } from "./Util";
8
8
  export { parseConnectionString, ConnectionStringParser } from "./ConnectionStringParser";
9
9
  export { FieldType } from "./Enums";
10
- export { IRequestHeaders, RequestHeaders } from "./RequestResponseHeaders";
10
+ export { IRequestHeaders, RequestHeaders, eRequestHeaders } from "./RequestResponseHeaders";
11
11
  export { DisabledPropertyName, ProcessLegacy, SampleRate, HttpMethod, DEFAULT_BREEZE_ENDPOINT, strNotSpecified } from "./Constants";
12
12
  export { IData as AIData } from "./Interfaces/Contracts/IData";
13
13
  export { IBase as AIBase } from "./Interfaces/Contracts/IBase";
@@ -30,7 +30,7 @@ export { IPageViewPerformanceTelemetry, IPageViewPerformanceTelemetryInternal }
30
30
  export { Trace } from "./Telemetry/Trace";
31
31
  export { PageViewPerformance } from "./Telemetry/PageViewPerformance";
32
32
  export { Data } from "./Telemetry/Common/Data";
33
- export { SeverityLevel } from "./Interfaces/Contracts/SeverityLevel";
33
+ export { eSeverityLevel, SeverityLevel } from "./Interfaces/Contracts/SeverityLevel";
34
34
  export { IConfig, ConfigurationManager } from "./Interfaces/IConfig";
35
35
  export { IChannelControlsAI } from "./Interfaces/IChannelControlsAI";
36
36
  export { IContextTagKeys, ContextTagKeys } from "./Interfaces/Contracts/ContextTagKeys";
@@ -40,7 +40,7 @@ export {
40
40
  dataSanitizeException, dataSanitizeProperties, dataSanitizeMeasurements, dataSanitizeId, dataSanitizeInput,
41
41
  dsPadNumber
42
42
  } from "./Telemetry/Common/DataSanitizer";
43
- export { TelemetryItemCreator } from "./TelemetryItemCreator";
43
+ export { TelemetryItemCreator, createTelemetryItem } from "./TelemetryItemCreator";
44
44
  export { ICorrelationConfig } from "./Interfaces/ICorrelationConfig";
45
45
  export { IAppInsights } from "./Interfaces/IAppInsights";
46
46
  export { IWeb } from "./Interfaces/Context/IWeb";
@@ -66,6 +66,11 @@ export {
66
66
  utlCanUseSessionStorage, utlGetSessionStorageKeys, utlGetSessionStorage, utlSetSessionStorage, utlRemoveSessionStorage
67
67
  } from "./StorageHelperFuncs";
68
68
  export { urlParseUrl, urlGetAbsoluteUrl, urlGetPathName, urlGetCompleteUrl, urlParseHost, urlParseFullHost } from "./UrlHelperFuncs";
69
+ export { ITraceParent } from "./Interfaces/ITraceParent";
70
+ export {
71
+ createTraceParent, parseTraceParent, isValidTraceId, isValidSpanId, isValidTraceParent, isSampledFlag, formatTraceParent, findW3cTraceParent
72
+ } from "./W3cTraceParent";
73
+
69
74
  export const PropertiesPluginIdentifier = "AppInsightsPropertiesPlugin";
70
75
  export const BreezeChannelIdentifier = "AppInsightsChannelPlugin";
71
76
  export const AnalyticsPluginIdentifier = "ApplicationInsightsAnalytics";
package/types/Enums.d.ts CHANGED
@@ -5,10 +5,7 @@ export declare const enum eStorageType {
5
5
  LocalStorage = 0,
6
6
  SessionStorage = 1
7
7
  }
8
- export declare const StorageType: {
9
- LocalStorage: number;
10
- SessionStorage: number;
11
- };
8
+ export declare const StorageType: import("@microsoft/applicationinsights-core-js").EnumValue<typeof eStorageType>;
12
9
  export declare type StorageType = eStorageType | typeof StorageType;
13
10
  /**
14
11
  * Enum is used in aiDataContract to describe how fields are serialized.
@@ -34,9 +31,5 @@ export declare const enum eDistributedTracingModes {
34
31
  */
35
32
  W3C = 2
36
33
  }
37
- export declare const DistributedTracingModes: {
38
- AI: number;
39
- AI_AND_W3C: number;
40
- W3C: number;
41
- };
34
+ export declare const DistributedTracingModes: import("@microsoft/applicationinsights-core-js").EnumValue<typeof eDistributedTracingModes>;
42
35
  export declare type DistributedTracingModes = number | eDistributedTracingModes;
@@ -1,10 +1,15 @@
1
1
  /**
2
2
  * Defines the level of severity for the event.
3
3
  */
4
- export declare enum SeverityLevel {
4
+ export declare const enum eSeverityLevel {
5
5
  Verbose = 0,
6
6
  Information = 1,
7
7
  Warning = 2,
8
8
  Error = 3,
9
9
  Critical = 4
10
10
  }
11
+ /**
12
+ * Defines the level of severity for the event.
13
+ */
14
+ export declare const SeverityLevel: import("@microsoft/applicationinsights-core-js").EnumValue<typeof eSeverityLevel>;
15
+ export declare type SeverityLevel = number | eSeverityLevel;
@@ -1,4 +1,4 @@
1
- import { IConfiguration, ICookieMgrConfig, ICustomProperties } from "@microsoft/applicationinsights-core-js";
1
+ import { IConfiguration, ICustomProperties } from "@microsoft/applicationinsights-core-js";
2
2
  import { DistributedTracingModes } from "../Enums";
3
3
  import { IRequestContext } from "./IRequestContext";
4
4
  /**
@@ -140,7 +140,7 @@ export interface IConfig {
140
140
  */
141
141
  enableSessionStorageBuffer?: boolean;
142
142
  /**
143
- * @deprecated Use either disableCookiesUsage or specify a cookieMgrCfg with the enabled value set.
143
+ * @deprecated Use either disableCookiesUsage or specify a cookieCfg with the enabled value set.
144
144
  * If true, the SDK will not store or read any data from cookies. Default is false. As this field is being deprecated, when both
145
145
  * isCookieUseDisabled and disableCookiesUsage are used disableCookiesUsage will take precedent.
146
146
  * @defaultValue false
@@ -148,7 +148,7 @@ export interface IConfig {
148
148
  isCookieUseDisabled?: boolean;
149
149
  /**
150
150
  * If true, the SDK will not store or read any data from cookies. Default is false.
151
- * If you have also specified a cookieMgrCfg then enabled property (if specified) will take precedent over this value.
151
+ * If you have also specified a cookieCfg then enabled property (if specified) will take precedent over this value.
152
152
  * @defaultValue false
153
153
  */
154
154
  disableCookiesUsage?: boolean;
@@ -162,12 +162,6 @@ export interface IConfig {
162
162
  * @defaultValue ""
163
163
  */
164
164
  cookiePath?: string;
165
- /**
166
- * [Optional] A Cookie Manager configuration which includes hooks to allow interception of the get, set and delete cookie
167
- * operations. If this configuration is specified any specified enabled and domain properties will take precedence over the
168
- * cookieDomain and disableCookiesUsage values.
169
- */
170
- cookieMgrCfg?: ICookieMgrConfig;
171
165
  /**
172
166
  * Default false. If false, retry on 206 (partial success), 408 (timeout), 429 (too many requests), 500 (internal server error), 503 (service unavailable), and 0 (offline, only if detected)
173
167
  * @description
@@ -0,0 +1,32 @@
1
+ /**
2
+ * This interface represents the components of a W3C traceparent header
3
+ */
4
+ export interface ITraceParent {
5
+ /**
6
+ * The version of the definition, this MUST be a string with a length of 2 and only contain lowercase
7
+ * hexadecimal characters. A value of 'ff' is considered to be an invalid version.
8
+ */
9
+ version: string;
10
+ /**
11
+ * This is the ID of the whole trace forest and is used to uniquely identify a distributed trace
12
+ * through a system. It is represented as a 32-character string of lowercase hexadecimal characters,
13
+ * for example, 4bf92f3577b34da6a3ce929d0e0e4736.
14
+ * All characters as zero (00000000000000000000000000000000) is considered an invalid value.
15
+ */
16
+ traceId: string;
17
+ /**
18
+ * This is the ID of the current request as known by the caller (in some tracing systems, this is also
19
+ * known as the parent-id, where a span is the execution of a client request). It is represented as an
20
+ * 16-character string of lowercase hexadecimal characters, for example, 00f067aa0ba902b7.
21
+ * All bytes as zero (0000000000000000) is considered an invalid value.
22
+ */
23
+ spanId: string;
24
+ /**
25
+ * An 8-bit value of flags that controls tracing such as sampling, trace level, etc. These flags are
26
+ * recommendations given by the caller rather than strict rules to follow.
27
+ * As this is a bit field, you cannot interpret flags by decoding the hex value and looking at the resulting
28
+ * number. For example, a flag 00000001 could be encoded as 01 in hex, or 09 in hex if present with the flag
29
+ * 00001000. A common mistake in bit fields is forgetting to mask when interpreting flags.
30
+ */
31
+ traceFlags: number;
32
+ }
@@ -35,4 +35,34 @@ export interface IRequestHeaders {
35
35
  sdkContextHeaderAppIdRequest: string;
36
36
  requestContextHeaderLowerCase: string;
37
37
  }
38
- export declare const RequestHeaders: IRequestHeaders;
38
+ export declare const enum eRequestHeaders {
39
+ requestContextHeader = 0,
40
+ requestContextTargetKey = 1,
41
+ requestContextAppIdFormat = 2,
42
+ requestIdHeader = 3,
43
+ traceParentHeader = 4,
44
+ traceStateHeader = 5,
45
+ sdkContextHeader = 6,
46
+ sdkContextHeaderAppIdRequest = 7,
47
+ requestContextHeaderLowerCase = 8
48
+ }
49
+ export declare const RequestHeaders: IRequestHeaders & {
50
+ requestContextHeader: "Request-Context";
51
+ requestContextTargetKey: "appId";
52
+ requestContextAppIdFormat: "appId=cid-v1:";
53
+ requestIdHeader: "Request-Id";
54
+ traceParentHeader: "traceparent";
55
+ traceStateHeader: "tracestate";
56
+ sdkContextHeader: "Sdk-Context";
57
+ sdkContextHeaderAppIdRequest: "appId";
58
+ requestContextHeaderLowerCase: "request-context";
59
+ 0: "Request-Context";
60
+ 1: "appId";
61
+ 2: "appId=cid-v1:";
62
+ 3: "Request-Id";
63
+ 4: "traceparent";
64
+ 5: "tracestate";
65
+ 6: "Sdk-Context";
66
+ 7: "appId";
67
+ 8: "request-context";
68
+ };
@@ -1,4 +1,4 @@
1
- import { IDiagnosticLogger, _InternalMessageId } from "@microsoft/applicationinsights-core-js";
1
+ import { IDiagnosticLogger, _eInternalMessageId } from "@microsoft/applicationinsights-core-js";
2
2
  export declare const enum DataSanitizerValues {
3
3
  /**
4
4
  * Max length allowed for custom names.
@@ -38,7 +38,7 @@ export declare function dataSanitizeException(logger: IDiagnosticLogger, excepti
38
38
  export declare function dataSanitizeProperties(logger: IDiagnosticLogger, properties: any): any;
39
39
  export declare function dataSanitizeMeasurements(logger: IDiagnosticLogger, measurements: any): any;
40
40
  export declare function dataSanitizeId(logger: IDiagnosticLogger, id: string): string;
41
- export declare function dataSanitizeInput(logger: IDiagnosticLogger, input: any, maxLength: number, _msgId: _InternalMessageId): any;
41
+ export declare function dataSanitizeInput(logger: IDiagnosticLogger, input: any, maxLength: number, _msgId: _eInternalMessageId): any;
42
42
  export declare function dsPadNumber(num: number): string;
43
43
  export interface IDataSanitizer {
44
44
  /**
@@ -78,7 +78,7 @@ export interface IDataSanitizer {
78
78
  sanitizeProperties: (logger: IDiagnosticLogger, properties: any) => any;
79
79
  sanitizeMeasurements: (logger: IDiagnosticLogger, measurements: any) => any;
80
80
  sanitizeId: (logger: IDiagnosticLogger, id: string) => string;
81
- sanitizeInput: (logger: IDiagnosticLogger, input: any, maxLength: number, _msgId: _InternalMessageId) => any;
81
+ sanitizeInput: (logger: IDiagnosticLogger, input: any, maxLength: number, _msgId: _eInternalMessageId) => any;
82
82
  padNumber: (num: number) => string;
83
83
  /**
84
84
  * helper method to trim strings (IE8 does not implement String.prototype.trim)