o11y 244.2.1 → 244.3.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.
Files changed (61) hide show
  1. package/dist/modules/o11y/client/client.d.ts +4 -1
  2. package/dist/modules/o11y/client/client.js +308 -282
  3. package/dist/modules/o11y/client/client.js.map +1 -1
  4. package/dist/modules/o11y/client/index.d.ts +10 -5
  5. package/dist/modules/o11y/client/interfaces/IdleDetector.d.ts +5 -0
  6. package/dist/modules/o11y/client/interfaces/IdleDetectorOptions.d.ts +3 -0
  7. package/dist/modules/o11y/client/interfaces/NetworkInstrumentationOptions.d.ts +1 -0
  8. package/dist/modules/o11y/client/library/IdleDetectorImpl.d.ts +2 -1
  9. package/dist/modules/o11y/client/library/NextgenImpl.d.ts +3 -1
  10. package/dist/modules/o11y/client/library/Tracing.d.ts +3 -1
  11. package/dist/modules/o11y/client/version.d.ts +1 -1
  12. package/dist/modules/o11y/collectors/client.d.ts +4 -1
  13. package/dist/modules/o11y/collectors/index.d.ts +10 -5
  14. package/dist/modules/o11y/collectors/interfaces/IdleDetector.d.ts +5 -0
  15. package/dist/modules/o11y/collectors/interfaces/IdleDetectorOptions.d.ts +3 -0
  16. package/dist/modules/o11y/collectors/interfaces/NetworkInstrumentationOptions.d.ts +1 -0
  17. package/dist/modules/o11y/collectors/library/IdleDetectorImpl.d.ts +2 -1
  18. package/dist/modules/o11y/collectors/library/NextgenImpl.d.ts +3 -1
  19. package/dist/modules/o11y/collectors/library/Tracing.d.ts +3 -1
  20. package/dist/modules/o11y/collectors/version.d.ts +1 -1
  21. package/dist/modules/o11y/core_envelope/client.d.ts +4 -1
  22. package/dist/modules/o11y/core_envelope/core_envelope.js +1 -1
  23. package/dist/modules/o11y/core_envelope/core_envelope.js.map +1 -1
  24. package/dist/modules/o11y/core_envelope/index.d.ts +10 -5
  25. package/dist/modules/o11y/core_envelope/interfaces/IdleDetector.d.ts +5 -0
  26. package/dist/modules/o11y/core_envelope/interfaces/IdleDetectorOptions.d.ts +3 -0
  27. package/dist/modules/o11y/core_envelope/interfaces/NetworkInstrumentationOptions.d.ts +1 -0
  28. package/dist/modules/o11y/core_envelope/library/IdleDetectorImpl.d.ts +2 -1
  29. package/dist/modules/o11y/core_envelope/library/NextgenImpl.d.ts +3 -1
  30. package/dist/modules/o11y/core_envelope/library/Tracing.d.ts +3 -1
  31. package/dist/modules/o11y/core_envelope/version.d.ts +1 -1
  32. package/dist/modules/o11y/shared/client.d.ts +4 -1
  33. package/dist/modules/o11y/shared/index.d.ts +10 -5
  34. package/dist/modules/o11y/shared/interfaces/IdleDetector.d.ts +5 -0
  35. package/dist/modules/o11y/shared/interfaces/IdleDetectorOptions.d.ts +3 -0
  36. package/dist/modules/o11y/shared/interfaces/NetworkInstrumentationOptions.d.ts +1 -0
  37. package/dist/modules/o11y/shared/library/IdleDetectorImpl.d.ts +2 -1
  38. package/dist/modules/o11y/shared/library/NextgenImpl.d.ts +3 -1
  39. package/dist/modules/o11y/shared/library/Tracing.d.ts +3 -1
  40. package/dist/modules/o11y/shared/version.d.ts +1 -1
  41. package/dist/modules/o11y/simple_collector/client.d.ts +4 -1
  42. package/dist/modules/o11y/simple_collector/index.d.ts +10 -5
  43. package/dist/modules/o11y/simple_collector/interfaces/IdleDetector.d.ts +5 -0
  44. package/dist/modules/o11y/simple_collector/interfaces/IdleDetectorOptions.d.ts +3 -0
  45. package/dist/modules/o11y/simple_collector/interfaces/NetworkInstrumentationOptions.d.ts +1 -0
  46. package/dist/modules/o11y/simple_collector/library/IdleDetectorImpl.d.ts +2 -1
  47. package/dist/modules/o11y/simple_collector/library/NextgenImpl.d.ts +3 -1
  48. package/dist/modules/o11y/simple_collector/library/Tracing.d.ts +3 -1
  49. package/dist/modules/o11y/simple_collector/simple_collector.js +3 -4
  50. package/dist/modules/o11y/simple_collector/simple_collector.js.map +1 -1
  51. package/dist/modules/o11y/simple_collector/version.d.ts +1 -1
  52. package/dist/modules/o11y/web_vitals/client.d.ts +4 -1
  53. package/dist/modules/o11y/web_vitals/index.d.ts +10 -5
  54. package/dist/modules/o11y/web_vitals/interfaces/IdleDetector.d.ts +5 -0
  55. package/dist/modules/o11y/web_vitals/interfaces/IdleDetectorOptions.d.ts +3 -0
  56. package/dist/modules/o11y/web_vitals/interfaces/NetworkInstrumentationOptions.d.ts +1 -0
  57. package/dist/modules/o11y/web_vitals/library/IdleDetectorImpl.d.ts +2 -1
  58. package/dist/modules/o11y/web_vitals/library/NextgenImpl.d.ts +3 -1
  59. package/dist/modules/o11y/web_vitals/library/Tracing.d.ts +3 -1
  60. package/dist/modules/o11y/web_vitals/version.d.ts +1 -1
  61. package/package.json +2 -2
