@atlaskit/react-ufo 5.0.12 → 5.1.0
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/CHANGELOG.md +21 -0
- package/dist/cjs/experience-trace-id-context/context-manager.js +180 -0
- package/dist/cjs/experience-trace-id-context/index.js +67 -11
- package/dist/cjs/interaction-metrics-init/index.js +15 -6
- package/dist/cjs/vc/index.js +6 -6
- package/dist/cjs/vc/vc-observer/observers/ssr-placeholders/index.js +0 -3
- package/dist/es2019/experience-trace-id-context/context-manager.js +142 -0
- package/dist/es2019/experience-trace-id-context/index.js +65 -9
- package/dist/es2019/interaction-metrics-init/index.js +15 -6
- package/dist/es2019/vc/index.js +6 -6
- package/dist/es2019/vc/vc-observer/observers/ssr-placeholders/index.js +0 -3
- package/dist/esm/experience-trace-id-context/context-manager.js +172 -0
- package/dist/esm/experience-trace-id-context/index.js +67 -11
- package/dist/esm/interaction-metrics-init/index.js +15 -6
- package/dist/esm/vc/index.js +6 -6
- package/dist/esm/vc/vc-observer/observers/ssr-placeholders/index.js +0 -3
- package/dist/types/common/react-ufo-payload-schema.d.ts +5 -0
- package/dist/types/config/index.d.ts +6 -0
- package/dist/types/experience-trace-id-context/context-manager.d.ts +65 -0
- package/dist/types-ts4.5/common/react-ufo-payload-schema.d.ts +5 -0
- package/dist/types-ts4.5/config/index.d.ts +6 -0
- package/dist/types-ts4.5/experience-trace-id-context/context-manager.d.ts +65 -0
- package/package.json +6 -5
- package/dist/cjs/vc/vc-observer-new/viewport-observer/utils/get-mutated-elements.js +0 -68
- package/dist/es2019/vc/vc-observer-new/viewport-observer/utils/get-mutated-elements.js +0 -45
- package/dist/esm/vc/vc-observer-new/viewport-observer/utils/get-mutated-elements.js +0 -61
- package/dist/types/vc/vc-observer-new/viewport-observer/utils/get-mutated-elements.d.ts +0 -6
- package/dist/types-ts4.5/vc/vc-observer-new/viewport-observer/utils/get-mutated-elements.d.ts +0 -6
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { context } from '@opentelemetry/api';
|
|
1
2
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
3
|
import { startLighthouseObserver } from '../additional-payload';
|
|
3
4
|
import { setUFOConfig } from '../config';
|
|
4
5
|
import { experimentalVC, sinkExperimentalHandler } from '../create-experimental-interaction-metrics-payload';
|
|
5
6
|
import { sinkExtraSearchPageInteractionHandler } from '../create-extra-search-page-interaction-payload';
|
|
7
|
+
import { setContextManager, UFOContextManager } from '../experience-trace-id-context/context-manager';
|
|
6
8
|
import { setupHiddenTimingCapture } from '../hidden-timing';
|
|
7
9
|
import { interactionExtraMetrics, postInteractionLog, sinkInteractionHandler, sinkPostInteractionLogHandler } from '../interaction-metrics';
|
|
8
10
|
import { getPerformanceObserver } from '../interactions-performance-observer';
|
|
@@ -131,6 +133,15 @@ export function init(analyticsWebClientAsync, config) {
|
|
|
131
133
|
initialisePressureObserver();
|
|
132
134
|
initialiseMemoryObserver();
|
|
133
135
|
setUFOConfig(config);
|
|
136
|
+
if (fg('platform_ufo_enable_otel_context_manager')) {
|
|
137
|
+
// Configure global OTel context manager
|
|
138
|
+
const contextManager = new UFOContextManager();
|
|
139
|
+
// set the contextmanager somewhere we can reference it later
|
|
140
|
+
setContextManager(contextManager);
|
|
141
|
+
// Register the context manager with the global OTel API
|
|
142
|
+
contextManager.enable();
|
|
143
|
+
context.setGlobalContextManager(contextManager);
|
|
144
|
+
}
|
|
134
145
|
if ((_config$vc = config.vc) !== null && _config$vc !== void 0 && _config$vc.enabled) {
|
|
135
146
|
var _config$experimentalI, _config$extraInteract;
|
|
136
147
|
const vcOptions = {
|
|
@@ -164,11 +175,10 @@ export function init(analyticsWebClientAsync, config) {
|
|
|
164
175
|
Promise.all([analyticsWebClientAsync, import( /* webpackChunkName: "create-payloads" */'../create-payload'), import( /* webpackChunkName: "create-post-interaction-log-payload" */'../create-post-interaction-log-payload'), import( /* webpackChunkName: "create-interaction-extra-metrics-payload" */'../create-interaction-extra-metrics-payload'), import( /* webpackChunkName: "create-terminal-error-payload@atlaskit-internal_terminal_errors" */'../create-terminal-error-payload')]).then(([awc, payloadPackage, createPostInteractionLogPayloadPackage, createInteractionExtraMetricsPayloadPackage, createTerminalErrorPayloadPackage]) => {
|
|
165
176
|
if (awc.getAnalyticsWebClientPromise) {
|
|
166
177
|
awc.getAnalyticsWebClientPromise().then(client => {
|
|
167
|
-
var _config$experimentalI2, _config$postInteracti, _config$extraInteract2, _config$extraSearchPa;
|
|
178
|
+
var _config$terminalError, _config$experimentalI2, _config$postInteracti, _config$extraInteract2, _config$extraSearchPa;
|
|
168
179
|
const instance = client.getInstance();
|
|
169
180
|
sinkInteraction(instance, payloadPackage);
|
|
170
|
-
|
|
171
|
-
if (fg('platform_ufo_enable_terminal_errors')) {
|
|
181
|
+
if (config !== null && config !== void 0 && (_config$terminalError = config.terminalErrors) !== null && _config$terminalError !== void 0 && _config$terminalError.enabled && fg('platform_ufo_enable_terminal_errors')) {
|
|
172
182
|
sinkTerminalErrors(instance, createTerminalErrorPayloadPackage.default);
|
|
173
183
|
}
|
|
174
184
|
if (config !== null && config !== void 0 && (_config$experimentalI2 = config.experimentalInteractionMetrics) !== null && _config$experimentalI2 !== void 0 && _config$experimentalI2.enabled) {
|
|
@@ -185,10 +195,9 @@ export function init(analyticsWebClientAsync, config) {
|
|
|
185
195
|
}
|
|
186
196
|
});
|
|
187
197
|
} else if (awc.sendOperationalEvent) {
|
|
188
|
-
var _config$experimentalI3, _config$postInteracti2, _config$extraInteract3, _config$extraSearchPa2;
|
|
198
|
+
var _config$terminalError2, _config$experimentalI3, _config$postInteracti2, _config$extraInteract3, _config$extraSearchPa2;
|
|
189
199
|
sinkInteraction(awc, payloadPackage);
|
|
190
|
-
|
|
191
|
-
if (fg('platform_ufo_enable_terminal_errors')) {
|
|
200
|
+
if (config !== null && config !== void 0 && (_config$terminalError2 = config.terminalErrors) !== null && _config$terminalError2 !== void 0 && _config$terminalError2.enabled && fg('platform_ufo_enable_terminal_errors')) {
|
|
192
201
|
sinkTerminalErrors(awc, createTerminalErrorPayloadPackage.default);
|
|
193
202
|
}
|
|
194
203
|
if (config !== null && config !== void 0 && (_config$experimentalI3 = config.experimentalInteractionMetrics) !== null && _config$experimentalI3 !== void 0 && _config$experimentalI3.enabled) {
|
package/dist/es2019/vc/index.js
CHANGED
|
@@ -65,7 +65,7 @@ export class VCObserverWrapper {
|
|
|
65
65
|
startTime
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
-
if (isVCRevisionEnabled('fy25.03', experienceKey)) {
|
|
68
|
+
if (isVCRevisionEnabled('fy25.03', experienceKey) || isVCRevisionEnabled('fy26.04', experienceKey)) {
|
|
69
69
|
var _this$newVCObserver;
|
|
70
70
|
(_this$newVCObserver = this.newVCObserver) === null || _this$newVCObserver === void 0 ? void 0 : _this$newVCObserver.start({
|
|
71
71
|
startTime
|
|
@@ -80,7 +80,7 @@ export class VCObserverWrapper {
|
|
|
80
80
|
var _this$oldVCObserver2;
|
|
81
81
|
(_this$oldVCObserver2 = this.oldVCObserver) === null || _this$oldVCObserver2 === void 0 ? void 0 : _this$oldVCObserver2.stop();
|
|
82
82
|
}
|
|
83
|
-
if (isVCRevisionEnabled('fy25.03', experienceKey)) {
|
|
83
|
+
if (isVCRevisionEnabled('fy25.03', experienceKey) || isVCRevisionEnabled('fy26.04', experienceKey)) {
|
|
84
84
|
var _this$newVCObserver2;
|
|
85
85
|
(_this$newVCObserver2 = this.newVCObserver) === null || _this$newVCObserver2 === void 0 ? void 0 : _this$newVCObserver2.stop();
|
|
86
86
|
}
|
|
@@ -93,7 +93,7 @@ export class VCObserverWrapper {
|
|
|
93
93
|
return (_this$oldVCObserver$g = (_this$oldVCObserver3 = this.oldVCObserver) === null || _this$oldVCObserver3 === void 0 ? void 0 : _this$oldVCObserver3.getVCRawData()) !== null && _this$oldVCObserver$g !== void 0 ? _this$oldVCObserver$g : null;
|
|
94
94
|
}
|
|
95
95
|
async getVCResult(param) {
|
|
96
|
-
var _this$oldVCObserver4, _this$newVCObserver3, _ref;
|
|
96
|
+
var _this$oldVCObserver4, _this$newVCObserver3, _v3v4Result$, _ref;
|
|
97
97
|
const {
|
|
98
98
|
experienceKey,
|
|
99
99
|
include3p,
|
|
@@ -102,7 +102,7 @@ export class VCObserverWrapper {
|
|
|
102
102
|
includeRawData
|
|
103
103
|
} = param;
|
|
104
104
|
const v1v2Result = isVCRevisionEnabled('fy25.01', experienceKey) || isVCRevisionEnabled('fy25.02', experienceKey) ? await ((_this$oldVCObserver4 = this.oldVCObserver) === null || _this$oldVCObserver4 === void 0 ? void 0 : _this$oldVCObserver4.getVCResult(param)) : {};
|
|
105
|
-
const v3v4Result = isVCRevisionEnabled('fy25.03', experienceKey) ? await ((_this$newVCObserver3 = this.newVCObserver) === null || _this$newVCObserver3 === void 0 ? void 0 : _this$newVCObserver3.getVCResult({
|
|
105
|
+
const v3v4Result = isVCRevisionEnabled('fy25.03', experienceKey) || isVCRevisionEnabled('fy26.04', experienceKey) ? await ((_this$newVCObserver3 = this.newVCObserver) === null || _this$newVCObserver3 === void 0 ? void 0 : _this$newVCObserver3.getVCResult({
|
|
106
106
|
start: param.start,
|
|
107
107
|
stop: param.stop,
|
|
108
108
|
interactionId: param.interactionId,
|
|
@@ -117,10 +117,10 @@ export class VCObserverWrapper {
|
|
|
117
117
|
includeSSRInV3: param.includeSSRInV3,
|
|
118
118
|
rawDataStopTime: param.rawDataStopTime
|
|
119
119
|
})) : [];
|
|
120
|
-
if (!v3v4Result) {
|
|
120
|
+
if (!v3v4Result || v3v4Result.length === 0) {
|
|
121
121
|
return v1v2Result !== null && v1v2Result !== void 0 ? v1v2Result : {};
|
|
122
122
|
}
|
|
123
|
-
const ssrRatio = v3v4Result[0]
|
|
123
|
+
const ssrRatio = v3v4Result === null || v3v4Result === void 0 ? void 0 : (_v3v4Result$ = v3v4Result[0]) === null || _v3v4Result$ === void 0 ? void 0 : _v3v4Result$.ssrRatio;
|
|
124
124
|
return {
|
|
125
125
|
...(includeSSRRatio && ssrRatio !== undefined ? {
|
|
126
126
|
'ufo:vc:ssrRatio': ssrRatio
|
|
@@ -296,9 +296,6 @@ export class SSRPlaceholderHandlers {
|
|
|
296
296
|
* by collecting dimensions from their children instead
|
|
297
297
|
*/
|
|
298
298
|
getEffectiveBoundingRect(el) {
|
|
299
|
-
if (fg('platform_ufo_disable_vcnext_observations')) {
|
|
300
|
-
return el.getBoundingClientRect();
|
|
301
|
-
}
|
|
302
299
|
const computedStyle = window.getComputedStyle(el);
|
|
303
300
|
|
|
304
301
|
// If element has display: contents, collect bounding rect from children
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
import { ROOT_CONTEXT } from '@opentelemetry/api';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* We need to store a reference to the Context manager so that we can get it later.
|
|
8
|
+
* This is because the OTel JS API doesn't allow us to get the registered context manager,
|
|
9
|
+
* and we need to get it because we need to call a function that's not available in the OTel API:
|
|
10
|
+
* `setActive`. The OTel JS API design doesn't allow us to manually set the active context
|
|
11
|
+
* despite the spec allowing for the capability. Sigh.
|
|
12
|
+
*
|
|
13
|
+
* I imagine this situation might not be permanent if we can move to a system were we can rely
|
|
14
|
+
* solely on the API, but for the purposes of the first change being React UFO API compatible,
|
|
15
|
+
* we'll need to do this.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
var contextManager;
|
|
19
|
+
export function setContextManager(ctxMgr) {
|
|
20
|
+
contextManager = ctxMgr;
|
|
21
|
+
}
|
|
22
|
+
export function getContextManager() {
|
|
23
|
+
return contextManager;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The below is shamelessly borrowed from StackContextManager from @opentelemetry/sdk-trace-web
|
|
28
|
+
* Using this rather than importing the entire package because this is all we need for now
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* UFO Context Manager for managing the state in web
|
|
33
|
+
* it doesn't fully support the async calls though
|
|
34
|
+
*/
|
|
35
|
+
export var UFOContextManager = /*#__PURE__*/function () {
|
|
36
|
+
function UFOContextManager() {
|
|
37
|
+
_classCallCheck(this, UFOContextManager);
|
|
38
|
+
/**
|
|
39
|
+
* whether the context manager is enabled or not
|
|
40
|
+
*/
|
|
41
|
+
_defineProperty(this, "_enabled", false);
|
|
42
|
+
/**
|
|
43
|
+
* Keeps the reference to current context
|
|
44
|
+
*/
|
|
45
|
+
_defineProperty(this, "_currentContext", ROOT_CONTEXT);
|
|
46
|
+
}
|
|
47
|
+
return _createClass(UFOContextManager, [{
|
|
48
|
+
key: "_bindFunction",
|
|
49
|
+
value:
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @param context
|
|
53
|
+
* @param target Function to be executed within the context
|
|
54
|
+
*/
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
56
|
+
function _bindFunction() {
|
|
57
|
+
var context = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ROOT_CONTEXT;
|
|
58
|
+
var target = arguments.length > 1 ? arguments[1] : undefined;
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
60
|
+
var manager = this;
|
|
61
|
+
var contextWrapper = function contextWrapper() {
|
|
62
|
+
var _this = this;
|
|
63
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
64
|
+
args[_key] = arguments[_key];
|
|
65
|
+
}
|
|
66
|
+
return manager.with(context, function () {
|
|
67
|
+
return target.apply(_this, args);
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
Object.defineProperty(contextWrapper, 'length', {
|
|
71
|
+
enumerable: false,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: false,
|
|
74
|
+
value: target.length
|
|
75
|
+
});
|
|
76
|
+
return contextWrapper;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Returns the active context
|
|
81
|
+
*/
|
|
82
|
+
}, {
|
|
83
|
+
key: "active",
|
|
84
|
+
value: function active() {
|
|
85
|
+
return this._currentContext;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Binds a the certain context or the active one to the target function and then returns the target
|
|
90
|
+
* @param context A context (span) to be bind to target
|
|
91
|
+
* @param target a function or event emitter. When target or one of its callbacks is called,
|
|
92
|
+
* the provided context will be used as the active context for the duration of the call.
|
|
93
|
+
*/
|
|
94
|
+
}, {
|
|
95
|
+
key: "bind",
|
|
96
|
+
value: function bind(context, target) {
|
|
97
|
+
// if no specific context to propagate is given, we use the current one
|
|
98
|
+
if (context === undefined) {
|
|
99
|
+
context = this.active();
|
|
100
|
+
}
|
|
101
|
+
if (typeof target === 'function') {
|
|
102
|
+
return this._bindFunction(context, target);
|
|
103
|
+
}
|
|
104
|
+
return target;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Disable the context manager (clears the current context)
|
|
109
|
+
*/
|
|
110
|
+
}, {
|
|
111
|
+
key: "disable",
|
|
112
|
+
value: function disable() {
|
|
113
|
+
this._currentContext = ROOT_CONTEXT;
|
|
114
|
+
this._enabled = false;
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Enables the context manager and creates a default(root) context
|
|
120
|
+
*/
|
|
121
|
+
}, {
|
|
122
|
+
key: "enable",
|
|
123
|
+
value: function enable() {
|
|
124
|
+
if (this._enabled) {
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
this._enabled = true;
|
|
128
|
+
this._currentContext = ROOT_CONTEXT;
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Calls the callback function [fn] with the provided [context]. If [context] is undefined then it will use the window.
|
|
134
|
+
* The context will be set as active
|
|
135
|
+
* @param context
|
|
136
|
+
* @param fn Callback function
|
|
137
|
+
* @param thisArg optional receiver to be used for calling fn
|
|
138
|
+
* @param args optional arguments forwarded to fn
|
|
139
|
+
*/
|
|
140
|
+
}, {
|
|
141
|
+
key: "with",
|
|
142
|
+
value: function _with(context, fn, thisArg) {
|
|
143
|
+
var previousContext = this._currentContext;
|
|
144
|
+
this._currentContext = context || ROOT_CONTEXT;
|
|
145
|
+
try {
|
|
146
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
|
147
|
+
args[_key2 - 3] = arguments[_key2];
|
|
148
|
+
}
|
|
149
|
+
return fn.call.apply(fn, [thisArg].concat(args));
|
|
150
|
+
} finally {
|
|
151
|
+
this._currentContext = previousContext;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Sets the active context.
|
|
157
|
+
* This function is an extension of the OTel spec, in order to facilitate the current API of React UFO trace context handling.
|
|
158
|
+
* It doesn't keep track of any previously set active contexts, because it's assumed (for now) that only one trace context
|
|
159
|
+
* will ever exist at a time.
|
|
160
|
+
* The next step in the work to improve tracing in the FE will likely remove this function as we need to track the
|
|
161
|
+
* hierarchy of contexts (likely using the `with()` function above).
|
|
162
|
+
* @param context The context to be made the globally active one
|
|
163
|
+
*/
|
|
164
|
+
}, {
|
|
165
|
+
key: "setActive",
|
|
166
|
+
value: function setActive(context) {
|
|
167
|
+
if (this._enabled) {
|
|
168
|
+
this._currentContext = context;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}]);
|
|
172
|
+
}();
|
|
@@ -1,35 +1,91 @@
|
|
|
1
|
+
import { context, createContextKey, ROOT_CONTEXT } from '@opentelemetry/api';
|
|
2
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
|
+
import { getContextManager, UFOContextManager } from './context-manager';
|
|
1
4
|
import { makeTraceHttpRequestHeaders } from './utils/make-trace-http-request-headers';
|
|
2
5
|
var state = {
|
|
3
6
|
context: null
|
|
4
7
|
};
|
|
8
|
+
var traceIdKey = createContextKey("traceId");
|
|
9
|
+
var spanIdKey = createContextKey("spanId");
|
|
10
|
+
var experienceTypeKey = createContextKey("type");
|
|
11
|
+
|
|
12
|
+
// DO NOT CALL THIS FUNCTION DIRECTLY!!!!
|
|
13
|
+
// It is only to be called by React UFO libraries for the automatic handling of trace context for experiences.
|
|
14
|
+
// Calling this may cause trace context to be broken
|
|
5
15
|
export function generateSpanId() {
|
|
6
16
|
return Array.from(new Array(16), function () {
|
|
7
17
|
return Math.floor(Math.random() * 16).toString(16);
|
|
8
18
|
}).join('');
|
|
9
19
|
}
|
|
20
|
+
|
|
21
|
+
// DO NOT CALL THIS FUNCTION DIRECTLY!!!!
|
|
22
|
+
// It is only to be called by React UFO libraries for the automatic handling of trace context for experiences.
|
|
23
|
+
// Calling this may cause trace context to be broken
|
|
10
24
|
export function setInteractionActiveTrace(interactionId, experienceType) {
|
|
11
25
|
setActiveTrace(interactionId.replace(/-/g, ''), generateSpanId(), experienceType);
|
|
12
26
|
}
|
|
27
|
+
|
|
28
|
+
// DO NOT CALL THIS FUNCTION DIRECTLY!!!!
|
|
29
|
+
// It is only to be called by React UFO libraries for the automatic handling of trace context for experiences.
|
|
30
|
+
// Calling this may cause trace context to be broken
|
|
13
31
|
export function setActiveTrace(traceId, spanId, type) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
32
|
+
if (fg('platform_ufo_enable_otel_context_manager')) {
|
|
33
|
+
var activeTraceContext = ROOT_CONTEXT.setValue(traceIdKey, traceId).setValue(spanIdKey, spanId).setValue(experienceTypeKey, type);
|
|
34
|
+
|
|
35
|
+
// Now we need to get the global Context Manager and set the active context
|
|
36
|
+
// Using type assertion because we've "extended" the ContextManager type
|
|
37
|
+
if (getContextManager() instanceof UFOContextManager) {
|
|
38
|
+
var contextManager = getContextManager();
|
|
39
|
+
contextManager.setActive(activeTraceContext);
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
state.context = {
|
|
43
|
+
traceId: traceId,
|
|
44
|
+
spanId: spanId,
|
|
45
|
+
type: type
|
|
46
|
+
};
|
|
47
|
+
}
|
|
19
48
|
}
|
|
20
49
|
export function getActiveTrace() {
|
|
21
|
-
|
|
50
|
+
if (fg('platform_ufo_enable_otel_context_manager')) {
|
|
51
|
+
// Get trace context from active context
|
|
52
|
+
var activeTraceContext = {
|
|
53
|
+
traceId: String(context.active().getValue(traceIdKey)),
|
|
54
|
+
spanId: String(context.active().getValue(spanIdKey)),
|
|
55
|
+
type: String(context.active().getValue(experienceTypeKey))
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Return activeTraceContext if traceId and spanId are not "undefined"
|
|
59
|
+
return activeTraceContext.traceId !== 'undefined' && activeTraceContext.spanId !== 'undefined' ? activeTraceContext : undefined;
|
|
60
|
+
} else {
|
|
61
|
+
return state.context || undefined;
|
|
62
|
+
}
|
|
22
63
|
}
|
|
64
|
+
|
|
65
|
+
// DO NOT CALL THIS FUNCTION DIRECTLY!!!!
|
|
66
|
+
// It is only to be called by React UFO libraries for the automatic handling of trace context for experiences.
|
|
67
|
+
// Calling this may cause trace context to be broken
|
|
23
68
|
export function clearActiveTrace() {
|
|
24
|
-
|
|
69
|
+
if (fg('platform_ufo_enable_otel_context_manager')) {
|
|
70
|
+
// Now we need to get the global Context Manager and set the active context
|
|
71
|
+
// Using type assertion because we've "extended" the ContextManager type
|
|
72
|
+
if (getContextManager() instanceof UFOContextManager) {
|
|
73
|
+
var contextManager = getContextManager();
|
|
74
|
+
|
|
75
|
+
// ROOT_CONTEXT is an empty context used to initialise ContextManagers
|
|
76
|
+
contextManager.setActive(ROOT_CONTEXT);
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
state.context = null;
|
|
80
|
+
}
|
|
25
81
|
}
|
|
26
82
|
export function getActiveTraceHttpRequestHeaders(_url) {
|
|
27
|
-
if (
|
|
83
|
+
if (getActiveTrace() === undefined) {
|
|
28
84
|
return null;
|
|
29
85
|
}
|
|
30
|
-
var
|
|
31
|
-
traceId =
|
|
32
|
-
spanId =
|
|
86
|
+
var _ref = getActiveTrace(),
|
|
87
|
+
traceId = _ref.traceId,
|
|
88
|
+
spanId = _ref.spanId;
|
|
33
89
|
return makeTraceHttpRequestHeaders(traceId, spanId);
|
|
34
90
|
}
|
|
35
91
|
export function getActiveTraceAsQueryParams(_url) {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
import { context } from '@opentelemetry/api';
|
|
4
5
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
6
|
import { startLighthouseObserver } from '../additional-payload';
|
|
6
7
|
import { setUFOConfig } from '../config';
|
|
7
8
|
import { experimentalVC, sinkExperimentalHandler } from '../create-experimental-interaction-metrics-payload';
|
|
8
9
|
import { sinkExtraSearchPageInteractionHandler } from '../create-extra-search-page-interaction-payload';
|
|
10
|
+
import { setContextManager, UFOContextManager } from '../experience-trace-id-context/context-manager';
|
|
9
11
|
import { setupHiddenTimingCapture } from '../hidden-timing';
|
|
10
12
|
import { interactionExtraMetrics, postInteractionLog, sinkInteractionHandler, sinkPostInteractionLogHandler } from '../interaction-metrics';
|
|
11
13
|
import { getPerformanceObserver } from '../interactions-performance-observer';
|
|
@@ -146,6 +148,15 @@ export function init(analyticsWebClientAsync, config) {
|
|
|
146
148
|
initialisePressureObserver();
|
|
147
149
|
initialiseMemoryObserver();
|
|
148
150
|
setUFOConfig(config);
|
|
151
|
+
if (fg('platform_ufo_enable_otel_context_manager')) {
|
|
152
|
+
// Configure global OTel context manager
|
|
153
|
+
var contextManager = new UFOContextManager();
|
|
154
|
+
// set the contextmanager somewhere we can reference it later
|
|
155
|
+
setContextManager(contextManager);
|
|
156
|
+
// Register the context manager with the global OTel API
|
|
157
|
+
contextManager.enable();
|
|
158
|
+
context.setGlobalContextManager(contextManager);
|
|
159
|
+
}
|
|
149
160
|
if ((_config$vc = config.vc) !== null && _config$vc !== void 0 && _config$vc.enabled) {
|
|
150
161
|
var _config$experimentalI, _config$extraInteract;
|
|
151
162
|
var vcOptions = {
|
|
@@ -185,11 +196,10 @@ export function init(analyticsWebClientAsync, config) {
|
|
|
185
196
|
createTerminalErrorPayloadPackage = _ref3[4];
|
|
186
197
|
if (awc.getAnalyticsWebClientPromise) {
|
|
187
198
|
awc.getAnalyticsWebClientPromise().then(function (client) {
|
|
188
|
-
var _config$experimentalI2, _config$postInteracti, _config$extraInteract2, _config$extraSearchPa;
|
|
199
|
+
var _config$terminalError, _config$experimentalI2, _config$postInteracti, _config$extraInteract2, _config$extraSearchPa;
|
|
189
200
|
var instance = client.getInstance();
|
|
190
201
|
sinkInteraction(instance, payloadPackage);
|
|
191
|
-
|
|
192
|
-
if (fg('platform_ufo_enable_terminal_errors')) {
|
|
202
|
+
if (config !== null && config !== void 0 && (_config$terminalError = config.terminalErrors) !== null && _config$terminalError !== void 0 && _config$terminalError.enabled && fg('platform_ufo_enable_terminal_errors')) {
|
|
193
203
|
sinkTerminalErrors(instance, createTerminalErrorPayloadPackage.default);
|
|
194
204
|
}
|
|
195
205
|
if (config !== null && config !== void 0 && (_config$experimentalI2 = config.experimentalInteractionMetrics) !== null && _config$experimentalI2 !== void 0 && _config$experimentalI2.enabled) {
|
|
@@ -206,10 +216,9 @@ export function init(analyticsWebClientAsync, config) {
|
|
|
206
216
|
}
|
|
207
217
|
});
|
|
208
218
|
} else if (awc.sendOperationalEvent) {
|
|
209
|
-
var _config$experimentalI3, _config$postInteracti2, _config$extraInteract3, _config$extraSearchPa2;
|
|
219
|
+
var _config$terminalError2, _config$experimentalI3, _config$postInteracti2, _config$extraInteract3, _config$extraSearchPa2;
|
|
210
220
|
sinkInteraction(awc, payloadPackage);
|
|
211
|
-
|
|
212
|
-
if (fg('platform_ufo_enable_terminal_errors')) {
|
|
221
|
+
if (config !== null && config !== void 0 && (_config$terminalError2 = config.terminalErrors) !== null && _config$terminalError2 !== void 0 && _config$terminalError2.enabled && fg('platform_ufo_enable_terminal_errors')) {
|
|
213
222
|
sinkTerminalErrors(awc, createTerminalErrorPayloadPackage.default);
|
|
214
223
|
}
|
|
215
224
|
if (config !== null && config !== void 0 && (_config$experimentalI3 = config.experimentalInteractionMetrics) !== null && _config$experimentalI3 !== void 0 && _config$experimentalI3.enabled) {
|
package/dist/esm/vc/index.js
CHANGED
|
@@ -77,7 +77,7 @@ export var VCObserverWrapper = /*#__PURE__*/function () {
|
|
|
77
77
|
startTime: startTime
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
|
-
if (isVCRevisionEnabled('fy25.03', experienceKey)) {
|
|
80
|
+
if (isVCRevisionEnabled('fy25.03', experienceKey) || isVCRevisionEnabled('fy26.04', experienceKey)) {
|
|
81
81
|
var _this$newVCObserver;
|
|
82
82
|
(_this$newVCObserver = this.newVCObserver) === null || _this$newVCObserver === void 0 || _this$newVCObserver.start({
|
|
83
83
|
startTime: startTime
|
|
@@ -94,7 +94,7 @@ export var VCObserverWrapper = /*#__PURE__*/function () {
|
|
|
94
94
|
var _this$oldVCObserver2;
|
|
95
95
|
(_this$oldVCObserver2 = this.oldVCObserver) === null || _this$oldVCObserver2 === void 0 || _this$oldVCObserver2.stop();
|
|
96
96
|
}
|
|
97
|
-
if (isVCRevisionEnabled('fy25.03', experienceKey)) {
|
|
97
|
+
if (isVCRevisionEnabled('fy25.03', experienceKey) || isVCRevisionEnabled('fy26.04', experienceKey)) {
|
|
98
98
|
var _this$newVCObserver2;
|
|
99
99
|
(_this$newVCObserver2 = this.newVCObserver) === null || _this$newVCObserver2 === void 0 || _this$newVCObserver2.stop();
|
|
100
100
|
}
|
|
@@ -112,7 +112,7 @@ export var VCObserverWrapper = /*#__PURE__*/function () {
|
|
|
112
112
|
key: "getVCResult",
|
|
113
113
|
value: function () {
|
|
114
114
|
var _getVCResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(param) {
|
|
115
|
-
var _this$oldVCObserver4, _this$newVCObserver3, _ref2;
|
|
115
|
+
var _this$oldVCObserver4, _this$newVCObserver3, _v3v4Result$, _ref2;
|
|
116
116
|
var experienceKey, include3p, excludeSmartAnswersInSearch, includeSSRRatio, includeRawData, v1v2Result, v3v4Result, ssrRatio;
|
|
117
117
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
118
118
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -132,7 +132,7 @@ export var VCObserverWrapper = /*#__PURE__*/function () {
|
|
|
132
132
|
_context.t0 = {};
|
|
133
133
|
case 8:
|
|
134
134
|
v1v2Result = _context.t0;
|
|
135
|
-
if (!isVCRevisionEnabled('fy25.03', experienceKey)) {
|
|
135
|
+
if (!(isVCRevisionEnabled('fy25.03', experienceKey) || isVCRevisionEnabled('fy26.04', experienceKey))) {
|
|
136
136
|
_context.next = 15;
|
|
137
137
|
break;
|
|
138
138
|
}
|
|
@@ -160,13 +160,13 @@ export var VCObserverWrapper = /*#__PURE__*/function () {
|
|
|
160
160
|
_context.t1 = [];
|
|
161
161
|
case 16:
|
|
162
162
|
v3v4Result = _context.t1;
|
|
163
|
-
if (v3v4Result) {
|
|
163
|
+
if (!(!v3v4Result || v3v4Result.length === 0)) {
|
|
164
164
|
_context.next = 19;
|
|
165
165
|
break;
|
|
166
166
|
}
|
|
167
167
|
return _context.abrupt("return", v1v2Result !== null && v1v2Result !== void 0 ? v1v2Result : {});
|
|
168
168
|
case 19:
|
|
169
|
-
ssrRatio = v3v4Result[0]
|
|
169
|
+
ssrRatio = v3v4Result === null || v3v4Result === void 0 || (_v3v4Result$ = v3v4Result[0]) === null || _v3v4Result$ === void 0 ? void 0 : _v3v4Result$.ssrRatio;
|
|
170
170
|
return _context.abrupt("return", _objectSpread(_objectSpread(_objectSpread({}, includeSSRRatio && ssrRatio !== undefined ? {
|
|
171
171
|
'ufo:vc:ssrRatio': ssrRatio
|
|
172
172
|
} : {}), v1v2Result), {}, {
|
|
@@ -342,9 +342,6 @@ export var SSRPlaceholderHandlers = /*#__PURE__*/function () {
|
|
|
342
342
|
}, {
|
|
343
343
|
key: "getEffectiveBoundingRect",
|
|
344
344
|
value: function getEffectiveBoundingRect(el) {
|
|
345
|
-
if (fg('platform_ufo_disable_vcnext_observations')) {
|
|
346
|
-
return el.getBoundingClientRect();
|
|
347
|
-
}
|
|
348
345
|
var computedStyle = window.getComputedStyle(el);
|
|
349
346
|
|
|
350
347
|
// If element has display: contents, collect bounding rect from children
|
|
@@ -146,6 +146,12 @@ export type Config = {
|
|
|
146
146
|
readonly rates?: Rates;
|
|
147
147
|
readonly kind?: Record<InteractionType, number>;
|
|
148
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* Option to enable terminal error tracking
|
|
151
|
+
*/
|
|
152
|
+
readonly terminalErrors?: {
|
|
153
|
+
readonly enabled?: boolean;
|
|
154
|
+
};
|
|
149
155
|
/**
|
|
150
156
|
* @private
|
|
151
157
|
* @deprecated - to be removed on next major version
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type Context, type ContextManager } from '@opentelemetry/api';
|
|
2
|
+
export declare function setContextManager(ctxMgr: ContextManager): void;
|
|
3
|
+
export declare function getContextManager(): ContextManager;
|
|
4
|
+
/**
|
|
5
|
+
* The below is shamelessly borrowed from StackContextManager from @opentelemetry/sdk-trace-web
|
|
6
|
+
* Using this rather than importing the entire package because this is all we need for now
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* UFO Context Manager for managing the state in web
|
|
10
|
+
* it doesn't fully support the async calls though
|
|
11
|
+
*/
|
|
12
|
+
export declare class UFOContextManager implements ContextManager {
|
|
13
|
+
/**
|
|
14
|
+
* whether the context manager is enabled or not
|
|
15
|
+
*/
|
|
16
|
+
private _enabled;
|
|
17
|
+
/**
|
|
18
|
+
* Keeps the reference to current context
|
|
19
|
+
*/
|
|
20
|
+
_currentContext: Context;
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param context
|
|
24
|
+
* @param target Function to be executed within the context
|
|
25
|
+
*/
|
|
26
|
+
private _bindFunction;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the active context
|
|
29
|
+
*/
|
|
30
|
+
active(): Context;
|
|
31
|
+
/**
|
|
32
|
+
* Binds a the certain context or the active one to the target function and then returns the target
|
|
33
|
+
* @param context A context (span) to be bind to target
|
|
34
|
+
* @param target a function or event emitter. When target or one of its callbacks is called,
|
|
35
|
+
* the provided context will be used as the active context for the duration of the call.
|
|
36
|
+
*/
|
|
37
|
+
bind<T>(context: Context, target: T): T;
|
|
38
|
+
/**
|
|
39
|
+
* Disable the context manager (clears the current context)
|
|
40
|
+
*/
|
|
41
|
+
disable(): this;
|
|
42
|
+
/**
|
|
43
|
+
* Enables the context manager and creates a default(root) context
|
|
44
|
+
*/
|
|
45
|
+
enable(): this;
|
|
46
|
+
/**
|
|
47
|
+
* Calls the callback function [fn] with the provided [context]. If [context] is undefined then it will use the window.
|
|
48
|
+
* The context will be set as active
|
|
49
|
+
* @param context
|
|
50
|
+
* @param fn Callback function
|
|
51
|
+
* @param thisArg optional receiver to be used for calling fn
|
|
52
|
+
* @param args optional arguments forwarded to fn
|
|
53
|
+
*/
|
|
54
|
+
with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: Context | null, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
|
|
55
|
+
/**
|
|
56
|
+
* Sets the active context.
|
|
57
|
+
* This function is an extension of the OTel spec, in order to facilitate the current API of React UFO trace context handling.
|
|
58
|
+
* It doesn't keep track of any previously set active contexts, because it's assumed (for now) that only one trace context
|
|
59
|
+
* will ever exist at a time.
|
|
60
|
+
* The next step in the work to improve tracing in the FE will likely remove this function as we need to track the
|
|
61
|
+
* hierarchy of contexts (likely using the `with()` function above).
|
|
62
|
+
* @param context The context to be made the globally active one
|
|
63
|
+
*/
|
|
64
|
+
setActive(context: Context): void;
|
|
65
|
+
}
|
|
@@ -146,6 +146,12 @@ export type Config = {
|
|
|
146
146
|
readonly rates?: Rates;
|
|
147
147
|
readonly kind?: Record<InteractionType, number>;
|
|
148
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* Option to enable terminal error tracking
|
|
151
|
+
*/
|
|
152
|
+
readonly terminalErrors?: {
|
|
153
|
+
readonly enabled?: boolean;
|
|
154
|
+
};
|
|
149
155
|
/**
|
|
150
156
|
* @private
|
|
151
157
|
* @deprecated - to be removed on next major version
|