commonObjectTracing.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. const commonMap = new WeakMap();
  3. /**
  4. * Takes a shared (garbage collectable) object between resources, e.g. a headers object shared between Next.js server components and returns a common propagation context.
  5. *
  6. * @param commonObject The shared object.
  7. * @param propagationContext The propagation context that should be shared between all the resources if no propagation context was registered yet.
  8. * @returns the shared propagation context.
  9. */
  10. function commonObjectToPropagationContext(
  11. commonObject,
  12. propagationContext,
  13. ) {
  14. if (typeof commonObject === 'object' && commonObject) {
  15. const memoPropagationContext = commonMap.get(commonObject);
  16. if (memoPropagationContext) {
  17. return memoPropagationContext;
  18. } else {
  19. commonMap.set(commonObject, propagationContext);
  20. return propagationContext;
  21. }
  22. } else {
  23. return propagationContext;
  24. }
  25. }
  26. exports.commonObjectToPropagationContext = commonObjectToPropagationContext;
  27. //# sourceMappingURL=commonObjectTracing.js.map