@@ -1,5 +1,265 @@
1
1
  import { utility, PublicSafety, schemaUtil } from 'o11y/shared';
2
2
 
3
+ const activity={namespace:"sf.instrumentation",name:"Activity",pbjsSchema:{"nested":{"sf":{"nested":{"instrumentation":{"nested":{"Activity":{"reserved":[[5,5],[7,7]],"fields":{"duration":{"id":3,"type":"double"},"stopReason":{"id":6,"type":"string"},"isRoot":{"id":8,"type":"bool"},"timerOverridden":{"id":12,"type":"uint32"},"name":{"options":{"(meta.max_length)":25},"id":2,"type":"string"},"isSampled":{"id":11,"type":"bool"},"preRootId":{"id":9,"type":"string"},"id":{"id":1,"type":"string"},
4
+ "userPayload":{"id":4,"type":"Payload"},"errorCount":{"id":10,"type":"uint32"},"parentId":{"id":13,"type":"string"}}},"Payload":{"fields":{"payload":{"id":2,"type":"bytes"},"schemaName":{"id":1,"type":"string"}}}}}}}}}};
5
+
6
+ const error={namespace:"sf.instrumentation",name:"Error",pbjsSchema:{"nested":{"sf":{"nested":{"instrumentation":{"nested":{"Error":{"reserved":[[5,5],[7,7]],"fields":{"activityId":{"id":6,"type":"string"},"stack":{"id":3,"type":"string"},"name":{"id":1,"type":"string"},"message":{"options":{"(meta.max_length)":200},"id":2,"type":"string"},"userPayload":{"id":4,"type":"Payload"}}},"Payload":{"fields":{"payload":{"id":2,"type":"bytes"},"schemaName":{"id":1,"type":"string"}}}}}}}}}};
7
+
8
+ const idle_detector_report={namespace:"sf.instrumentation",name:"IdleDetectorReport",pbjsSchema:{"nested":{"sf":{"nested":{"instrumentation":{"nested":{"IdleDetectorReport":{"fields":{"listenerCount":{"id":3,"type":"uint32"},"busyTasks":{"rule":"repeated","id":5,"type":"string"},"busyDurations":{"rule":"repeated","id":6,"type":"double"},"pollableCount":{"id":4,"type":"uint32"},"pollCounts":{"rule":"repeated","id":8,"type":"double"},"logThreshold":{"id":2,"type":"double"},"maxDuration":{"id":1,
9
+ "type":"double"},"pollables":{"rule":"repeated","id":7,"type":"string"}}}}}}}}}};
10
+
11
+ const instrumented_event={namespace:"sf.instrumentation",name:"InstrumentedEvent",pbjsSchema:{"nested":{"sf":{"nested":{"instrumentation":{"nested":{"MouseEvent":{"fields":{"cancelable":{"id":5,"type":"bool"},"ctrlKey":{"id":9,"type":"bool"},"type":{"id":25,"type":"string"},"button":{"id":3,"type":"uint32"},"offsetX":{"id":17,"type":"uint32"},"eventPhase":{"id":12,"type":"uint32"},"shiftKey":{"id":23,"type":"bool"},"offsetY":{"id":18,"type":"uint32"},"composed":{"id":8,"type":"bool"},"altKey":{"id":1,
12
+ "type":"bool"},"isTrusted":{"id":13,"type":"bool"},"buttons":{"id":4,"type":"uint32"},"movementY":{"id":16,"type":"uint32"},"clientY":{"id":7,"type":"uint32"},"clientX":{"id":6,"type":"uint32"},"movementX":{"id":15,"type":"uint32"},"defaultPrevented":{"id":10,"type":"bool"},"metaKey":{"id":14,"type":"bool"},"timeStamp":{"id":24,"type":"double"},"bubbles":{"id":2,"type":"bool"},"detail":{"id":11,"type":"int64"},"pageY":{"id":20,"type":"uint32"},"pageX":{"id":19,"type":"uint32"},"screenX":{"id":21,
13
+ "type":"uint32"},"screenY":{"id":22,"type":"uint32"}}},"InstrumentedEvent":{"oneofs":{"event":{"oneof":["mouseEvent"]}},"reserved":[[4,4],"xpath",[6,6],[8,8]],"fields":{"mouseEvent":{"id":7,"type":"MouseEvent"},"auto":{"id":3,"type":"bool"},"parentComponent":{"id":2,"type":"string"},"ownerComponent":{"id":1,"type":"string"},"userPayload":{"id":5,"type":"Payload"},"simplePath":{"id":9,"type":"string"}}},"Payload":{"fields":{"payload":{"id":2,"type":"bytes"},"schemaName":{"id":1,"type":"string"}}}}}}}}}};
14
+
15
+ const simple={namespace:"sf.instrumentation",name:"Simple",pbjsSchema:{"nested":{"sf":{"nested":{"instrumentation":{"nested":{"Simple":{"fields":{"text":{"options":{"(meta.max_length)":25},"id":1,"type":"string"}}}}}}}}}};
16
+
17
+ class TaskerImpl {
18
+ constructor(name, initialCount, _doneCallback, _overDoneCallback) {
19
+ this.name = name;
20
+ this._doneCallback = _doneCallback;
21
+ this._overDoneCallback = _overDoneCallback;
22
+ this._busyCount = 0;
23
+ this._isOk = true;
24
+ this._busyCount = initialCount;
25
+ }
26
+ get isBusy() {
27
+ return this._isOk ? this._busyCount > 0 : undefined;
28
+ }
29
+ add() {
30
+ if (this._isOk) {
31
+ this._busyCount += 1;
32
+ }
33
+ }
34
+ done() {
35
+ if (this._isOk) {
36
+ if (this._busyCount > 0) {
37
+ this._busyCount -= 1;
38
+ if (!this._busyCount) {
39
+ this._doneCallback();
40
+ }
41
+ }
42
+ else {
43
+ this._isOk = false;
44
+ this._overDoneCallback();
45
+ }
46
+ }
47
+ }
48
+ }
49
+
50
+ const defaultLogThreshold = 300;
51
+ class IdleDetectorImpl {
52
+ constructor(options) {
53
+ this._taskers = new Map();
54
+ this._listeners = new Set();
55
+ this._busyCheckers = new Map();
56
+ this._logThreshold = defaultLogThreshold;
57
+ this._endedTasks = new Array();
58
+ this._pollableReport = new Array();
59
+ if (utility.requireArgumentIfDefined(options === null || options === void 0 ? void 0 : options.logThreshold, 'options.logThreshold', 'number')) {
60
+ this._logThreshold = options.logThreshold;
61
+ }
62
+ if (utility.requireArgumentIfDefined(options === null || options === void 0 ? void 0 : options.reportListener, 'options.reportListener', 'function')) {
63
+ this._reportListener = options.reportListener;
64
+ }
65
+ if (utility.requireArgumentIfDefined(options === null || options === void 0 ? void 0 : options.errorListener, 'options.errorListener', 'function')) {
66
+ this._errorListener = options.errorListener;
67
+ }
68
+ }
69
+ requestIdleDetectedCallback(callback) {
70
+ utility.requireArgument(callback, 'callback', 'function');
71
+ if (this._listeners.size === 0) {
72
+ this._firstCallbackTime = utility.time().perfNow;
73
+ }
74
+ this._listeners.add(callback);
75
+ this._checkIfLoaded();
76
+ }
77
+ _reportTaskEnded(tasker) {
78
+ if (this._listeners.size) {
79
+ const snapshot = Object.assign({}, this._taskers.get(tasker));
80
+ this._endedTasks.push(snapshot);
81
+ }
82
+ }
83
+ declareNotifierTaskSingle(name) {
84
+ utility.requireArgument(name, 'name', 'string');
85
+ const tasker = this._addTasker(name, 1);
86
+ const retVal = {
87
+ get isBusy() {
88
+ return tasker.isBusy;
89
+ },
90
+ done: () => {
91
+ tasker.done();
92
+ this._taskers.delete(tasker);
93
+ }
94
+ };
95
+ return retVal;
96
+ }
97
+ declareNotifierTaskMulti(name, existingBusyCount = 0) {
98
+ utility.requireArgument(name, 'name', 'string');
99
+ if (existingBusyCount !== undefined) {
100
+ utility.requireArgument(existingBusyCount, 'existingBusyCount', 'number');
101
+ if (!Number.isInteger(existingBusyCount) || existingBusyCount < 0) {
102
+ throw new Error('existingBusyCount accepts only non-negative integers');
103
+ }
104
+ }
105
+ const tasker = this._addTasker(name, existingBusyCount);
106
+ const retVal = {
107
+ get isBusy() {
108
+ return tasker.isBusy;
109
+ },
110
+ add: () => {
111
+ if (!tasker.isBusy) {
112
+ const meta = this._taskers.get(tasker);
113
+ meta.start = utility.time().perfNow;
114
+ meta.end = undefined;
115
+ }
116
+ tasker.add();
117
+ },
118
+ done: tasker.done.bind(tasker)
119
+ };
120
+ return retVal;
121
+ }
122
+ declarePollableTaskMulti(name, isBusyChecker) {
123
+ utility.requireArgument(name, 'name', 'string');
124
+ utility.requireArgument(isBusyChecker, 'isBusyChecker', 'function');
125
+ this._busyCheckers.set(isBusyChecker, name);
126
+ }
127
+ _addTasker(name, existingBusyCount) {
128
+ const tasker = new TaskerImpl(name, existingBusyCount, () => {
129
+ this._taskers.get(tasker).end = utility.time().perfNow;
130
+ this._reportTaskEnded(tasker);
131
+ this._checkIfLoaded();
132
+ }, () => {
133
+ var _a;
134
+ (_a = this._errorListener) === null || _a === void 0 ? void 0 : _a.call(this, `Overdone: ${tasker.name}`);
135
+ utility.noProdThrow(`Tasker '${tasker.name}' is done too many times.`);
136
+ });
137
+ this._taskers.set(tasker, {
138
+ name,
139
+ start: existingBusyCount > 0 ? utility.time().perfNow : undefined,
140
+ end: undefined
141
+ });
142
+ return tasker;
143
+ }
144
+ _areAllNotifiersIdle() {
145
+ return !Array.from(this._taskers.keys()).some((t) => t.isBusy);
146
+ }
147
+ _getFirstBusyPollable() {
148
+ const entry = Array.from(this._busyCheckers).find((entry) => {
149
+ var _a;
150
+ const isBusyChecker = entry[0];
151
+ const name = entry[1];
152
+ try {
153
+ return isBusyChecker();
154
+ }
155
+ catch (e) {
156
+ (_a = this._errorListener) === null || _a === void 0 ? void 0 : _a.call(this, e, `BusyChecker ${name}`);
157
+ utility.noProdThrow(e);
158
+ return false;
159
+ }
160
+ });
161
+ return entry ? entry[1] : undefined;
162
+ }
163
+ _checkIfLoaded() {
164
+ if (!this._listeners.size) {
165
+ return;
166
+ }
167
+ if (this._timerCheckQueued) {
168
+ clearTimeout(this._timerCheckQueued);
169
+ }
170
+ if (this._areAllNotifiersIdle()) {
171
+ this._timerCheckQueued = setTimeout(() => {
172
+ this._timerCheckQueued = setTimeout(() => {
173
+ this._doubleCheck();
174
+ }, 40);
175
+ }, 0);
176
+ }
177
+ }
178
+ _doubleCheck() {
179
+ this._timerCheckQueued = undefined;
180
+ if (this._areAllNotifiersIdle()) {
181
+ const pollableName = this._getFirstBusyPollable();
182
+ if (pollableName !== undefined) {
183
+ this._addToPollableReport(pollableName);
184
+ this._timerCheckQueued = setTimeout(() => {
185
+ this._doubleCheck();
186
+ }, 15);
187
+ }
188
+ else {
189
+ const maxDuration = utility.time().perfNow - this._firstCallbackTime;
190
+ const listeners = Array.from(this._listeners.values());
191
+ this._listeners.clear();
192
+ this._firstCallbackTime = undefined;
193
+ const endedTasks = this._endedTasks.splice(0);
194
+ const pollableReport = this._pollableReport.splice(0);
195
+ this._notify(listeners, maxDuration, endedTasks, pollableReport);
196
+ }
197
+ }
198
+ }
199
+ _addToPollableReport(name) {
200
+ const lastEntry = this._pollableReport.length
201
+ ? this._pollableReport[this._pollableReport.length - 1]
202
+ : undefined;
203
+ if ((lastEntry === null || lastEntry === void 0 ? void 0 : lastEntry.name) === name) {
204
+ lastEntry.count += 1;
205
+ }
206
+ else {
207
+ this._pollableReport.push({
208
+ name,
209
+ count: 1
210
+ });
211
+ }
212
+ }
213
+ _notify(listeners, maxDuration, taskReport, pollableReport) {
214
+ var _a;
215
+ if (maxDuration >= this._logThreshold && this._reportListener) {
216
+ const logData = this._getReport(maxDuration, listeners.length, taskReport, pollableReport);
217
+ this._reportListener(logData);
218
+ }
219
+ listeners.reverse();
220
+ const tsNow = utility.time().tsNow;
221
+ for (const [index, listener] of listeners.entries()) {
222
+ try {
223
+ listener(tsNow);
224
+ }
225
+ catch (e) {
226
+ (_a = this._errorListener) === null || _a === void 0 ? void 0 : _a.call(this, e, `Listener #${listeners.length - 1 - index}`);
227
+ utility.noProdThrow(e);
228
+ }
229
+ }
230
+ }
231
+ getReport() {
232
+ const perfNow = utility.time().perfNow;
233
+ const maxDuration = this._firstCallbackTime > 0 ? perfNow - this._firstCallbackTime : undefined;
234
+ const onGoingTasks = Array.from(this._taskers.entries())
235
+ .filter((e) => e[0].isBusy)
236
+ .map((e) => ({
237
+ name: e[1].name,
238
+ start: e[1].start,
239
+ end: perfNow
240
+ }));
241
+ return this._getReport(maxDuration, this._listeners.size, this._endedTasks.concat(onGoingTasks), this._pollableReport);
242
+ }
243
+ _getReport(maxDuration, listenerCount, taskReport, pollableReport) {
244
+ const sortedTaskers = taskReport
245
+ .map((t) => ({
246
+ name: t.name,
247
+ duration: t.end - t.start
248
+ }))
249
+ .sort((a, b) => b.duration - a.duration);
250
+ return {
251
+ logThreshold: this._logThreshold,
252
+ maxDuration,
253
+ listenerCount,
254
+ pollableCount: this._busyCheckers.size,
255
+ busyTasks: sortedTaskers.map((t) => t.name),
256
+ busyDurations: sortedTaskers.map((t) => t.duration),
257
+ pollables: pollableReport.map((p) => p.name),
258
+ pollCounts: pollableReport.map((p) => p.count)
259
+ };
260
+ }
261
+ }
262
+
3
263
  const defaultTraceIdLengthW3 = 32;
