o11y 244.7.2 → 244.9.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.
@@ -397,37 +397,50 @@ class Tracing {
397
397
  }
398
398
  return traceHeaders || {};
399
399
  }
400
- _overrideFetch(instr, logErrors, activityName, useTracing, options, tasker) {
400
+ _overrideFetch(instr, logErrors, activityName, useTracing, tracingHeadersOptions, tasker) {
401
401
  Tracing._originalFetch = Tracing._global.fetch;
402
- const o11yFetch = async (url, reqOptions, ...restArgs) => {
402
+ const o11yFetch = async (resource, options, ...restArgs) => {
403
403
  let activity;
404
404
  try {
405
405
  tasker === null || tasker === void 0 ? void 0 : tasker.add();
406
- const ofo = reqOptions === null || reqOptions === void 0 ? void 0 : reqOptions.o11y;
406
+ const ofo = options === null || options === void 0 ? void 0 : options.o11y;
407
407
  if (!(ofo === null || ofo === void 0 ? void 0 : ofo.skipInstr)) {
408
408
  activity = instr.startActivity(activityName || defaultActivityNameForFetch);
409
409
  }
410
410
  else {
411
411
  Tracing._reqIndex += 1;
412
412
  try {
413
- if (typeof url === 'string') {
414
- const urlObj = new URL(url);
413
+ if (resource instanceof URL) {
414
+ resource.searchParams.append('o11y', Tracing._reqIndex.toString());
415
+ }
416
+ else if (typeof resource === 'string') {
417
+ const urlObj = new URL(resource);
415
418
  const kv = `o11y=${Tracing._reqIndex}`;
416
419
  urlObj.search += urlObj.search.startsWith('?') ? `&${kv}` : kv;
417
- url = urlObj.toString();
420
+ resource = urlObj.toString();
418
421
  }
419
422
  }
420
423
  catch (_a) { }
421
424
  }
422
- if (reqOptions) {
423
- delete reqOptions.o11y;
424
- }
425
+ options === null || options === void 0 ? true : delete options.o11y;
425
426
  if (useTracing) {
426
- reqOptions = reqOptions || {};
427
- const traceHeaders = Tracing._getTraceHeaders(activity, options, reqOptions.method, url === null || url === void 0 ? void 0 : url.toString());
428
- reqOptions.headers = Object.assign(reqOptions.headers || {}, traceHeaders);
427
+ let method = options === null || options === void 0 ? void 0 : options.method;
428
+ let url = resource === null || resource === void 0 ? void 0 : resource.toString();
429
+ if (resource instanceof Request) {
430
+ if (!method) {
431
+ method = resource.method;
432
+ }
433
+ url = resource.url;
434
+ }
435
+ const traceHeaders = Tracing._getTraceHeaders(activity, tracingHeadersOptions, method, url);
436
+ if (!this._applyTraceHeaders(resource, options, traceHeaders) &&
437
+ options === undefined) {
438
+ options = {
439
+ headers: traceHeaders
440
+ };
441
+ }
429
442
  }
430
- return await Tracing._originalFetch.call(Tracing._global, url, reqOptions, ...restArgs);
443
+ return await Tracing._originalFetch.call(Tracing._global, resource, options, ...restArgs);
431
444
  }
432
445
  catch (ex) {
433
446
  if (logErrors) {
@@ -536,6 +549,37 @@ class Tracing {
536
549
  resetRequestCounter() {
537
550
  Tracing._reqIndex = 0;
538
551
  }
552
+ _applyTraceHeaders(resource, options, traceHeaders) {
553
+ if ((options === null || options === void 0 ? void 0 : options.headers) !== undefined) {
554
+ if (options.headers instanceof Headers && typeof options.headers.set === 'function') {
555
+ Object.entries(traceHeaders).forEach(([key, value]) => {
556
+ options.headers.set(key, value);
557
+ });
558
+ return true;
559
+ }
560
+ if (Array.isArray(options.headers)) {
561
+ Object.entries(traceHeaders).forEach((entry) => {
562
+ options.headers.push(entry);
563
+ });
564
+ return true;
565
+ }
566
+ if (typeof options.headers === 'object') {
567
+ options.headers = Object.assign(options.headers, traceHeaders);
568
+ return true;
569
+ }
570
+ }
571
+ else if (resource instanceof Request && resource.headers instanceof Headers) {
572
+ Object.entries(traceHeaders).forEach(([key, value]) => {
573
+ resource.headers.set(key, value);
574
+ });
575
+ return true;
576
+ }
577
+ else if (options) {
578
+ options.headers = Object.assign({}, traceHeaders);
579
+ return true;
580
+ }
581
+ return false;
582
+ }
539
583
  }
540
584
  Tracing._global = utility.getGlobal();
541
585
  Tracing._isNetworkInstrumentationEnabled = false;
@@ -2098,7 +2142,7 @@ class ConsoleCollector {
2098
2142
  }
2099
2143
  }
2100
2144
 
2101
- const version = '244.7.2';
2145
+ const version = '244.9.0';
2102
2146
 
2103
2147
  const idleDetector = new IdleDetectorImpl({
2104
2148
  logThreshold: 300,