o11y 248.8.0 → 248.10.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 (71) hide show
  1. package/dist/modules/o11y/client/client.js +301 -21
  2. package/dist/modules/o11y/client/client.js.map +1 -1
  3. package/dist/modules/o11y/client/interfaces/Activity.d.ts +1 -0
  4. package/dist/modules/o11y/client/interfaces/NetworkInstrumentationOptions.d.ts +2 -0
  5. package/dist/modules/o11y/client/library/ActivityImpl.d.ts +1 -0
  6. package/dist/modules/o11y/client/library/ActivityNoOp.d.ts +1 -0
  7. package/dist/modules/o11y/client/library/FuzzyMapper.d.ts +8 -0
  8. package/dist/modules/o11y/client/library/PerformanceObservability.d.ts +31 -0
  9. package/dist/modules/o11y/client/library/RootActivityNoOp.d.ts +1 -0
  10. package/dist/modules/o11y/client/library/Tracing.d.ts +4 -2
  11. package/dist/modules/o11y/client/test/TestEnvironment.d.ts +3 -3
  12. package/dist/modules/o11y/client/types/TypeDefinitions-Private.d.ts +45 -0
  13. package/dist/modules/o11y/client/version.d.ts +1 -1
  14. package/dist/modules/o11y/collectors/interfaces/Activity.d.ts +1 -0
  15. package/dist/modules/o11y/collectors/interfaces/NetworkInstrumentationOptions.d.ts +2 -0
  16. package/dist/modules/o11y/collectors/library/ActivityImpl.d.ts +1 -0
  17. package/dist/modules/o11y/collectors/library/ActivityNoOp.d.ts +1 -0
  18. package/dist/modules/o11y/collectors/library/FuzzyMapper.d.ts +8 -0
  19. package/dist/modules/o11y/collectors/library/PerformanceObservability.d.ts +31 -0
  20. package/dist/modules/o11y/collectors/library/RootActivityNoOp.d.ts +1 -0
  21. package/dist/modules/o11y/collectors/library/Tracing.d.ts +4 -2
  22. package/dist/modules/o11y/collectors/test/TestEnvironment.d.ts +3 -3
  23. package/dist/modules/o11y/collectors/types/TypeDefinitions-Private.d.ts +45 -0
  24. package/dist/modules/o11y/collectors/version.d.ts +1 -1
  25. package/dist/modules/o11y/core_envelope/core_envelope.js +1 -1
  26. package/dist/modules/o11y/core_envelope/core_envelope.js.map +1 -1
  27. package/dist/modules/o11y/core_envelope/interfaces/Activity.d.ts +1 -0
  28. package/dist/modules/o11y/core_envelope/interfaces/NetworkInstrumentationOptions.d.ts +2 -0
  29. package/dist/modules/o11y/core_envelope/library/ActivityImpl.d.ts +1 -0
  30. package/dist/modules/o11y/core_envelope/library/ActivityNoOp.d.ts +1 -0
  31. package/dist/modules/o11y/core_envelope/library/FuzzyMapper.d.ts +8 -0
  32. package/dist/modules/o11y/core_envelope/library/PerformanceObservability.d.ts +31 -0
  33. package/dist/modules/o11y/core_envelope/library/RootActivityNoOp.d.ts +1 -0
  34. package/dist/modules/o11y/core_envelope/library/Tracing.d.ts +4 -2
  35. package/dist/modules/o11y/core_envelope/test/TestEnvironment.d.ts +3 -3
  36. package/dist/modules/o11y/core_envelope/types/TypeDefinitions-Private.d.ts +45 -0
  37. package/dist/modules/o11y/core_envelope/version.d.ts +1 -1
  38. package/dist/modules/o11y/shared/interfaces/Activity.d.ts +1 -0
  39. package/dist/modules/o11y/shared/interfaces/NetworkInstrumentationOptions.d.ts +2 -0
  40. package/dist/modules/o11y/shared/library/ActivityImpl.d.ts +1 -0
  41. package/dist/modules/o11y/shared/library/ActivityNoOp.d.ts +1 -0
  42. package/dist/modules/o11y/shared/library/FuzzyMapper.d.ts +8 -0
  43. package/dist/modules/o11y/shared/library/PerformanceObservability.d.ts +31 -0
  44. package/dist/modules/o11y/shared/library/RootActivityNoOp.d.ts +1 -0
  45. package/dist/modules/o11y/shared/library/Tracing.d.ts +4 -2
  46. package/dist/modules/o11y/shared/test/TestEnvironment.d.ts +3 -3
  47. package/dist/modules/o11y/shared/types/TypeDefinitions-Private.d.ts +45 -0
  48. package/dist/modules/o11y/shared/version.d.ts +1 -1
  49. package/dist/modules/o11y/simple_collector/interfaces/Activity.d.ts +1 -0
  50. package/dist/modules/o11y/simple_collector/interfaces/NetworkInstrumentationOptions.d.ts +2 -0
  51. package/dist/modules/o11y/simple_collector/library/ActivityImpl.d.ts +1 -0
  52. package/dist/modules/o11y/simple_collector/library/ActivityNoOp.d.ts +1 -0
  53. package/dist/modules/o11y/simple_collector/library/FuzzyMapper.d.ts +8 -0
  54. package/dist/modules/o11y/simple_collector/library/PerformanceObservability.d.ts +31 -0
  55. package/dist/modules/o11y/simple_collector/library/RootActivityNoOp.d.ts +1 -0
  56. package/dist/modules/o11y/simple_collector/library/Tracing.d.ts +4 -2
  57. package/dist/modules/o11y/simple_collector/test/TestEnvironment.d.ts +3 -3
  58. package/dist/modules/o11y/simple_collector/types/TypeDefinitions-Private.d.ts +45 -0
  59. package/dist/modules/o11y/simple_collector/version.d.ts +1 -1
  60. package/dist/modules/o11y/web_vitals/interfaces/Activity.d.ts +1 -0
  61. package/dist/modules/o11y/web_vitals/interfaces/NetworkInstrumentationOptions.d.ts +2 -0
  62. package/dist/modules/o11y/web_vitals/library/ActivityImpl.d.ts +1 -0
  63. package/dist/modules/o11y/web_vitals/library/ActivityNoOp.d.ts +1 -0
  64. package/dist/modules/o11y/web_vitals/library/FuzzyMapper.d.ts +8 -0
  65. package/dist/modules/o11y/web_vitals/library/PerformanceObservability.d.ts +31 -0
  66. package/dist/modules/o11y/web_vitals/library/RootActivityNoOp.d.ts +1 -0
  67. package/dist/modules/o11y/web_vitals/library/Tracing.d.ts +4 -2
  68. package/dist/modules/o11y/web_vitals/test/TestEnvironment.d.ts +3 -3
  69. package/dist/modules/o11y/web_vitals/types/TypeDefinitions-Private.d.ts +45 -0
  70. package/dist/modules/o11y/web_vitals/version.d.ts +1 -1
  71. package/package.json +4 -3
