@microsoft/applicationinsights-core-js 2.8.4-nightly.2205-08 → 2.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/applicationinsights-core-js.integrity.json +9 -9
- package/browser/applicationinsights-core-js.js +2008 -1811
- package/browser/applicationinsights-core-js.js.map +1 -1
- package/browser/applicationinsights-core-js.min.js +2 -2
- package/browser/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.api.json +1302 -199
- package/dist/applicationinsights-core-js.api.md +54 -0
- package/dist/applicationinsights-core-js.d.ts +174 -1
- package/dist/applicationinsights-core-js.js +2008 -1811
- package/dist/applicationinsights-core-js.js.map +1 -1
- package/dist/applicationinsights-core-js.min.js +2 -2
- package/dist/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.rollup.d.ts +174 -1
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js +2 -2
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseCore.js +25 -12
- package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +3 -3
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK/ChannelController.js +3 -3
- package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
- package/dist-esm/JavaScriptSDK/Constants.js +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +2 -2
- package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js +2 -2
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -1
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +1 -1
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +6 -6
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js +40 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/EventHelpers.js +1 -1
- package/dist-esm/JavaScriptSDK/HelperFuncs.js +1 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js +6 -6
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
- package/dist-esm/JavaScriptSDK/InternalConstants.js +1 -1
- package/dist-esm/JavaScriptSDK/NotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK/PerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +6 -6
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
- package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +54 -6
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +2 -2
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +2 -2
- package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +1 -1
- package/dist-esm/JavaScriptSDK/W3cTraceParent.js +172 -0
- package/dist-esm/JavaScriptSDK/W3cTraceParent.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +7 -7
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +86 -86
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDistributedTraceContext.js +8 -0
- package/dist-esm/JavaScriptSDK.Interfaces/IDistributedTraceContext.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITraceParent.js +8 -0
- package/dist-esm/JavaScriptSDK.Interfaces/ITraceParent.js.map +1 -0
- package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +1 -1
- package/dist-esm/applicationinsights-core-js.js +3 -2
- package/dist-esm/applicationinsights-core-js.js.map +1 -1
- package/package.json +67 -70
- package/src/JavaScriptSDK/BaseCore.ts +32 -1
- package/src/JavaScriptSDK/DataCacheHelper.ts +1 -1
- package/src/JavaScriptSDK/EnvUtils.ts +45 -0
- package/src/JavaScriptSDK/TelemetryHelpers.ts +57 -5
- package/src/JavaScriptSDK/W3cTraceParent.ts +196 -0
- package/src/JavaScriptSDK.Interfaces/IAppInsightsCore.ts +12 -0
- package/src/JavaScriptSDK.Interfaces/IDistributedTraceContext.ts +54 -0
- package/src/JavaScriptSDK.Interfaces/ITraceParent.ts +38 -0
- package/types/JavaScriptSDK/BaseCore.d.ts +10 -0
- package/types/JavaScriptSDK/EnvUtils.d.ts +10 -0
- package/types/JavaScriptSDK/TelemetryHelpers.d.ts +7 -0
- package/types/JavaScriptSDK/W3cTraceParent.d.ts +59 -0
- package/types/JavaScriptSDK.Interfaces/IAppInsightsCore.d.ts +10 -0
- package/types/JavaScriptSDK.Interfaces/IDistributedTraceContext.d.ts +43 -0
- package/types/JavaScriptSDK.Interfaces/ITraceParent.d.ts +32 -0
- package/types/applicationinsights-core-js.d.ts +4 -1
- package/types/tsdoc-metadata.json +1 -1
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { ITraceParent } from "../JavaScriptSDK.Interfaces/ITraceParent";
|
|
2
|
+
import { generateW3CId } from "./CoreUtils";
|
|
3
|
+
import { findMetaTag, findNamedServerTiming } from "./EnvUtils";
|
|
4
|
+
import { isArray, isString, strTrim } from "./HelperFuncs";
|
|
5
|
+
|
|
6
|
+
// using {0,16} for leading and trailing whitespace just to constrain the possible runtime of a random string
|
|
7
|
+
const TRACE_PARENT_REGEX = /^([\da-f]{2})-([\da-f]{32})-([\da-f]{16})-([\da-f]{2})(-[^\s]*)?$/;
|
|
8
|
+
const DEFAULT_VERSION = "00";
|
|
9
|
+
const INVALID_VERSION = "ff";
|
|
10
|
+
const INVALID_TRACE_ID = "00000000000000000000000000000000";
|
|
11
|
+
const INVALID_SPAN_ID = "0000000000000000";
|
|
12
|
+
const SAMPLED_FLAG = 0x01;
|
|
13
|
+
|
|
14
|
+
function _isValid(value: string, len: number, invalidValue?: string): boolean {
|
|
15
|
+
if (value && value.length === len && value !== invalidValue) {
|
|
16
|
+
return !!value.match(/^[\da-f]*$/);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function _formatValue(value: string, len: number, defValue: string): string {
|
|
23
|
+
if (_isValid(value, len)) {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return defValue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function _formatFlags(value: number): string {
|
|
31
|
+
if (isNaN(value) || value < 0 || value > 255) {
|
|
32
|
+
value = 0x01;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let result = value.toString(16);
|
|
36
|
+
while (result.length < 2) {
|
|
37
|
+
result = "0" + result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create a new ITraceParent instance using the provided values.
|
|
45
|
+
* @param traceId - The traceId to use, when invalid a new random W3C id will be generated.
|
|
46
|
+
* @param spanId - The parent/span id to use, a new random value will be generated if it is invalid.
|
|
47
|
+
* @param flags - The traceFlags to use, defaults to zero (0) if not supplied or invalid
|
|
48
|
+
* @param version - The version to used, defaults to version "01" if not supplied or invalid.
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
export function createTraceParent(traceId?: string, spanId?: string, flags?: number, version?: string): ITraceParent {
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
version: _isValid(version, 2, INVALID_VERSION) ? version : DEFAULT_VERSION,
|
|
55
|
+
traceId: isValidTraceId(traceId) ? traceId : generateW3CId(),
|
|
56
|
+
spanId: isValidSpanId(spanId) ? spanId : generateW3CId().substr(0, 16),
|
|
57
|
+
traceFlags: flags >= 0 && flags <= 0xFF ? flags : 1
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Attempt to parse the provided string as a W3C TraceParent header value (https://www.w3.org/TR/trace-context/#traceparent-header)
|
|
63
|
+
*
|
|
64
|
+
* @param value
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
export function parseTraceParent(value: string): ITraceParent {
|
|
68
|
+
if (!value) {
|
|
69
|
+
// Don't pass a null/undefined or empty string
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (isArray(value)) {
|
|
74
|
+
// The value may have been encoded on the page into an array so handle this automatically
|
|
75
|
+
value = value[0] || "";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (!value || !isString(value) || value.length > 8192) {
|
|
79
|
+
// limit potential processing based on total length
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// See https://www.w3.org/TR/trace-context/#versioning-of-traceparent
|
|
84
|
+
const match = TRACE_PARENT_REGEX.exec(strTrim(value));
|
|
85
|
+
if (!match || // No match
|
|
86
|
+
match[1] === INVALID_VERSION || // version ff is forbidden
|
|
87
|
+
match[2] === INVALID_TRACE_ID || // All zeros is considered to be invalid
|
|
88
|
+
match[3] === INVALID_SPAN_ID) { // All zeros is considered to be invalid
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
version: match[1],
|
|
94
|
+
traceId: match[2],
|
|
95
|
+
spanId: match[3],
|
|
96
|
+
traceFlags: parseInt(match[4], 16)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Is the provided W3c Trace Id a valid string representation, it must be a 32-character string
|
|
102
|
+
* of lowercase hexadecimal characters for example, 4bf92f3577b34da6a3ce929d0e0e4736.
|
|
103
|
+
* If all characters as zero (00000000000000000000000000000000) it will be considered an invalid value.
|
|
104
|
+
* @param value - The W3c trace Id to be validated
|
|
105
|
+
* @returns true if valid otherwise false
|
|
106
|
+
*/
|
|
107
|
+
export function isValidTraceId(value: string): boolean {
|
|
108
|
+
return _isValid(value, 32, INVALID_TRACE_ID);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Is the provided W3c span id (aka. parent id) a valid string representation, it must be a 16-character
|
|
113
|
+
* string of lowercase hexadecimal characters, for example, 00f067aa0ba902b7.
|
|
114
|
+
* If all characters are zero (0000000000000000) this is considered an invalid value.
|
|
115
|
+
* @param value - The W3c span id to be validated
|
|
116
|
+
* @returns true if valid otherwise false
|
|
117
|
+
*/
|
|
118
|
+
export function isValidSpanId(value: string): boolean {
|
|
119
|
+
return _isValid(value, 16, INVALID_SPAN_ID);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Validates that the provided ITraceParent instance conforms to the currently supported specifications
|
|
124
|
+
* @param value
|
|
125
|
+
* @returns
|
|
126
|
+
*/
|
|
127
|
+
export function isValidTraceParent(value: ITraceParent) {
|
|
128
|
+
if (!value ||
|
|
129
|
+
!_isValid(value.version, 2, INVALID_VERSION) ||
|
|
130
|
+
!_isValid(value.traceId, 32, INVALID_TRACE_ID) ||
|
|
131
|
+
!_isValid(value.spanId, 16, INVALID_SPAN_ID) ||
|
|
132
|
+
!_isValid(_formatFlags(value.traceFlags), 2)) {
|
|
133
|
+
|
|
134
|
+
// Each known field must contain a valid value
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Is the parsed traceParent indicating that the trace is currently sampled.
|
|
143
|
+
* @param value - The parsed traceParent value
|
|
144
|
+
* @returns
|
|
145
|
+
*/
|
|
146
|
+
export function isSampledFlag(value: ITraceParent) {
|
|
147
|
+
if (isValidTraceParent(value)) {
|
|
148
|
+
return (value.traceFlags & SAMPLED_FLAG) === SAMPLED_FLAG;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Format the ITraceParent value as a string using the supported and know version formats.
|
|
156
|
+
* So even if the passed traceParent is a later version the string value returned from this
|
|
157
|
+
* function will convert it to only the known version formats.
|
|
158
|
+
* This currently only supports version "00" and invalid "ff"
|
|
159
|
+
* @param value - The parsed traceParent value
|
|
160
|
+
* @returns
|
|
161
|
+
*/
|
|
162
|
+
export function formatTraceParent(value: ITraceParent) {
|
|
163
|
+
if (value) {
|
|
164
|
+
// Special Note: This only supports formatting as version 00, future versions should encode any known supported version
|
|
165
|
+
// So parsing a future version will populate the correct version value but reformatting will reduce it to version 00.
|
|
166
|
+
let flags = _formatFlags(value.traceFlags);
|
|
167
|
+
if (!_isValid(flags, 2)) {
|
|
168
|
+
flags = "01";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
let version = value.version || DEFAULT_VERSION;
|
|
172
|
+
if (version !== "00" && version !== "ff") {
|
|
173
|
+
// Reduce version to "00"
|
|
174
|
+
version = DEFAULT_VERSION;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Format as version 00
|
|
178
|
+
return `${version}-${_formatValue(value.traceId, 32, INVALID_TRACE_ID)}-${_formatValue(value.spanId, 16, INVALID_SPAN_ID)}-${flags}`;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return "";
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Helper function to fetch the passed traceparent from the page, looking for it as a meta-tag or a Server-Timing header.
|
|
186
|
+
* @returns
|
|
187
|
+
*/
|
|
188
|
+
export function findW3cTraceParent(): ITraceParent {
|
|
189
|
+
const name = "traceparent";
|
|
190
|
+
let traceParent: ITraceParent = parseTraceParent(findMetaTag(name));
|
|
191
|
+
if (!traceParent) {
|
|
192
|
+
traceParent = parseTraceParent(findNamedServerTiming(name))
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return traceParent;
|
|
196
|
+
}
|
|
@@ -14,6 +14,7 @@ import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "./IT
|
|
|
14
14
|
import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
|
|
15
15
|
import { UnloadHandler } from "../JavaScriptSDK/UnloadHandlerContainer";
|
|
16
16
|
import { SendRequestReason } from "../JavaScriptSDK.Enums/SendRequestReason";
|
|
17
|
+
import { IDistributedTraceContext } from "./IDistributedTraceContext";
|
|
17
18
|
|
|
18
19
|
export interface ILoadedPlugin<T extends IPlugin> {
|
|
19
20
|
plugin: T;
|
|
@@ -160,4 +161,15 @@ export interface IAppInsightsCore extends IPerfManagerProvider {
|
|
|
160
161
|
* @returns - true if the callback will be return after the flush is complete otherwise the caller should assume that any provided callback will never be called
|
|
161
162
|
*/
|
|
162
163
|
flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Gets the current distributed trace context for this instance if available
|
|
167
|
+
* @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
|
|
168
|
+
*/
|
|
169
|
+
getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Sets the current distributed trace context for this instance if available
|
|
173
|
+
*/
|
|
174
|
+
setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
|
|
163
175
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
export interface IDistributedTraceContext {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns the current name of the page
|
|
8
|
+
*/
|
|
9
|
+
getName(): string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Sets the current name of the page
|
|
13
|
+
* @param pageName
|
|
14
|
+
*/
|
|
15
|
+
setName(pageName: string): void;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
|
|
19
|
+
* Must be read from incoming headers or generated according to the W3C TraceContext specification,
|
|
20
|
+
* in a hex representation of 16-byte array. A.k.a. trace-id, TraceID or Distributed TraceID
|
|
21
|
+
*/
|
|
22
|
+
getTraceId(): string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Set the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
|
|
26
|
+
* Must be conform to the W3C TraceContext specification, in a hex representation of 16-byte array.
|
|
27
|
+
* A.k.a. trace-id, TraceID or Distributed TraceID https://www.w3.org/TR/trace-context/#trace-id
|
|
28
|
+
*/
|
|
29
|
+
setTraceId(newValue: string): void;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
|
|
33
|
+
* Also know as the parentId, used to link requests together
|
|
34
|
+
*/
|
|
35
|
+
getSpanId(): string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
|
|
39
|
+
* Also know as the parentId, used to link requests together
|
|
40
|
+
* https://www.w3.org/TR/trace-context/#parent-id
|
|
41
|
+
*/
|
|
42
|
+
setSpanId(newValue: string): void;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* An integer representation of the W3C TraceContext trace-flags.
|
|
46
|
+
*/
|
|
47
|
+
getTraceFlags(): number | undefined;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* https://www.w3.org/TR/trace-context/#trace-flags
|
|
51
|
+
* @param newValue
|
|
52
|
+
*/
|
|
53
|
+
setTraceFlags(newValue?: number): void;
|
|
54
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
+
// Licensed under the MIT License.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This interface represents the components of a W3C traceparent header
|
|
6
|
+
*/
|
|
7
|
+
export interface ITraceParent {
|
|
8
|
+
/**
|
|
9
|
+
* The version of the definition, this MUST be a string with a length of 2 and only contain lowercase
|
|
10
|
+
* hexadecimal characters. A value of 'ff' is considered to be an invalid version.
|
|
11
|
+
*/
|
|
12
|
+
version: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This is the ID of the whole trace forest and is used to uniquely identify a distributed trace
|
|
16
|
+
* through a system. It is represented as a 32-character string of lowercase hexadecimal characters,
|
|
17
|
+
* for example, 4bf92f3577b34da6a3ce929d0e0e4736.
|
|
18
|
+
* All characters as zero (00000000000000000000000000000000) is considered an invalid value.
|
|
19
|
+
*/
|
|
20
|
+
traceId: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* This is the ID of the current request as known by the caller (in some tracing systems, this is also
|
|
24
|
+
* known as the parent-id, where a span is the execution of a client request). It is represented as an
|
|
25
|
+
* 16-character string of lowercase hexadecimal characters, for example, 00f067aa0ba902b7.
|
|
26
|
+
* All bytes as zero (0000000000000000) is considered an invalid value.
|
|
27
|
+
*/
|
|
28
|
+
spanId: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* An 8-bit value of flags that controls tracing such as sampling, trace level, etc. These flags are
|
|
32
|
+
* recommendations given by the caller rather than strict rules to follow.
|
|
33
|
+
* As this is a bit field, you cannot interpret flags by decoding the hex value and looking at the resulting
|
|
34
|
+
* number. For example, a flag 00000001 could be encoded as 01 in hex, or 09 in hex if present with the flag
|
|
35
|
+
* 00001000. A common mistake in bit fields is forgetting to mask when interpreting flags.
|
|
36
|
+
*/
|
|
37
|
+
traceFlags: number;
|
|
38
|
+
}
|
|
@@ -14,6 +14,7 @@ import { UnloadHandler } from "./UnloadHandlerContainer";
|
|
|
14
14
|
import { ITelemetryUpdateState } from "../JavaScriptSDK.Interfaces/ITelemetryUpdateState";
|
|
15
15
|
import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
|
|
16
16
|
import { SendRequestReason } from "../JavaScriptSDK.Enums/SendRequestReason";
|
|
17
|
+
import { IDistributedTraceContext } from "../JavaScriptSDK.Interfaces/IDistributedTraceContext";
|
|
17
18
|
export declare class BaseCore implements IAppInsightsCore {
|
|
18
19
|
static defaultConfig: IConfiguration;
|
|
19
20
|
config: IConfiguration;
|
|
@@ -103,6 +104,15 @@ export declare class BaseCore implements IAppInsightsCore {
|
|
|
103
104
|
* @returns - true if the callback will be return after the flush is complete otherwise the caller should assume that any provided callback will never be called
|
|
104
105
|
*/
|
|
105
106
|
flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason): void;
|
|
107
|
+
/**
|
|
108
|
+
* Gets the current distributed trace context for this instance if available
|
|
109
|
+
* @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
|
|
110
|
+
*/
|
|
111
|
+
getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
|
|
112
|
+
/**
|
|
113
|
+
* Sets the current distributed trace context for this instance if available
|
|
114
|
+
*/
|
|
115
|
+
setTraceCtx(newTracectx: IDistributedTraceContext): void;
|
|
106
116
|
protected releaseQueue(): void;
|
|
107
117
|
/**
|
|
108
118
|
* Hook for Core extensions to allow them to update their own configuration before updating all of the plugins.
|
|
@@ -140,3 +140,13 @@ export declare function useXDomainRequest(): boolean | undefined;
|
|
|
140
140
|
* @returns True if supported, otherwise false
|
|
141
141
|
*/
|
|
142
142
|
export declare function isXhrSupported(): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Helper function to fetch the named meta-tag from the page.
|
|
145
|
+
* @param name
|
|
146
|
+
*/
|
|
147
|
+
export declare function findMetaTag(name: string): any;
|
|
148
|
+
/**
|
|
149
|
+
* Helper function to fetch the named server timing value from the page response (first navigation event).
|
|
150
|
+
* @param name
|
|
151
|
+
*/
|
|
152
|
+
export declare function findNamedServerTiming(name: string): any;
|
|
@@ -3,6 +3,7 @@ import { IProcessTelemetryContext, IProcessTelemetryUnloadContext } from "../Jav
|
|
|
3
3
|
import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
|
|
4
4
|
import { IUnloadableComponent } from "../JavaScriptSDK.Interfaces/IUnloadableComponent";
|
|
5
5
|
import { ITelemetryUnloadState } from "../JavaScriptSDK.Interfaces/ITelemetryUnloadState";
|
|
6
|
+
import { IDistributedTraceContext } from "../JavaScriptSDK.Interfaces/IDistributedTraceContext";
|
|
6
7
|
export interface IPluginState {
|
|
7
8
|
core?: IAppInsightsCore;
|
|
8
9
|
isInitialized?: boolean;
|
|
@@ -29,3 +30,9 @@ export declare function sortPlugins<T = IPlugin>(plugins: T[]): T[];
|
|
|
29
30
|
* @returns boolean - true if the plugin has or will call asyncCallback, this allows the plugin to perform any asynchronous operations.
|
|
30
31
|
*/
|
|
31
32
|
export declare function unloadComponents(components: any | IUnloadableComponent[], unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void): void | boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a IDistributedTraceContext which optionally also "sets" the value on a parent
|
|
35
|
+
* @param parentCtx - An optional parent distributed trace instance
|
|
36
|
+
* @returns A new IDistributedTraceContext instance that uses an internal temporary object
|
|
37
|
+
*/
|
|
38
|
+
export declare function createDistributedTraceContext(parentCtx?: IDistributedTraceContext): IDistributedTraceContext;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ITraceParent } from "../JavaScriptSDK.Interfaces/ITraceParent";
|
|
2
|
+
/**
|
|
3
|
+
* Create a new ITraceParent instance using the provided values.
|
|
4
|
+
* @param traceId - The traceId to use, when invalid a new random W3C id will be generated.
|
|
5
|
+
* @param spanId - The parent/span id to use, a new random value will be generated if it is invalid.
|
|
6
|
+
* @param flags - The traceFlags to use, defaults to zero (0) if not supplied or invalid
|
|
7
|
+
* @param version - The version to used, defaults to version "01" if not supplied or invalid.
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function createTraceParent(traceId?: string, spanId?: string, flags?: number, version?: string): ITraceParent;
|
|
11
|
+
/**
|
|
12
|
+
* Attempt to parse the provided string as a W3C TraceParent header value (https://www.w3.org/TR/trace-context/#traceparent-header)
|
|
13
|
+
*
|
|
14
|
+
* @param value
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseTraceParent(value: string): ITraceParent;
|
|
18
|
+
/**
|
|
19
|
+
* Is the provided W3c Trace Id a valid string representation, it must be a 32-character string
|
|
20
|
+
* of lowercase hexadecimal characters for example, 4bf92f3577b34da6a3ce929d0e0e4736.
|
|
21
|
+
* If all characters as zero (00000000000000000000000000000000) it will be considered an invalid value.
|
|
22
|
+
* @param value - The W3c trace Id to be validated
|
|
23
|
+
* @returns true if valid otherwise false
|
|
24
|
+
*/
|
|
25
|
+
export declare function isValidTraceId(value: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Is the provided W3c span id (aka. parent id) a valid string representation, it must be a 16-character
|
|
28
|
+
* string of lowercase hexadecimal characters, for example, 00f067aa0ba902b7.
|
|
29
|
+
* If all characters are zero (0000000000000000) this is considered an invalid value.
|
|
30
|
+
* @param value - The W3c span id to be validated
|
|
31
|
+
* @returns true if valid otherwise false
|
|
32
|
+
*/
|
|
33
|
+
export declare function isValidSpanId(value: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Validates that the provided ITraceParent instance conforms to the currently supported specifications
|
|
36
|
+
* @param value
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
export declare function isValidTraceParent(value: ITraceParent): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Is the parsed traceParent indicating that the trace is currently sampled.
|
|
42
|
+
* @param value - The parsed traceParent value
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
export declare function isSampledFlag(value: ITraceParent): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Format the ITraceParent value as a string using the supported and know version formats.
|
|
48
|
+
* So even if the passed traceParent is a later version the string value returned from this
|
|
49
|
+
* function will convert it to only the known version formats.
|
|
50
|
+
* This currently only supports version "00" and invalid "ff"
|
|
51
|
+
* @param value - The parsed traceParent value
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
export declare function formatTraceParent(value: ITraceParent): string;
|
|
55
|
+
/**
|
|
56
|
+
* Helper function to fetch the passed traceparent from the page, looking for it as a meta-tag or a Server-Timing header.
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
export declare function findW3cTraceParent(): ITraceParent;
|
|
@@ -12,6 +12,7 @@ import { ITelemetryInitializerHandler, TelemetryInitializerFunction } from "./IT
|
|
|
12
12
|
import { ITelemetryUnloadState } from "./ITelemetryUnloadState";
|
|
13
13
|
import { UnloadHandler } from "../JavaScriptSDK/UnloadHandlerContainer";
|
|
14
14
|
import { SendRequestReason } from "../JavaScriptSDK.Enums/SendRequestReason";
|
|
15
|
+
import { IDistributedTraceContext } from "./IDistributedTraceContext";
|
|
15
16
|
export interface ILoadedPlugin<T extends IPlugin> {
|
|
16
17
|
plugin: T;
|
|
17
18
|
/**
|
|
@@ -120,4 +121,13 @@ export interface IAppInsightsCore extends IPerfManagerProvider {
|
|
|
120
121
|
* @returns - true if the callback will be return after the flush is complete otherwise the caller should assume that any provided callback will never be called
|
|
121
122
|
*/
|
|
122
123
|
flush(isAsync?: boolean, callBack?: (flushComplete?: boolean) => void, sendReason?: SendRequestReason, cbTimeout?: number): boolean | void;
|
|
124
|
+
/**
|
|
125
|
+
* Gets the current distributed trace context for this instance if available
|
|
126
|
+
* @param createNew - Optional flag to create a new instance if one doesn't currently exist, defaults to true
|
|
127
|
+
*/
|
|
128
|
+
getTraceCtx(createNew?: boolean): IDistributedTraceContext | null;
|
|
129
|
+
/**
|
|
130
|
+
* Sets the current distributed trace context for this instance if available
|
|
131
|
+
*/
|
|
132
|
+
setTraceCtx(newTraceCtx: IDistributedTraceContext | null | undefined): void;
|
|
123
133
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface IDistributedTraceContext {
|
|
2
|
+
/**
|
|
3
|
+
* Returns the current name of the page
|
|
4
|
+
*/
|
|
5
|
+
getName(): string;
|
|
6
|
+
/**
|
|
7
|
+
* Sets the current name of the page
|
|
8
|
+
* @param pageName
|
|
9
|
+
*/
|
|
10
|
+
setName(pageName: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
|
|
13
|
+
* Must be read from incoming headers or generated according to the W3C TraceContext specification,
|
|
14
|
+
* in a hex representation of 16-byte array. A.k.a. trace-id, TraceID or Distributed TraceID
|
|
15
|
+
*/
|
|
16
|
+
getTraceId(): string;
|
|
17
|
+
/**
|
|
18
|
+
* Set the unique identifier for a trace. All requests / spans from the same trace share the same traceId.
|
|
19
|
+
* Must be conform to the W3C TraceContext specification, in a hex representation of 16-byte array.
|
|
20
|
+
* A.k.a. trace-id, TraceID or Distributed TraceID https://www.w3.org/TR/trace-context/#trace-id
|
|
21
|
+
*/
|
|
22
|
+
setTraceId(newValue: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
|
|
25
|
+
* Also know as the parentId, used to link requests together
|
|
26
|
+
*/
|
|
27
|
+
getSpanId(): string;
|
|
28
|
+
/**
|
|
29
|
+
* Self-generated 8-bytes identifier of the incoming request. Must be a hex representation of 8-byte array.
|
|
30
|
+
* Also know as the parentId, used to link requests together
|
|
31
|
+
* https://www.w3.org/TR/trace-context/#parent-id
|
|
32
|
+
*/
|
|
33
|
+
setSpanId(newValue: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* An integer representation of the W3C TraceContext trace-flags.
|
|
36
|
+
*/
|
|
37
|
+
getTraceFlags(): number | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* https://www.w3.org/TR/trace-context/#trace-flags
|
|
40
|
+
* @param newValue
|
|
41
|
+
*/
|
|
42
|
+
setTraceFlags(newValue?: number): void;
|
|
43
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -21,7 +21,7 @@ export { CoreUtils, ICoreUtils, EventHelper, IEventHelper, Undefined, newGuid, p
|
|
|
21
21
|
export { isTypeof, isUndefined, isNullOrUndefined, hasOwnProperty, isObject, isFunction, normalizeJsName, objForEachKey, strEndsWith, strStartsWith, isDate, isArray, isError, isString, isNumber, isBoolean, toISOString, arrForEach, arrIndexOf, arrMap, arrReduce, strTrim, objKeys, objDefineAccessors, dateNow, getExceptionName, throwError, strContains, isSymbol, setValue, getSetValue, isNotTruthy, isTruthy, proxyAssign, proxyFunctions, proxyFunctionAs, createClassFromInterface, optimizeObject, isNotUndefined, isNotNullOrUndefined, objFreeze, objSeal, objExtend, objToString, deepFreeze } from "./JavaScriptSDK/HelperFuncs";
|
|
22
22
|
export { EnumValue, createEnumStyle, EnumMap, createEnumMap, createValueMap } from "./JavaScriptSDK.Enums/EnumHelperFuncs";
|
|
23
23
|
export { attachEvent, detachEvent, addEventHandler, addEventListeners, addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener, removeEventHandler, removeEventListeners, removePageUnloadEventListener, removePageHideEventListener, removePageShowEventListener, eventOn, eventOff, mergeEvtNamespace, _IRegisteredEvents, __getRegisteredEvents } from "./JavaScriptSDK/EventHelpers";
|
|
24
|
-
export { getGlobalInst, hasWindow, getWindow, hasDocument, getDocument, getCrypto, getMsCrypto, hasNavigator, getNavigator, hasHistory, getHistory, getLocation, getPerformance, hasJSON, getJSON, isReactNative, getConsole, dumpObj, isIE, getIEVersion, isSafari, setEnableEnvMocks, isBeaconsSupported, isFetchSupported, useXDomainRequest, isXhrSupported } from "./JavaScriptSDK/EnvUtils";
|
|
24
|
+
export { getGlobalInst, hasWindow, getWindow, hasDocument, getDocument, getCrypto, getMsCrypto, hasNavigator, getNavigator, hasHistory, getHistory, getLocation, getPerformance, hasJSON, getJSON, isReactNative, getConsole, dumpObj, isIE, getIEVersion, isSafari, setEnableEnvMocks, isBeaconsSupported, isFetchSupported, useXDomainRequest, isXhrSupported, findMetaTag, findNamedServerTiming } from "./JavaScriptSDK/EnvUtils";
|
|
25
25
|
export { getGlobal, objCreateFn as objCreate, strShimPrototype as strPrototype, strShimFunction as strFunction, strShimUndefined as strUndefined, strShimObject as strObject } from "@microsoft/applicationinsights-shims";
|
|
26
26
|
export { NotificationManager } from "./JavaScriptSDK/NotificationManager";
|
|
27
27
|
export { INotificationManager } from "./JavaScriptSDK.Interfaces/INotificationManager";
|
|
@@ -42,3 +42,6 @@ export { createUniqueNamespace } from "./JavaScriptSDK/DataCacheHelper";
|
|
|
42
42
|
export { UnloadHandler, IUnloadHandlerContainer, createUnloadHandlerContainer } from "./JavaScriptSDK/UnloadHandlerContainer";
|
|
43
43
|
export { ITelemetryUpdateState } from "./JavaScriptSDK.Interfaces/ITelemetryUpdateState";
|
|
44
44
|
export { ITelemetryUnloadState } from "./JavaScriptSDK.Interfaces/ITelemetryUnloadState";
|
|
45
|
+
export { IDistributedTraceContext } from "./JavaScriptSDK.Interfaces/IDistributedTraceContext";
|
|
46
|
+
export { ITraceParent } from "./JavaScriptSDK.Interfaces/ITraceParent";
|
|
47
|
+
export { createTraceParent, parseTraceParent, isValidTraceId, isValidSpanId, isValidTraceParent, isSampledFlag, formatTraceParent, findW3cTraceParent } from "./JavaScriptSDK/W3cTraceParent";
|