commonObjectTracing.js 976 B

12345678910111213141516171819202122232425262728
  1. const commonMap = new WeakMap();
  2. /**
  3. * 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.
  4. *
  5. * @param commonObject The shared object.
  6. * @param propagationContext The propagation context that should be shared between all the resources if no propagation context was registered yet.
  7. * @returns the shared propagation context.
  8. */
  9. function commonObjectToPropagationContext(
  10. commonObject,
  11. propagationContext,
  12. ) {
  13. if (typeof commonObject === 'object' && commonObject) {
  14. const memoPropagationContext = commonMap.get(commonObject);
  15. if (memoPropagationContext) {
  16. return memoPropagationContext;
  17. } else {
  18. commonMap.set(commonObject, propagationContext);
  19. return propagationContext;
  20. }
  21. } else {
  22. return propagationContext;
  23. }
  24. }
  25. export { commonObjectToPropagationContext };
  26. //# sourceMappingURL=commonObjectTracing.js.map