@@ -1,4 +1,4 @@
1
- import { simpleSchema, errorSchema, activitySchema, instrumentedEventSchema, idleDetectorReportSchema } from 'o11y_schema/sf_instrumentation';
1
+ import { networkSchema, simpleSchema, errorSchema, activitySchema, instrumentedEventSchema, idleDetectorReportSchema } from 'o11y_schema/sf_instrumentation';
2
2
  import { utility, PublicSafety, schemaUtil, maxStringLengthAppLimit, metricsUtility, payloadUtility } from 'o11y/shared';
3
3
 
4
4
  class TaskerImpl {
@@ -247,6 +247,202 @@ class IdleDetectorImpl {
247
247
  }
248
248
  }
249
249
 
250
+ const navigation_timing={namespace:"sfcore.performance",name:"NavigationTiming",pbjsSchema:{"nested":{"sfcore":{"nested":{"performance":{"nested":{"NavigationTiming":{"oneofs":{"_xhrDelay":{"oneof":["xhrDelay"]},"_renderBlockingStatus":{"oneof":["renderBlockingStatus"]},"_firstInterimResponseStart":{"oneof":["firstInterimResponseStart"]},"_srvDuration":{"oneof":["srvDuration"]},"_isCdnCached":{"oneof":["isCdnCached"]},"_dbDuration":{"oneof":["dbDuration"]},"_reqBatchCount":{"oneof":["reqBatchCount"]}},
251
+ "fields":{"redirectCount":{"id":37,"type":"uint32"},"encodedBodySize":{"id":21,"type":"uint32"},"reqActionNames":{"rule":"repeated","id":28,"type":"string"},"unloadEventEnd":{"id":40,"type":"double"},"responseEnd":{"id":19,"type":"double"},"domainLookupEnd":{"id":12,"type":"double"},"unloadEventStart":{"id":39,"type":"double"},"domContentLoadedEventStart":{"id":32,"type":"double"},"type":{"id":38,"type":"string"},"firstInterimResponseStart":{"options":{"proto3_optional":true},"id":18,"type":"double"},
252
+ "duration":{"id":3,"type":"double"},"decodedBodySize":{"id":22,"type":"uint32"},"redirectStart":{"id":8,"type":"double"},"connectEnd":{"id":15,"type":"double"},"isCdnCached":{"options":{"proto3_optional":true},"id":24,"type":"bool"},"requestStart":{"id":16,"type":"double"},"startTime":{"id":2,"type":"double"},"fetchStart":{"id":10,"type":"double"},"domContentLoadedEventEnd":{"id":33,"type":"double"},"srvReqId":{"id":29,"type":"string"},"reqBatchCount":{"options":{"proto3_optional":true},"id":27,"type":"uint32"},
253
+ "renderBlockingStatus":{"options":{"proto3_optional":true},"id":6,"type":"string"},"workerStart":{"id":7,"type":"double"},"responseStart":{"id":17,"type":"double"},"xhrDelay":{"options":{"proto3_optional":true},"id":30,"type":"double"},"domInteractive":{"id":34,"type":"double"},"domComplete":{"id":31,"type":"double"},"domainLookupStart":{"id":11,"type":"double"},"responseStatus":{"id":23,"type":"uint32"},"redirectEnd":{"id":9,"type":"double"},"transferSize":{"id":20,"type":"uint32"},"srvDuration":{"options":{"proto3_optional":true},
254
+ "id":26,"type":"double"},"dbDuration":{"options":{"proto3_optional":true},"id":25,"type":"double"},"connectStart":{"id":13,"type":"double"},"loadEventStart":{"id":35,"type":"double"},"secureConnectionStart":{"id":14,"type":"double"},"name":{"id":1,"type":"string"},"nextHopProtocol":{"id":5,"type":"string"},"initiatorType":{"id":4,"type":"string"},"loadEventEnd":{"id":36,"type":"double"}}}}}}}}}};
255
+
256
+ const resource_timing={namespace:"sfcore.performance",name:"ResourceTiming",pbjsSchema:{"nested":{"sfcore":{"nested":{"performance":{"nested":{"ResourceTiming":{"oneofs":{"_xhrDelay":{"oneof":["xhrDelay"]},"_renderBlockingStatus":{"oneof":["renderBlockingStatus"]},"_firstInterimResponseStart":{"oneof":["firstInterimResponseStart"]},"_srvDuration":{"oneof":["srvDuration"]},"_isCdnCached":{"oneof":["isCdnCached"]},"_dbDuration":{"oneof":["dbDuration"]},"_reqBatchCount":{"oneof":["reqBatchCount"]}},
257
+ "fields":{"encodedBodySize":{"id":21,"type":"uint32"},"reqActionNames":{"rule":"repeated","id":28,"type":"string"},"responseEnd":{"id":19,"type":"double"},"domainLookupEnd":{"id":12,"type":"double"},"firstInterimResponseStart":{"options":{"proto3_optional":true},"id":18,"type":"double"},"duration":{"id":3,"type":"double"},"decodedBodySize":{"id":22,"type":"uint32"},"redirectStart":{"id":8,"type":"double"},"connectEnd":{"id":15,"type":"double"},"isCdnCached":{"options":{"proto3_optional":true},"id":24,
258
+ "type":"bool"},"requestStart":{"id":16,"type":"double"},"startTime":{"id":2,"type":"double"},"fetchStart":{"id":10,"type":"double"},"srvReqId":{"id":29,"type":"string"},"reqBatchCount":{"options":{"proto3_optional":true},"id":27,"type":"uint32"},"renderBlockingStatus":{"options":{"proto3_optional":true},"id":6,"type":"string"},"workerStart":{"id":7,"type":"double"},"responseStart":{"id":17,"type":"double"},"xhrDelay":{"options":{"proto3_optional":true},"id":30,"type":"double"},"domainLookupStart":{"id":11,
259
+ "type":"double"},"responseStatus":{"id":23,"type":"uint32"},"redirectEnd":{"id":9,"type":"double"},"transferSize":{"id":20,"type":"uint32"},"srvDuration":{"options":{"proto3_optional":true},"id":26,"type":"double"},"dbDuration":{"options":{"proto3_optional":true},"id":25,"type":"double"},"connectStart":{"id":13,"type":"double"},"secureConnectionStart":{"id":14,"type":"double"},"name":{"id":1,"type":"string"},"nextHopProtocol":{"id":5,"type":"string"},"initiatorType":{"id":4,"type":"string"}}}}}}}}}};
260
+
261
+ class FuzzyMapper {
262
+ constructor(_fuzzyKeyRange) {
263
+ this._fuzzyKeyRange = _fuzzyKeyRange;
264
+ this._map = new Map();
265
+ utility.requireArgument(_fuzzyKeyRange, '_fuzzyKeyRange', 'number');
266
+ }
267
+ add(key, fuzzyKey, value) {
268
+ const mapValue = this._map.get(key);
269
+ if (mapValue) {
270
+ mapValue.push({ fuzzyKey, value });
271
+ }
272
+ else {
273
+ this._map.set(key, [{ fuzzyKey, value }]);
274
+ }
275
+ }
276
+ pop(key, fuzzyKey) {
277
+ const mapValues = this._map.get(key);
278
+ if ((mapValues === null || mapValues === void 0 ? void 0 : mapValues.length) >= 1) {
279
+ let minDelta = Number.POSITIVE_INFINITY;
280
+ let minIndex = -1;
281
+ for (let index = 0; index < mapValues.length; index++) {
282
+ const { fuzzyKey: curFuzzyKey } = mapValues[index];
283
+ const curDelta = Math.abs(curFuzzyKey - fuzzyKey);
284
+ if (curDelta <= this._fuzzyKeyRange && curDelta < minDelta) {
285
+ minDelta = curDelta;
286
+ minIndex = index;
287
+ }
288
+ }
289
+ if (minIndex >= 0) {
290
+ const { value } = mapValues.splice(minIndex, 1)[0];
291
+ if (mapValues.length === 0) {
292
+ this._map.delete(key);
293
+ }
294
+ return value;
295
+ }
296
+ }
297
+ return undefined;
298
+ }
299
+ clear() {
300
+ this._map.clear();
301
+ }
302
+ }
303
+
304
+ const basicInitiatorTypes = ['fetch', 'xmlhttprequest'];
305
+ class PerformanceObservability {
306
+ constructor(_instr, _logPerformanceActivityName, logLevel) {
307
+ this._instr = _instr;
308
+ this._logPerformanceActivityName = _logPerformanceActivityName;
309
+ this._fuzzyMapper = new FuzzyMapper(50);
310
+ this._isStarted = false;
311
+ this._hasPerf =
312
+ typeof performance !== 'undefined' && typeof PerformanceObserver === 'function';
313
+ this._boundOobserverCallback = this._logPerformanceEntries.bind(this);
314
+ if (!logLevel || logLevel.toLowerCase() === 'full') {
315
+ this._logLevel = 1;
316
+ }
317
+ else if ((logLevel === null || logLevel === void 0 ? void 0 : logLevel.toLowerCase()) === 'basic') {
318
+ this._logLevel = 0;
319
+ }
320
+ else {
321
+ throw new Error(`Invalid log level: ${logLevel}`);
322
+ }
323
+ }
324
+ get isStarted() {
325
+ return this._isStarted;
326
+ }
327
+ get logLevel() {
328
+ return this._logLevel;
329
+ }
330
+ start() {
331
+ if (!this._hasPerf) {
332
+ return;
333
+ }
334
+ if (!this._isStarted) {
335
+ this._isStarted = true;
336
+ this._navigationObserver = new PerformanceObserver(this._boundOobserverCallback);
337
+ this._navigationObserver.observe({ type: 'navigation', buffered: true });
338
+ this._resourceObserver = new PerformanceObserver(this._boundOobserverCallback);
339
+ this._resourceObserver.observe({ type: 'resource', buffered: true });
340
+ }
341
+ }
342
+ stop() {
343
+ if (this._resourceObserver) {
344
+ this._resourceObserver.disconnect();
345
+ this._resourceObserver = undefined;
346
+ }
347
+ if (this._navigationObserver) {
348
+ this._navigationObserver.disconnect();
349
+ this._navigationObserver = undefined;
350
+ }
351
+ this._fuzzyMapper.clear();
352
+ this._isStarted = false;
353
+ }
354
+ addEntry(url, perfTime, data) {
355
+ this._fuzzyMapper.add(url, perfTime, data);
356
+ }
357
+ _resourceEntryToResourceTiming(prt) {
358
+ var _a, _b;
359
+ const rt = {
360
+ name: prt.name,
361
+ startTime: prt.startTime,
362
+ duration: prt.duration,
363
+ initiatorType: prt.initiatorType,
364
+ nextHopProtocol: prt.nextHopProtocol,
365
+ renderBlockingStatus: prt.renderBlockingStatus,
366
+ workerStart: prt.workerStart,
367
+ redirectStart: prt.redirectStart,
368
+ redirectEnd: prt.redirectEnd,
369
+ fetchStart: prt.fetchStart,
370
+ domainLookupStart: prt.domainLookupStart,
371
+ domainLookupEnd: prt.domainLookupEnd,
372
+ connectStart: prt.connectStart,
373
+ secureConnectionStart: prt.secureConnectionStart,
374
+ connectEnd: prt.connectEnd,
375
+ requestStart: prt.requestStart,
376
+ responseStart: prt.responseStart,
377
+ firstInterimResponseStart: prt.firstInterimResponseStart,
378
+ responseEnd: prt.responseEnd,
379
+ transferSize: prt.transferSize,
380
+ encodedBodySize: prt.encodedBodySize,
381
+ decodedBodySize: prt.decodedBodySize,
382
+ responseStatus: prt.responseStatus
383
+ };
384
+ const sts = prt.serverTiming;
385
+ if (Array.isArray(sts)) {
386
+ rt.dbDuration = (_a = sts.find((st) => st.name === 'db')) === null || _a === void 0 ? void 0 : _a.duration;
387
+ rt.srvDuration = (_b = sts.find((st) => st.name === 'Total')) === null || _b === void 0 ? void 0 : _b.duration;
388
+ }
389
+ return rt;
390
+ }
391
+ _shouldInclude(entry) {
392
+ if (this._logLevel === 1) {
393
+ return true;
394
+ }
395
+ return (basicInitiatorTypes.indexOf(entry.initiatorType) >= 0 ||
396
+ entry.entryType === 'navigation');
397
+ }
398
+ _logActivity(schema, payload) {
399
+ const options = {
400
+ perfStartOverride: payload.startTime,
401
+ perfStopOverride: payload.startTime + payload.duration
402
+ };
403
+ this._instr.startActivity(this._logPerformanceActivityName).stop(schema, payload, options);
404
+ }
405
+ _logPerformanceEntries(list) {
406
+ for (const entry of list.getEntriesByType('navigation')) {
407
+ const nt = entry;
408
+ if (this._shouldInclude(nt)) {
409
+ if (nt !== this._navTiming) {
410
+ this._navTiming = nt;
411
+ const payload = this._resourceEntryToResourceTiming(nt);
412
+ const navOnly = {
413
+ domComplete: nt.domComplete,
414
+ domContentLoadedEventStart: nt.domContentLoadedEventStart,
415
+ domContentLoadedEventEnd: nt.domContentLoadedEventEnd,
416
+ domInteractive: nt.domInteractive,
417
+ loadEventStart: nt.loadEventStart,
418
+ loadEventEnd: nt.loadEventEnd,
419
+ redirectCount: nt.redirectCount,
420
+ type: nt.type,
421
+ unloadEventStart: nt.unloadEventStart,
422
+ unloadEventEnd: nt.unloadEventEnd
423
+ };
424
+ this._logActivity(navigation_timing, Object.assign(payload, navOnly));
425
+ }
426
+ break;
427
+ }
428
+ }
429
+ for (const entry of list.getEntriesByType('resource')) {
430
+ const rt = entry;
431
+ if (this._shouldInclude(rt)) {
432
+ const payload = this._resourceEntryToResourceTiming(rt);
433
+ const requestInfo = this._fuzzyMapper.pop(rt.name, rt.startTime);
434
+ Object.assign(payload, {
435
+ srvReqId: requestInfo === null || requestInfo === void 0 ? void 0 : requestInfo.requestId,
436
+ xhrDelay: requestInfo
437
+ ? requestInfo.activityDuration - (rt.startTime + rt.duration)
438
+ : undefined
439
+ });
440
+ this._logActivity(resource_timing, payload);
441
+ }
442
+ }
443
+ }
444
+ }
445
+
250
446
  const defaultTraceIdLengthW3 = 32;