4
264
  const defaultTraceIdLengthB3 = 16;
5
265
  const defaultSpanIdLength = 16;
@@ -12,9 +272,11 @@ const headerParentSpanId = 'X-B3-ParentSpanId';
12
272
  const defaultActivityNameForFetch = 'fetch';
13
273
  const defaultActivityNameForXhrSend = 'xhr_send';
14
274
  class Tracing {
15
- constructor(_instr) {
275
+ constructor(_instr, _idleDetector) {
16
276
  this._instr = _instr;
277
+ this._idleDetector = _idleDetector;
17
278
  utility.requireArgument(_instr, '_instr', 'object');
279
+ utility.requireArgument(_idleDetector, '_idleDetector', 'object');
18
280
  }
19
281
  static _getB3CompactFormat(traceId, spanId, isSampled, parentSpanId) {
20
282
  let b3 = `${traceId}-${spanId}`;
@@ -99,21 +361,22 @@ class Tracing {
99
361
  Tracing._isNetworkInstrumentationEnabled = false;
100
362
  }
101
363
  }
102
- _enableNetworkInstrumentation(instr, logErrors, activityName, useTracing, options) {
364
+ _enableNetworkInstrumentation(instr, logErrors, activityName, useTracing, options, tasker) {
103
365
  if (typeof Tracing._global.fetch === 'function') {
104
- this._overrideFetch(instr, logErrors, activityName, useTracing, options);
366
+ this._overrideFetch(instr, logErrors, activityName, useTracing, options, tasker);
105
367
  Tracing._isNetworkInstrumentationEnabled = true;
106
368
  }
107
369
  if (typeof Tracing._global.XMLHttpRequest === 'function') {
108
- this._overrideXhr(instr, logErrors, activityName, useTracing, options);
370
+ this._overrideXhr(instr, logErrors, activityName, useTracing, options, tasker);
109
371
  Tracing._isNetworkInstrumentationEnabled = true;
110
372
  }
111
373
  }
112
- _overrideFetch(instr, logErrors, activityName, useTracing, options) {
374
+ _overrideFetch(instr, logErrors, activityName, useTracing, options, tasker) {
113
375
  Tracing._originalFetch = Tracing._global.fetch;
114
376
  const o11yFetch = async (url, reqOptions, ...restArgs) => {
115
377
  let activity;
116
378
  try {
379
+ tasker === null || tasker === void 0 ? void 0 : tasker.add();
117
380
  activity = instr.startActivity(activityName || defaultActivityNameForFetch);
118
381
  if (useTracing) {
119
382
  reqOptions = reqOptions || {};
@@ -134,20 +397,20 @@ class Tracing {
134
397
  throw ex;
135
398
  }
136
399
  finally {
137
- if (activity) {
138
- activity.stop();
139
- }
400
+ activity === null || activity === void 0 ? void 0 : activity.stop();
401
+ tasker === null || tasker === void 0 ? void 0 : tasker.done();
140
402
  }
141
403
  };
142
404
  Tracing._global.fetch = o11yFetch;
143
405
  }
144
- _overrideXhr(instr, logErrors, activityName, useTracing, options) {
406
+ _overrideXhr(instr, logErrors, activityName, useTracing, options, tasker) {
145
407
  Tracing._originalXhr = Tracing._global.XMLHttpRequest;
146
408
  Tracing._originalXhrSend = Tracing._originalXhr.prototype.send;
147
409
  Tracing._originalXhr.prototype.send = function (...args) {
148
410
  let activity;
149
- const xhr = this;
150
411
  try {
412
+ tasker === null || tasker === void 0 ? void 0 : tasker.add();
413
+ const xhr = this;
151
414
  xhr._o11yActivity = activity = instr.startActivity(activityName || defaultActivityNameForXhrSend);
152
415
  if (useTracing) {
153
416
  const headers = activity.getTraceHeaders(options);
@@ -166,9 +429,8 @@ class Tracing {
166
429
  instr.error(ex);
167
430
  }
168
431
  }
169
- if (activity) {
170
- activity.stop();
171
- }
432
+ activity === null || activity === void 0 ? void 0 : activity.stop();
433
+ tasker === null || tasker === void 0 ? void 0 : tasker.done();
172
434
  throw ex;
173
435
  }
174
436
  };
@@ -176,10 +438,9 @@ class Tracing {
176
438
  construct(target) {
177
439
  const newXhr = new target();
178
440
  newXhr.addEventListener('load', () => {
179
- const activity = newXhr._o11yActivity;
180
- if (activity) {
181
- activity.stop();
182
- }
441
+ var _a;
442
+ (_a = newXhr._o11yActivity) === null || _a === void 0 ? void 0 : _a.stop();
443
+ tasker === null || tasker === void 0 ? void 0 : tasker.done();
183
444
  });
184
445
  newXhr.addEventListener('error', (__err) => {
185
446
  const error = new Error('XHR Network-Level Error');
@@ -193,12 +454,12 @@ class Tracing {
193
454
  else if (logErrors) {
194
455
  instr.error(error);
195
456
  }
457
+ tasker === null || tasker === void 0 ? void 0 : tasker.done();
196
458
  });
197
459
  newXhr.addEventListener('abort', () => {
198
- const activity = newXhr._o11yActivity;
199
- if (activity) {
200
- activity.discard();
201
- }
460
+ const activity = newXhr._o11yActivity;
461
+ activity === null || activity === void 0 ? void 0 : activity.discard();
462
+ tasker === null || tasker === void 0 ? void 0 : tasker.done();
202
463
  });
203
464
  return newXhr;
204
465
  }
@@ -206,11 +467,16 @@ class Tracing {
206
467
  Tracing._global.XMLHttpRequest = xhrProxy;
207
468
  }
208
469
  networkInstrumentation(options) {
470
+ var _a;
209
471
  utility.requireArgument(options, 'options', ['boolean', 'object']);
210
472
  if (options) {
211
473
  this._disableNetworkInstrumentation();
212
474
  const tracingOptions = typeof options === 'object' ? options : {};
213
- this._enableNetworkInstrumentation(utility.definedValueOrDefault(tracingOptions.instrumentation, this._instr), utility.definedValueOrDefault(tracingOptions.logErrors, true), tracingOptions.activityName, utility.definedValueOrDefault(tracingOptions.useTracing, true), tracingOptions.tracingHeadersOptions);
475
+ let tasker = undefined;
476
+ if (utility.definedValueOrDefault(tracingOptions.useTasker, true)) {
477
+ tasker = (_a = this._idleDetector) === null || _a === void 0 ? void 0 : _a.declareNotifierTaskMulti('o11y network');
478
+ }
479
+ this._enableNetworkInstrumentation(utility.definedValueOrDefault(tracingOptions.instrumentation, this._instr), utility.definedValueOrDefault(tracingOptions.logErrors, true), tracingOptions.activityName, utility.definedValueOrDefault(tracingOptions.useTracing, true), tracingOptions.tracingHeadersOptions, tasker);
214
480
  }
215
481
  else {
216
482
  this._disableNetworkInstrumentation();
@@ -418,20 +684,6 @@ class ActivityImpl {
418
684
  }
419
685
  ActivityImpl._count = 0;
420
686
 
421
- const activity={namespace:"sf.instrumentation",name:"Activity",pbjsSchema:{"nested":{"sf":{"nested":{"instrumentation":{"nested":{"Activity":{"reserved":[[5,5],[7,7]],"fields":{"duration":{"id":3,"type":"double"},"stopReason":{"id":6,"type":"string"},"isRoot":{"id":8,"type":"bool"},"timerOverridden":{"id":12,"type":"uint32"},"name":{"options":{"(meta.max_length)":25},"id":2,"type":"string"},"isSampled":{"id":11,"type":"bool"},"preRootId":{"id":9,"type":"string"},"id":{"id":1,"type":"string"},
422
- "userPayload":{"id":4,"type":"Payload"},"errorCount":{"id":10,"type":"uint32"},"parentId":{"id":13,"type":"string"}}},"Payload":{"fields":{"payload":{"id":2,"type":"bytes"},"schemaName":{"id":1,"type":"string"}}}}}}}}}};
423
-
424
- const error={namespace:"sf.instrumentation",name:"Error",pbjsSchema:{"nested":{"sf":{"nested":{"instrumentation":{"nested":{"Error":{"reserved":[[5,5],[7,7]],"fields":{"activityId":{"id":6,"type":"string"},"stack":{"id":3,"type":"string"},"name":{"id":1,"type":"string"},"message":{"options":{"(meta.max_length)":200},"id":2,"type":"string"},"userPayload":{"id":4,"type":"Payload"}}},"Payload":{"fields":{"payload":{"id":2,"type":"bytes"},"schemaName":{"id":1,"type":"string"}}}}}}}}}};
425
-
426
- const idle_detector_report={namespace:"sf.instrumentation",name:"IdleDetectorReport",pbjsSchema:{"nested":{"sf":{"nested":{"instrumentation":{"nested":{"IdleDetectorReport":{"fields":{"listenerCount":{"id":3,"type":"uint32"},"busyTasks":{"rule":"repeated","id":5,"type":"string"},"busyDurations":{"rule":"repeated","id":6,"type":"double"},"pollableCount":{"id":4,"type":"uint32"},"pollCounts":{"rule":"repeated","id":8,"type":"double"},"logThreshold":{"id":2,"type":"double"},"maxDuration":{"id":1,
427
- "type":"double"},"pollables":{"rule":"repeated","id":7,"type":"string"}}}}}}}}}};
428
-
429
- const instrumented_event={namespace:"sf.instrumentation",name:"InstrumentedEvent",pbjsSchema:{"nested":{"sf":{"nested":{"instrumentation":{"nested":{"MouseEvent":{"fields":{"cancelable":{"id":5,"type":"bool"},"ctrlKey":{"id":9,"type":"bool"},"type":{"id":25,"type":"string"},"button":{"id":3,"type":"uint32"},"offsetX":{"id":17,"type":"uint32"},"eventPhase":{"id":12,"type":"uint32"},"shiftKey":{"id":23,"type":"bool"},"offsetY":{"id":18,"type":"uint32"},"composed":{"id":8,"type":"bool"},"altKey":{"id":1,
430
- "type":"bool"},"isTrusted":{"id":13,"type":"bool"},"buttons":{"id":4,"type":"uint32"},"movementY":{"id":16,"type":"uint32"},"clientY":{"id":7,"type":"uint32"},"clientX":{"id":6,"type":"uint32"},"movementX":{"id":15,"type":"uint32"},"defaultPrevented":{"id":10,"type":"bool"},"metaKey":{"id":14,"type":"bool"},"timeStamp":{"id":24,"type":"double"},"bubbles":{"id":2,"type":"bool"},"detail":{"id":11,"type":"int64"},"pageY":{"id":20,"type":"uint32"},"pageX":{"id":19,"type":"uint32"},"screenX":{"id":21,
431
- "type":"uint32"},"screenY":{"id":22,"type":"uint32"}}},"InstrumentedEvent":{"oneofs":{"event":{"oneof":["mouseEvent"]}},"reserved":[[4,4],"xpath",[6,6],[8,8]],"fields":{"mouseEvent":{"id":7,"type":"MouseEvent"},"auto":{"id":3,"type":"bool"},"parentComponent":{"id":2,"type":"string"},"ownerComponent":{"id":1,"type":"string"},"userPayload":{"id":5,"type":"Payload"},"simplePath":{"id":9,"type":"string"}}},"Payload":{"fields":{"payload":{"id":2,"type":"bytes"},"schemaName":{"id":1,"type":"string"}}}}}}}}}};
432
-
433
- const simple={namespace:"sf.instrumentation",name:"Simple",pbjsSchema:{"nested":{"sf":{"nested":{"instrumentation":{"nested":{"Simple":{"fields":{"text":{"options":{"(meta.max_length)":25},"id":1,"type":"string"}}}}}}}}}};
434
-
435
687
  const id = new Array(16).fill(0).join('');
436
688
  class ActivityNoOp {
437
689
  getId() {
@@ -1501,7 +1753,8 @@ const maxInstrumentationLength = 80;
1501
1753
  const truncatedText = '_CUT';
1502
1754
  const maxInstrumentationLengthBeforeTruncated = maxInstrumentationLength - truncatedText.length;
1503
1755
  class NextgenImpl {
1504
- constructor() {
1756
+ constructor(_idleDetector) {
1757
+ this._idleDetector = _idleDetector;
1505
1758
  this._logCollectors = new Set();
1506
1759
  this._instruments = new Map();
1507
1760
  this._seqBySchema = new Map();
@@ -1536,7 +1789,7 @@ class NextgenImpl {
1536
1789
  this._appInstr = new AppInstrumentationImpl(this, name, options === null || options === void 0 ? void 0 : options.allowMultipleRootActivities);
1537
1790
  this._instruments.set(name, this._appInstr);
1538
1791
  this._isBufferingEnabled = options === null || options === void 0 ? void 0 : options.enableBuffering;
1539
- const tracing = new Tracing(this._appInstr);
1792
+ const tracing = new Tracing(this._appInstr, this._idleDetector);
1540
1793
  return {
1541
1794
  log: this._appInstr.log.bind(this._appInstr),
1542
1795
  error: this._appInstr.error.bind(this._appInstr),
@@ -1718,9 +1971,13 @@ class NextgenImpl {
1718
1971
  NextgenImpl._collectorFailureLimit = 5;
1719
1972
 
1720
1973
  class Index {
1974
+ constructor(_idleDetector) {
1975
+ this._idleDetector = _idleDetector;
1976
+ utility.requireArgument(_idleDetector, '_idleDetector');
1977
+ }
1721
1978
  get _lazyNextGen() {
1722
1979
  if (!this._nextgen) {
1723
- this._nextgen = new NextgenImpl();
1980
+ this._nextgen = new NextgenImpl(this._idleDetector);
1724
1981
  }
1725
1982
  return this._nextgen;
1726
1983
  }
@@ -1739,249 +1996,8 @@ class Index {
1739
1996
  return this._lazyNextGen.getInstrumentation(name);
1740
1997
  }
1741
1998
  }
1742
- const index = new Index();
1743
- const registerInstrumentedApp = index.registerInstrumentedApp.bind(index);
1744
- const getInstrumentation = index.getInstrumentation.bind(index);
1745
1999
  const time = utility.time.bind(utility);
1746
2000
 
1747
- class TaskerImpl {
1748
- constructor(name, initialCount, _doneCallback, _overDoneCallback) {
1749
- this.name = name;
1750
- this._doneCallback = _doneCallback;
1751
- this._overDoneCallback = _overDoneCallback;
1752
- this._busyCount = 0;
1753
- this._isOk = true;
1754
- this._busyCount = initialCount;
1755
- }
1756
- get isBusy() {
1757
- return this._isOk ? this._busyCount > 0 : undefined;
1758
- }
1759
- add() {
1760
- if (this._isOk) {
1761
- this._busyCount += 1;
1762
- }
1763
- }
1764
- done() {
1765
- if (this._isOk) {
1766
- if (this._busyCount > 0) {
1767
- this._busyCount -= 1;
1768
- if (!this._busyCount) {
1769
- this._doneCallback();
1770
- }
1771
- }
1772
- else {
1773
- this._isOk = false;
1774
- this._overDoneCallback();
1775
- }
1776
- }
1777
- }
1778
- }
1779
-
1780
- const defaultLogThreshold = 300;
1781
- class IdleDetectorImpl {
1782
- constructor(options) {
1783
- this._instr = getInstrumentation('IdleDetector');
1784
- this._taskers = new Map();
1785
- this._listeners = new Set();
1786
- this._busyCheckers = new Map();
1787
- this._logThreshold = defaultLogThreshold;
1788
- this._endedTasks = new Array();
1789
- this._pollableReport = new Array();
1790
- if (utility.requireArgumentIfDefined(options === null || options === void 0 ? void 0 : options.logThreshold, 'options.logThreshold', 'number')) {
1791
- this._logThreshold = options.logThreshold;
1792
- }
1793
- }
1794
- requestIdleDetectedCallback(callback) {
1795
- utility.requireArgument(callback, 'callback', 'function');
1796
- if (this._listeners.size === 0) {
1797
- this._firstCallbackTime = utility.time().perfNow;
1798
- }
1799
- this._listeners.add(callback);
1800
- this._checkIfLoaded();
1801
- }
1802
- _reportTaskEnded(tasker) {
1803
- if (this._listeners.size) {
1804
- const snapshot = Object.assign({}, this._taskers.get(tasker));
1805
- this._endedTasks.push(snapshot);
1806
- }
1807
- }
1808
- declareNotifierTaskSingle(name) {
1809
- utility.requireArgument(name, 'name', 'string');
1810
- const tasker = this._addTasker(name, 1);
1811
- const retVal = {
1812
- get isBusy() {
1813
- return tasker.isBusy;
1814
- },
1815
- done: () => {
1816
- tasker.done();
1817
- this._taskers.delete(tasker);
1818
- }
1819
- };
1820
- return retVal;
1821
- }
1822
- declareNotifierTaskMulti(name, existingBusyCount = 0) {
1823
- utility.requireArgument(name, 'name', 'string');
1824
- if (existingBusyCount !== undefined) {
1825
- utility.requireArgument(existingBusyCount, 'existingBusyCount', 'number');
1826
- if (!Number.isInteger(existingBusyCount) || existingBusyCount < 0) {
1827
- throw new Error('existingBusyCount accepts only non-negative integers');
1828
- }
1829
- }
1830
- const tasker = this._addTasker(name, existingBusyCount);
1831
- const retVal = {
1832
- get isBusy() {
1833
- return tasker.isBusy;
1834
- },
1835
- add: () => {
1836
- if (!tasker.isBusy) {
1837
- const meta = this._taskers.get(tasker);
1838
- meta.start = utility.time().perfNow;
1839
- meta.end = undefined;
1840
- }
1841
- tasker.add();
1842
- },
1843
- done: tasker.done.bind(tasker)
1844
- };
1845
- return retVal;
1846
- }
1847
- declarePollableTaskMulti(name, isBusyChecker) {
1848
- utility.requireArgument(name, 'name', 'string');
1849
- utility.requireArgument(isBusyChecker, 'isBusyChecker', 'function');
1850
- this._busyCheckers.set(isBusyChecker, name);
1851
- }
1852
- _addTasker(name, existingBusyCount) {
1853
- const tasker = new TaskerImpl(name, existingBusyCount, () => {
1854
- this._taskers.get(tasker).end = utility.time().perfNow;
1855
- this._reportTaskEnded(tasker);
1856
- this._checkIfLoaded();
1857
- }, () => {
1858
- this._instr.error(`Overdone: ${tasker.name}`);
1859
- utility.noProdThrow(`Tasker '${tasker.name}' is done too many times.`);
1860
- });
1861
- this._taskers.set(tasker, {
1862
- name,
1863
- start: existingBusyCount > 0 ? utility.time().perfNow : undefined,
1864
- end: undefined
1865
- });
1866
- return tasker;
1867
- }
1868
- _areAllNotifiersIdle() {
1869
- return !Array.from(this._taskers.keys()).some((t) => t.isBusy);
1870
- }
1871
- _getFirstBusyPollable() {
1872
- const entry = Array.from(this._busyCheckers).find((entry) => {
1873
- const isBusyChecker = entry[0];
1874
- const name = entry[1];
1875
- try {
1876
- return isBusyChecker();
1877
- }
1878
- catch (e) {
1879
- this._instr.error(e, `BusyChecker ${name}`);
1880
- utility.noProdThrow(e);
1881
- return false;
1882
- }
1883
- });
1884
- return entry ? entry[1] : undefined;
1885
- }
1886
- _checkIfLoaded() {
1887
- if (!this._listeners.size) {
1888
- return;
1889
- }
1890
- if (this._timerCheckQueued) {
1891
- clearTimeout(this._timerCheckQueued);
1892
- }
1893
- if (this._areAllNotifiersIdle()) {
1894
- this._timerCheckQueued = setTimeout(() => {
1895
- this._timerCheckQueued = setTimeout(() => {
1896
- this._doubleCheck();
1897
- }, 40);
1898
- }, 0);
1899
- }
1900
- }
1901
- _doubleCheck() {
1902
- this._timerCheckQueued = undefined;
1903
- if (this._areAllNotifiersIdle()) {
1904
- const pollableName = this._getFirstBusyPollable();
1905
- if (pollableName !== undefined) {
1906
- this._addToPollableReport(pollableName);
1907
- this._timerCheckQueued = setTimeout(() => {
1908
- this._doubleCheck();
1909
- }, 15);
1910
- }
1911
- else {
1912
- const maxDuration = utility.time().perfNow - this._firstCallbackTime;
1913
- const listeners = Array.from(this._listeners.values());
1914
- this._listeners.clear();
1915
- this._firstCallbackTime = undefined;
1916
- const endedTasks = this._endedTasks.splice(0);
1917
- const pollableReport = this._pollableReport.splice(0);
1918
- this._notify(listeners, maxDuration, endedTasks, pollableReport);
1919
- }
1920
- }
1921
- }
1922
- _addToPollableReport(name) {
1923
- const lastEntry = this._pollableReport.length
1924
- ? this._pollableReport[this._pollableReport.length - 1]
1925
- : undefined;
1926
- if ((lastEntry === null || lastEntry === void 0 ? void 0 : lastEntry.name) === name) {
1927
- lastEntry.count += 1;
1928
- }
1929
- else {
1930
- this._pollableReport.push({
1931
- name,
1932
- count: 1
1933
- });
1934
- }
1935
- }
1936
- _notify(listeners, maxDuration, taskReport, pollableReport) {
1937
- if (maxDuration >= this._logThreshold) {
1938
- const logData = this._getReport(maxDuration, listeners.length, taskReport, pollableReport);
1939
- this._instr.log(idle_detector_report, logData);
1940
- }
1941
- listeners.reverse();
1942
- const tsNow = utility.time().tsNow;
1943
- for (const [index, listener] of listeners.entries()) {
1944
- try {
1945
- listener(tsNow);
1946
- }
1947
- catch (e) {
1948
- this._instr.error(e, `Listener #${listeners.length - 1 - index}`);
1949
- utility.noProdThrow(e);
1950
- }
1951
- }
1952
- }
1953
- getReport() {
1954
- const perfNow = utility.time().perfNow;
1955
- const maxDuration = this._firstCallbackTime > 0 ? perfNow - this._firstCallbackTime : undefined;
1956
- const onGoingTasks = Array.from(this._taskers.entries())
1957
- .filter((e) => e[0].isBusy)
1958
- .map((e) => ({
1959
- name: e[1].name,
1960
- start: e[1].start,
1961
- end: perfNow
1962
- }));
1963
- return this._getReport(maxDuration, this._listeners.size, this._endedTasks.concat(onGoingTasks), this._pollableReport);
1964
- }
1965
- _getReport(maxDuration, listenerCount, taskReport, pollableReport) {
1966
- const sortedTaskers = taskReport
1967
- .map((t) => ({
1968
- name: t.name,
1969
- duration: t.end - t.start
1970
- }))
1971
- .sort((a, b) => b.duration - a.duration);
1972
- return {
1973
- logThreshold: this._logThreshold,
1974
- maxDuration,
1975
- listenerCount,
1976
- pollableCount: this._busyCheckers.size,
1977
- busyTasks: sortedTaskers.map((t) => t.name),
1978
- busyDurations: sortedTaskers.map((t) => t.duration),
1979
- pollables: pollableReport.map((p) => p.name),
1980
- pollCounts: pollableReport.map((p) => p.count)
1981
- };
1982
- }
1983
- }
1984
-
1985
2001
  const bgColorMap = {
1986
2002
  Error: 'Crimson',
1987
2003
  Activity: 'CadetBlue',
@@ -2020,11 +2036,21 @@ class ConsoleCollector {
2020
2036
  }
2021
2037
  }
2022
2038
 
2023
- const version = '244.2.1';
2039
+ const version = '244.3.0';
2024
2040
 
2025
2041
  const idleDetector = new IdleDetectorImpl({
2026
- logThreshold: 300
2042
+ logThreshold: 300,
2043
+ reportListener: (report) => {
2044
+ idleDetectorInstr === null || idleDetectorInstr === void 0 ? void 0 : idleDetectorInstr.log(idle_detector_report, report);
2045
+ },
2046
+ errorListener: (e, text) => {
2047
+ idleDetectorInstr === null || idleDetectorInstr === void 0 ? void 0 : idleDetectorInstr.error(e, text);
2048
+ }
2027
2049
  });
2050
+ const index = new Index(idleDetector);
2051
+ const registerInstrumentedApp = index.registerInstrumentedApp.bind(index);
2052
+ const getInstrumentation = index.getInstrumentation.bind(index);
2053
+ const idleDetectorInstr = getInstrumentation('IdleDetector');
2028
2054
 
2029
2055
  export { ConsoleCollector, version as _version, getInstrumentation, idleDetector, registerInstrumentedApp, time };
2030
2056
  //# sourceMappingURL=client.js.map