251
447
  const defaultTraceIdLengthB3 = 16;
252
448
  const defaultSpanIdLength = 16;
@@ -256,6 +452,7 @@ const headerTraceId = 'X-B3-TraceId';
256
452
  const headerSpanId = 'X-B3-SpanId';
257
453
  const headerSampled = 'X-B3-Sampled';
258
454
  const headerParentSpanId = 'X-B3-ParentSpanId';
455
+ const headerRequestId = 'X-SFDC-Request-Id';
259
456
  const defaultActivityNameForFetch = 'fetch';
260
457
  const defaultActivityNameForXhrSend = 'xhr_send';
261
458
  class Tracing {
@@ -349,10 +546,14 @@ class Tracing {
349
546
  Tracing._global.XMLHttpRequest.prototype.send = Tracing._originalXhrSend;
350
547
  Tracing._originalXhrSend = undefined;
351
548
  }
549
+ if (Tracing._performanceObservability) {
550
+ Tracing._performanceObservability.stop();
551
+ Tracing._performanceObservability = undefined;
552
+ }
352
553
  Tracing._isNetworkInstrumentationEnabled = false;
353
554
  }
354
555
  }
355
- _enableNetworkInstrumentation(instr, logErrors, activityName, useTracing, options, tasker) {
556
+ _enableNetworkInstrumentation(instr, logErrors, activityName, useTracing, options, tasker, logPerformance, logPerformanceActivityName) {
356
557
  if (typeof Tracing._global.fetch === 'function') {
357
558
  this._overrideFetch(instr, logErrors, activityName, useTracing, options, tasker);
358
559
  Tracing._isNetworkInstrumentationEnabled = true;
@@ -361,6 +562,11 @@ class Tracing {
361
562
  this._overrideXhr(instr, logErrors, activityName, useTracing, options, tasker);
362
563
  Tracing._isNetworkInstrumentationEnabled = true;
363
564
  }
565
+ if (logPerformance) {
566
+ Tracing._performanceObservability = new PerformanceObservability(instr, logPerformanceActivityName, logPerformance === true ? 'full' : logPerformance);
567
+ Tracing._performanceObservability.start();
568
+ Tracing._isNetworkInstrumentationEnabled = true;
569
+ }
364
570
  }
365
571
  static _getTraceHeaders(activity, options, method, url) {
366
572
  let traceHeaders = (activity === null || activity === void 0 ? void 0 : activity.getTraceHeaders(options)) || {};
@@ -384,12 +590,33 @@ class Tracing {
384
590
  }
385
591
  return traceHeaders || {};
386
592
  }
593
+ static _extractHeader(headerName, input, init) {
594
+ if ((init === null || init === void 0 ? void 0 : init.headers) instanceof Headers) {
595
+ return init.headers.get(headerName);
596
+ }
597
+ if (Array.isArray(init === null || init === void 0 ? void 0 : init.headers)) {
598
+ const header = init.headers.find((entry) => entry[0] === headerName);
599
+ return header === null || header === void 0 ? void 0 : header[1];
600
+ }
601
+ if (typeof (init === null || init === void 0 ? void 0 : init.headers) === 'object') {
602
+ return init.headers[headerName];
603
+ }
604
+ if (input instanceof Request) {
605
+ return input.headers.get(headerName);
606
+ }
607
+ return undefined;
608
+ }
387
609
  _overrideFetch(instr, logErrors, activityName, useTracing, tracingHeadersOptions, tasker) {
388
610
  Tracing._originalFetch = Tracing._global.fetch;
389
611
  const o11yFetch = async (resource, options, ...restArgs) => {
612
+ var _a;
390
613
  let activity;
614
+ let url;
615
+ let method;
616
+ let fetchTime;
391
617
  try {
392
618
  tasker === null || tasker === void 0 ? void 0 : tasker.add();
619
+ method = options === null || options === void 0 ? void 0 : options.method;
393
620
  const ofo = options === null || options === void 0 ? void 0 : options.o11y;
394
621
  if (!(ofo === null || ofo === void 0 ? void 0 : ofo.skipInstr)) {
395
622
  activity = instr.startActivity(activityName || defaultActivityNameForFetch);
@@ -407,12 +634,11 @@ class Tracing {
407
634
  resource = urlObj.toString();
408
635
  }
409
636
  }
410
- catch (_a) { }
637
+ catch (_b) { }
411
638
  }
412
639
  options === null || options === void 0 ? true : delete options.o11y;
640
+ url = resource === null || resource === void 0 ? void 0 : resource.toString();
413
641
  if (useTracing) {
414
- let method = options === null || options === void 0 ? void 0 : options.method;
415
- let url = resource === null || resource === void 0 ? void 0 : resource.toString();
416
642
  if (resource instanceof Request) {
417
643
  if (!method) {
418
644
  method = resource.method;
@@ -427,6 +653,7 @@ class Tracing {
427
653
  };
428
654
  }
429
655
  }
656
+ fetchTime = utility.perfNow();
430
657
  return await Tracing._originalFetch.call(Tracing._global, resource, options, ...restArgs);
431
658
  }
432
659
  catch (ex) {
@@ -441,16 +668,56 @@ class Tracing {
441
668
  throw ex;
442
669
  }
443
670
  finally {
444
- activity === null || activity === void 0 ? void 0 : activity.stop();
445
- tasker === null || tasker === void 0 ? void 0 : tasker.done();
671
+ try {
672
+ const activityDuration = Tracing._endActivity(activity, url, method);
673
+ if ((_a = Tracing._performanceObservability) === null || _a === void 0 ? void 0 : _a.isStarted) {
674
+ const requestId = Tracing._extractHeader(headerRequestId, resource, options);
675
+ Tracing._performanceObservability.addEntry(url, fetchTime, {
676
+ requestId,
677
+ activityDuration
678
+ });
679
+ }
680
+ }
681
+ finally {
682
+ tasker === null || tasker === void 0 ? void 0 : tasker.done();
683
+ }
446
684
  }
447
685
  };
448
686
  Tracing._global.fetch = o11yFetch;
449
687
  }
688
+ static _endActivity(activity, url, method) {
689
+ var _a;
690
+ if (activity) {
691
+ if (activity.getErrorCount() == 0 || ((_a = Tracing._performanceObservability) === null || _a === void 0 ? void 0 : _a.isStarted)) {
692
+ activity.discard();
693
+ }
694
+ else {
695
+ activity.stop(networkSchema, {
696
+ mtd: method,
697
+ url
698
+ });
699
+ }
700
+ return activity.getStopPerfTime() - activity.getStartPerfTime();
701
+ }
702
+ return undefined;
703
+ }
450
704
  _overrideXhr(instr, logErrors, activityName, useTracing, options, tasker) {
451
705
  Tracing._originalXhr = Tracing._global.XMLHttpRequest;
452
706
  Tracing._originalXhrOpen = Tracing._originalXhr.prototype.open;
453
707
  Tracing._originalXhrSend = Tracing._originalXhr.prototype.send;
708
+ function postProcess(xhr, failedAtInit) {
709
+ var _a;
710
+ if (xhr._o11y) {
711
+ const activityDuration = Tracing._endActivity(xhr._o11y.activity, xhr._o11y.url, xhr._o11y.method);
712
+ if (!failedAtInit && ((_a = Tracing._performanceObservability) === null || _a === void 0 ? void 0 : _a.isStarted)) {
713
+ const requestId = xhr.getResponseHeader(headerRequestId);
714
+ Tracing._performanceObservability.addEntry(xhr._o11y.url, xhr._o11y.sendTime, {
715
+ requestId,
716
+ activityDuration
717
+ });
718
+ }
719
+ }
720
+ }
454
721
  Tracing._originalXhr.prototype.open = function (method, url, async, username, password) {
455
722
  this._o11y = {
456
723
  method,
@@ -460,9 +727,9 @@ class Tracing {
460
727
  };
461
728
  Tracing._originalXhr.prototype.send = function (...args) {
462
729
  let activity;
730
+ const xhr = this;
463
731
  try {
464
732
  tasker === null || tasker === void 0 ? void 0 : tasker.add();
465
- const xhr = this;
466
733
  xhr._o11y = xhr._o11y || {};
467
734
  xhr._o11y.activity = activity = instr.startActivity(activityName || defaultActivityNameForXhrSend);
468
735
  if (useTracing) {
@@ -471,6 +738,7 @@ class Tracing {
471
738
  xhr.setRequestHeader(entry[0], entry[1]);
472
739
  });
473
740
  }
741
+ xhr._o11y.sendTime = utility.perfNow();
474
742
  Tracing._originalXhrSend.call(this, ...args);
475
743
  }
476
744
  catch (ex) {
@@ -482,7 +750,7 @@ class Tracing {
482
750
  instr.error(ex);
483
751
  }
484
752
  }
485
- activity === null || activity === void 0 ? void 0 : activity.stop();
753
+ postProcess(xhr, true);
486
754
  tasker === null || tasker === void 0 ? void 0 : tasker.done();
487
755
  throw ex;
488
756
  }
@@ -491,24 +759,27 @@ class Tracing {
491
759
  construct(target) {
492
760
  const newXhr = new target();
493
761
  newXhr.addEventListener('load', () => {
494
- var _a, _b;
495
- (_b = (_a = newXhr._o11y) === null || _a === void 0 ? void 0 : _a.activity) === null || _b === void 0 ? void 0 : _b.stop();
762
+ postProcess(newXhr);
496
763
  tasker === null || tasker === void 0 ? void 0 : tasker.done();
497
764
  });
498
765
  newXhr.addEventListener('error', (__err) => {
499
766
  var _a;
500
- const error = new Error('XHR Network-Level Error');
501
- const activity = (_a = newXhr._o11y) === null || _a === void 0 ? void 0 : _a.activity;
502
- if (activity) {
767
+ try {
768
+ const error = new Error('XHR Network-Level Error');
503
769
  if (logErrors) {
504
- activity.error(error);
770
+ const activity = (_a = newXhr._o11y) === null || _a === void 0 ? void 0 : _a.activity;
771
+ if (activity) {
772
+ activity.error(error);
773
+ }
774
+ else {
775
+ instr.error(error);
776
+ }
505
777
  }
506
- activity.stop();
778
+ postProcess(newXhr);
507
779
  }
508
- else if (logErrors) {
509
- instr.error(error);
780
+ finally {
781
+ tasker === null || tasker === void 0 ? void 0 : tasker.done();
510
782
  }
511
- tasker === null || tasker === void 0 ? void 0 : tasker.done();
512
783
  });
513
784
  newXhr.addEventListener('abort', () => {
514
785
  var _a, _b;
@@ -530,7 +801,7 @@ class Tracing {
530
801
  if (utility.definedValueOrDefault(tracingOptions.useTasker, true)) {
531
802
  tasker = (_a = this._idleDetector) === null || _a === void 0 ? void 0 : _a.declareNotifierTaskMulti('o11y network');
532
803
  }
533
- this._enableNetworkInstrumentation(utility.definedValueOrDefault(tracingOptions.instrumentation, this._instr), utility.definedValueOrDefault(tracingOptions.logErrors, true), tracingOptions.activityName, utility.definedValueOrDefault(tracingOptions.useTracing, true), tracingOptions.tracingHeadersOptions, tasker);
804
+ this._enableNetworkInstrumentation(utility.definedValueOrDefault(tracingOptions.instrumentation, this._instr), utility.definedValueOrDefault(tracingOptions.logErrors, true), tracingOptions.activityName, utility.definedValueOrDefault(tracingOptions.useTracing, true), tracingOptions.tracingHeadersOptions, tasker, utility.definedValueOrDefault(tracingOptions.logPerformance, true), utility.definedValueOrDefault(tracingOptions.logPerformanceActivityName, 'perf-timing'));
534
805
  }
535
806
  }
536
807
  resetRequestCounter() {
@@ -767,6 +1038,9 @@ class ActivityImpl {
767
1038
  getStopPerfTime() {
768
1039
  return this._stopPerfTime;
769
1040
  }
1041
+ getErrorCount() {
1042
+ return this._errorCount;
1043
+ }
770
1044
  }
771
1045
  ActivityImpl._count = 0;
772
1046
 
@@ -797,6 +1071,9 @@ class ActivityNoOp {
797
1071
  getStopPerfTime() {
798
1072
  return undefined;
799
1073
  }
1074
+ getErrorCount() {
1075
+ return 0;
1076
+ }
800
1077
  }
801
1078
  const activityNoOp = Object.freeze(new ActivityNoOp());
802
1079
 
@@ -1496,6 +1773,9 @@ class RootActivityNoOp {
1496
1773
  getStopPerfTime() {
1497
1774
  return undefined;
1498
1775
  }
1776
+ getErrorCount() {
1777
+ return 0;
1778
+ }
1499
1779
  }
1500
1780
  const rootActivityNoOp = Object.freeze(new RootActivityNoOp());
1501
1781
 
@@ -2159,7 +2439,7 @@ class ConsoleCollector {
2159
2439
  }
2160
2440
  }
2161
2441
 
2162
- const version = '248.8.0';
2442
+ const version = '248.10.0';
2163
2443
 
2164
2444
  const idleDetector = new IdleDetectorImpl({
2165
2445
  logThreshold: 300,