@salesforce/cli 2.158.7 → 2.159.1

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 (305) hide show
  1. package/README.md +12 -12
  2. package/node_modules/@oclif/plugin-plugins/README.md +7 -7
  3. package/node_modules/@oclif/plugin-plugins/oclif.manifest.json +1 -1
  4. package/node_modules/@oclif/plugin-plugins/package.json +7 -7
  5. package/node_modules/@opentelemetry/core/dist/common/attributes.cjs +5 -0
  6. package/node_modules/@opentelemetry/core/dist/common/attributes.cjs.map +1 -1
  7. package/node_modules/@opentelemetry/core/dist/common/attributes.mjs +5 -0
  8. package/node_modules/@opentelemetry/core/dist/common/attributes.mjs.map +1 -1
  9. package/node_modules/@opentelemetry/core/dist/version.cjs +1 -1
  10. package/node_modules/@opentelemetry/core/dist/version.cjs.map +1 -1
  11. package/node_modules/@opentelemetry/core/dist/version.mjs +1 -1
  12. package/node_modules/@opentelemetry/core/dist/version.mjs.map +1 -1
  13. package/node_modules/@opentelemetry/core/package.json +2 -2
  14. package/node_modules/@opentelemetry/resources/README.md +21 -2
  15. package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.cjs +9 -47
  16. package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.cjs.map +1 -1
  17. package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.d.cts +10 -24
  18. package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.d.cts.map +1 -1
  19. package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.d.mts +10 -24
  20. package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.d.mts.map +1 -1
  21. package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.mjs +9 -47
  22. package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.mjs.map +1 -1
  23. package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.cjs +70 -0
  24. package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.cjs.map +1 -0
  25. package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.d.cts +35 -0
  26. package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.d.cts.map +1 -0
  27. package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.d.mts +35 -0
  28. package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.d.mts.map +1 -0
  29. package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.mjs +69 -0
  30. package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.mjs.map +1 -0
  31. package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.cjs +19 -0
  32. package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.cjs.map +1 -0
  33. package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.d.cts +12 -0
  34. package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.d.cts.map +1 -0
  35. package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.d.mts +12 -0
  36. package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.d.mts.map +1 -0
  37. package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.mjs +19 -0
  38. package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.mjs.map +1 -0
  39. package/node_modules/@opentelemetry/resources/dist/detectors/index.d.cts +3 -1
  40. package/node_modules/@opentelemetry/resources/dist/detectors/index.d.mts +3 -1
  41. package/node_modules/@opentelemetry/resources/dist/detectors/index.mjs +3 -1
  42. package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.cjs +0 -3
  43. package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.cjs.map +1 -1
  44. package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.d.cts +0 -3
  45. package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.d.cts.map +1 -1
  46. package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.d.mts +0 -3
  47. package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.d.mts.map +1 -1
  48. package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.mjs +0 -3
  49. package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.mjs.map +1 -1
  50. package/node_modules/@opentelemetry/resources/dist/index.cjs +4 -0
  51. package/node_modules/@opentelemetry/resources/dist/index.d.cts +3 -1
  52. package/node_modules/@opentelemetry/resources/dist/index.d.mts +3 -1
  53. package/node_modules/@opentelemetry/resources/dist/index.mjs +3 -1
  54. package/node_modules/@opentelemetry/resources/package.json +3 -3
  55. package/node_modules/@salesforce/plugin-trust/README.md +14 -30
  56. package/node_modules/@salesforce/plugin-trust/oclif.manifest.json +1 -1
  57. package/node_modules/@salesforce/plugin-trust/package.json +4 -4
  58. package/node_modules/basic-ftp/dist/Client.js +2 -2
  59. package/node_modules/basic-ftp/dist/safePathNames.d.ts +6 -0
  60. package/node_modules/basic-ftp/dist/safePathNames.js +52 -0
  61. package/node_modules/basic-ftp/package.json +1 -1
  62. package/node_modules/npm/docs/content/commands/npm-ls.md +1 -1
  63. package/node_modules/npm/docs/content/commands/npm.md +1 -1
  64. package/node_modules/npm/docs/output/commands/npm-access.html +2 -2
  65. package/node_modules/npm/docs/output/commands/npm-adduser.html +2 -2
  66. package/node_modules/npm/docs/output/commands/npm-approve-scripts.html +2 -2
  67. package/node_modules/npm/docs/output/commands/npm-audit.html +2 -2
  68. package/node_modules/npm/docs/output/commands/npm-bugs.html +2 -2
  69. package/node_modules/npm/docs/output/commands/npm-cache.html +2 -2
  70. package/node_modules/npm/docs/output/commands/npm-ci.html +2 -2
  71. package/node_modules/npm/docs/output/commands/npm-completion.html +2 -2
  72. package/node_modules/npm/docs/output/commands/npm-config.html +2 -2
  73. package/node_modules/npm/docs/output/commands/npm-dedupe.html +2 -2
  74. package/node_modules/npm/docs/output/commands/npm-deny-scripts.html +2 -2
  75. package/node_modules/npm/docs/output/commands/npm-deprecate.html +2 -2
  76. package/node_modules/npm/docs/output/commands/npm-diff.html +2 -2
  77. package/node_modules/npm/docs/output/commands/npm-dist-tag.html +2 -2
  78. package/node_modules/npm/docs/output/commands/npm-docs.html +2 -2
  79. package/node_modules/npm/docs/output/commands/npm-doctor.html +2 -2
  80. package/node_modules/npm/docs/output/commands/npm-edit.html +2 -2
  81. package/node_modules/npm/docs/output/commands/npm-exec.html +2 -2
  82. package/node_modules/npm/docs/output/commands/npm-explain.html +2 -2
  83. package/node_modules/npm/docs/output/commands/npm-explore.html +2 -2
  84. package/node_modules/npm/docs/output/commands/npm-find-dupes.html +2 -2
  85. package/node_modules/npm/docs/output/commands/npm-fund.html +2 -2
  86. package/node_modules/npm/docs/output/commands/npm-get.html +2 -2
  87. package/node_modules/npm/docs/output/commands/npm-help-search.html +2 -2
  88. package/node_modules/npm/docs/output/commands/npm-help.html +2 -2
  89. package/node_modules/npm/docs/output/commands/npm-init.html +2 -2
  90. package/node_modules/npm/docs/output/commands/npm-install-ci-test.html +2 -2
  91. package/node_modules/npm/docs/output/commands/npm-install-scripts.html +2 -2
  92. package/node_modules/npm/docs/output/commands/npm-install-test.html +2 -2
  93. package/node_modules/npm/docs/output/commands/npm-install.html +2 -2
  94. package/node_modules/npm/docs/output/commands/npm-link.html +2 -2
  95. package/node_modules/npm/docs/output/commands/npm-ll.html +2 -2
  96. package/node_modules/npm/docs/output/commands/npm-login.html +2 -2
  97. package/node_modules/npm/docs/output/commands/npm-logout.html +2 -2
  98. package/node_modules/npm/docs/output/commands/npm-ls.html +3 -3
  99. package/node_modules/npm/docs/output/commands/npm-org.html +2 -2
  100. package/node_modules/npm/docs/output/commands/npm-outdated.html +2 -2
  101. package/node_modules/npm/docs/output/commands/npm-owner.html +2 -2
  102. package/node_modules/npm/docs/output/commands/npm-pack.html +2 -2
  103. package/node_modules/npm/docs/output/commands/npm-ping.html +2 -2
  104. package/node_modules/npm/docs/output/commands/npm-pkg.html +2 -2
  105. package/node_modules/npm/docs/output/commands/npm-prefix.html +2 -2
  106. package/node_modules/npm/docs/output/commands/npm-profile.html +2 -2
  107. package/node_modules/npm/docs/output/commands/npm-prune.html +2 -2
  108. package/node_modules/npm/docs/output/commands/npm-publish.html +2 -2
  109. package/node_modules/npm/docs/output/commands/npm-query.html +2 -2
  110. package/node_modules/npm/docs/output/commands/npm-rebuild.html +2 -2
  111. package/node_modules/npm/docs/output/commands/npm-repo.html +2 -2
  112. package/node_modules/npm/docs/output/commands/npm-restart.html +2 -2
  113. package/node_modules/npm/docs/output/commands/npm-root.html +2 -2
  114. package/node_modules/npm/docs/output/commands/npm-run.html +2 -2
  115. package/node_modules/npm/docs/output/commands/npm-sbom.html +2 -2
  116. package/node_modules/npm/docs/output/commands/npm-search.html +2 -2
  117. package/node_modules/npm/docs/output/commands/npm-set.html +2 -2
  118. package/node_modules/npm/docs/output/commands/npm-shrinkwrap.html +2 -2
  119. package/node_modules/npm/docs/output/commands/npm-stage.html +2 -2
  120. package/node_modules/npm/docs/output/commands/npm-star.html +2 -2
  121. package/node_modules/npm/docs/output/commands/npm-stars.html +2 -2
  122. package/node_modules/npm/docs/output/commands/npm-start.html +2 -2
  123. package/node_modules/npm/docs/output/commands/npm-stop.html +2 -2
  124. package/node_modules/npm/docs/output/commands/npm-team.html +2 -2
  125. package/node_modules/npm/docs/output/commands/npm-test.html +2 -2
  126. package/node_modules/npm/docs/output/commands/npm-token.html +2 -2
  127. package/node_modules/npm/docs/output/commands/npm-trust.html +2 -2
  128. package/node_modules/npm/docs/output/commands/npm-undeprecate.html +2 -2
  129. package/node_modules/npm/docs/output/commands/npm-uninstall.html +2 -2
  130. package/node_modules/npm/docs/output/commands/npm-unpublish.html +2 -2
  131. package/node_modules/npm/docs/output/commands/npm-unstar.html +2 -2
  132. package/node_modules/npm/docs/output/commands/npm-update.html +2 -2
  133. package/node_modules/npm/docs/output/commands/npm-version.html +2 -2
  134. package/node_modules/npm/docs/output/commands/npm-view.html +2 -2
  135. package/node_modules/npm/docs/output/commands/npm-whoami.html +2 -2
  136. package/node_modules/npm/docs/output/commands/npm.html +3 -3
  137. package/node_modules/npm/docs/output/commands/npx.html +2 -2
  138. package/node_modules/npm/docs/output/configuring-npm/folders.html +2 -2
  139. package/node_modules/npm/docs/output/configuring-npm/install.html +2 -2
  140. package/node_modules/npm/docs/output/configuring-npm/npm-global.html +2 -2
  141. package/node_modules/npm/docs/output/configuring-npm/npm-json.html +2 -2
  142. package/node_modules/npm/docs/output/configuring-npm/npm-shrinkwrap-json.html +2 -2
  143. package/node_modules/npm/docs/output/configuring-npm/npmrc.html +2 -2
  144. package/node_modules/npm/docs/output/configuring-npm/package-json.html +2 -2
  145. package/node_modules/npm/docs/output/configuring-npm/package-lock-json.html +2 -2
  146. package/node_modules/npm/docs/output/using-npm/config.html +2 -2
  147. package/node_modules/npm/docs/output/using-npm/dependency-selectors.html +2 -2
  148. package/node_modules/npm/docs/output/using-npm/developers.html +2 -2
  149. package/node_modules/npm/docs/output/using-npm/logging.html +2 -2
  150. package/node_modules/npm/docs/output/using-npm/orgs.html +2 -2
  151. package/node_modules/npm/docs/output/using-npm/package-spec.html +2 -2
  152. package/node_modules/npm/docs/output/using-npm/registry.html +2 -2
  153. package/node_modules/npm/docs/output/using-npm/removal.html +2 -2
  154. package/node_modules/npm/docs/output/using-npm/scope.html +2 -2
  155. package/node_modules/npm/docs/output/using-npm/scripts.html +2 -2
  156. package/node_modules/npm/docs/output/using-npm/workspaces.html +2 -2
  157. package/node_modules/npm/lib/cli/entry.js +1 -1
  158. package/node_modules/npm/man/man1/npm-access.1 +1 -1
  159. package/node_modules/npm/man/man1/npm-adduser.1 +1 -1
  160. package/node_modules/npm/man/man1/npm-approve-scripts.1 +1 -1
  161. package/node_modules/npm/man/man1/npm-audit.1 +1 -1
  162. package/node_modules/npm/man/man1/npm-bugs.1 +1 -1
  163. package/node_modules/npm/man/man1/npm-cache.1 +1 -1
  164. package/node_modules/npm/man/man1/npm-ci.1 +1 -1
  165. package/node_modules/npm/man/man1/npm-completion.1 +1 -1
  166. package/node_modules/npm/man/man1/npm-config.1 +1 -1
  167. package/node_modules/npm/man/man1/npm-dedupe.1 +1 -1
  168. package/node_modules/npm/man/man1/npm-deny-scripts.1 +1 -1
  169. package/node_modules/npm/man/man1/npm-deprecate.1 +1 -1
  170. package/node_modules/npm/man/man1/npm-diff.1 +1 -1
  171. package/node_modules/npm/man/man1/npm-dist-tag.1 +1 -1
  172. package/node_modules/npm/man/man1/npm-docs.1 +1 -1
  173. package/node_modules/npm/man/man1/npm-doctor.1 +1 -1
  174. package/node_modules/npm/man/man1/npm-edit.1 +1 -1
  175. package/node_modules/npm/man/man1/npm-exec.1 +1 -1
  176. package/node_modules/npm/man/man1/npm-explain.1 +1 -1
  177. package/node_modules/npm/man/man1/npm-explore.1 +1 -1
  178. package/node_modules/npm/man/man1/npm-find-dupes.1 +1 -1
  179. package/node_modules/npm/man/man1/npm-fund.1 +1 -1
  180. package/node_modules/npm/man/man1/npm-get.1 +1 -1
  181. package/node_modules/npm/man/man1/npm-help-search.1 +1 -1
  182. package/node_modules/npm/man/man1/npm-help.1 +1 -1
  183. package/node_modules/npm/man/man1/npm-init.1 +1 -1
  184. package/node_modules/npm/man/man1/npm-install-ci-test.1 +1 -1
  185. package/node_modules/npm/man/man1/npm-install-scripts.1 +1 -1
  186. package/node_modules/npm/man/man1/npm-install-test.1 +1 -1
  187. package/node_modules/npm/man/man1/npm-install.1 +1 -1
  188. package/node_modules/npm/man/man1/npm-link.1 +1 -1
  189. package/node_modules/npm/man/man1/npm-ll.1 +1 -1
  190. package/node_modules/npm/man/man1/npm-login.1 +1 -1
  191. package/node_modules/npm/man/man1/npm-logout.1 +1 -1
  192. package/node_modules/npm/man/man1/npm-ls.1 +2 -2
  193. package/node_modules/npm/man/man1/npm-org.1 +1 -1
  194. package/node_modules/npm/man/man1/npm-outdated.1 +1 -1
  195. package/node_modules/npm/man/man1/npm-owner.1 +1 -1
  196. package/node_modules/npm/man/man1/npm-pack.1 +1 -1
  197. package/node_modules/npm/man/man1/npm-ping.1 +1 -1
  198. package/node_modules/npm/man/man1/npm-pkg.1 +1 -1
  199. package/node_modules/npm/man/man1/npm-prefix.1 +1 -1
  200. package/node_modules/npm/man/man1/npm-profile.1 +1 -1
  201. package/node_modules/npm/man/man1/npm-prune.1 +1 -1
  202. package/node_modules/npm/man/man1/npm-publish.1 +1 -1
  203. package/node_modules/npm/man/man1/npm-query.1 +1 -1
  204. package/node_modules/npm/man/man1/npm-rebuild.1 +1 -1
  205. package/node_modules/npm/man/man1/npm-repo.1 +1 -1
  206. package/node_modules/npm/man/man1/npm-restart.1 +1 -1
  207. package/node_modules/npm/man/man1/npm-root.1 +1 -1
  208. package/node_modules/npm/man/man1/npm-run.1 +1 -1
  209. package/node_modules/npm/man/man1/npm-sbom.1 +1 -1
  210. package/node_modules/npm/man/man1/npm-search.1 +1 -1
  211. package/node_modules/npm/man/man1/npm-set.1 +1 -1
  212. package/node_modules/npm/man/man1/npm-shrinkwrap.1 +1 -1
  213. package/node_modules/npm/man/man1/npm-stage.1 +1 -1
  214. package/node_modules/npm/man/man1/npm-star.1 +1 -1
  215. package/node_modules/npm/man/man1/npm-stars.1 +1 -1
  216. package/node_modules/npm/man/man1/npm-start.1 +1 -1
  217. package/node_modules/npm/man/man1/npm-stop.1 +1 -1
  218. package/node_modules/npm/man/man1/npm-team.1 +1 -1
  219. package/node_modules/npm/man/man1/npm-test.1 +1 -1
  220. package/node_modules/npm/man/man1/npm-token.1 +1 -1
  221. package/node_modules/npm/man/man1/npm-trust.1 +1 -1
  222. package/node_modules/npm/man/man1/npm-undeprecate.1 +1 -1
  223. package/node_modules/npm/man/man1/npm-uninstall.1 +1 -1
  224. package/node_modules/npm/man/man1/npm-unpublish.1 +1 -1
  225. package/node_modules/npm/man/man1/npm-unstar.1 +1 -1
  226. package/node_modules/npm/man/man1/npm-update.1 +1 -1
  227. package/node_modules/npm/man/man1/npm-version.1 +1 -1
  228. package/node_modules/npm/man/man1/npm-view.1 +1 -1
  229. package/node_modules/npm/man/man1/npm-whoami.1 +1 -1
  230. package/node_modules/npm/man/man1/npm.1 +2 -2
  231. package/node_modules/npm/man/man1/npx.1 +1 -1
  232. package/node_modules/npm/man/man5/folders.5 +1 -1
  233. package/node_modules/npm/man/man5/install.5 +1 -1
  234. package/node_modules/npm/man/man5/npm-global.5 +1 -1
  235. package/node_modules/npm/man/man5/npm-json.5 +1 -1
  236. package/node_modules/npm/man/man5/npm-shrinkwrap-json.5 +1 -1
  237. package/node_modules/npm/man/man5/npmrc.5 +1 -1
  238. package/node_modules/npm/man/man5/package-json.5 +1 -1
  239. package/node_modules/npm/man/man5/package-lock-json.5 +1 -1
  240. package/node_modules/npm/man/man7/config.7 +1 -1
  241. package/node_modules/npm/man/man7/dependency-selectors.7 +1 -1
  242. package/node_modules/npm/man/man7/developers.7 +1 -1
  243. package/node_modules/npm/man/man7/logging.7 +1 -1
  244. package/node_modules/npm/man/man7/orgs.7 +1 -1
  245. package/node_modules/npm/man/man7/package-spec.7 +1 -1
  246. package/node_modules/npm/man/man7/registry.7 +1 -1
  247. package/node_modules/npm/man/man7/removal.7 +1 -1
  248. package/node_modules/npm/man/man7/scope.7 +1 -1
  249. package/node_modules/npm/man/man7/scripts.7 +1 -1
  250. package/node_modules/npm/man/man7/workspaces.7 +1 -1
  251. package/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js +9 -2
  252. package/node_modules/npm/node_modules/@npmcli/promise-spawn/package.json +3 -2
  253. package/node_modules/npm/node_modules/bin-links/lib/get-paths.js +2 -0
  254. package/node_modules/npm/node_modules/bin-links/package.json +2 -1
  255. package/node_modules/npm/node_modules/ip-address/dist/common.js +2 -2
  256. package/node_modules/npm/node_modules/ip-address/dist/ipv4.js +7 -0
  257. package/node_modules/npm/node_modules/ip-address/dist/ipv6.js +7 -4
  258. package/node_modules/npm/node_modules/ip-address/dist/v6/constants.js +3 -0
  259. package/node_modules/npm/node_modules/ip-address/package.json +3 -2
  260. package/node_modules/npm/node_modules/libnpmexec/README.md +9 -1
  261. package/node_modules/npm/node_modules/libnpmexec/lib/index.js +6 -2
  262. package/node_modules/npm/node_modules/libnpmexec/lib/run-script.js +22 -5
  263. package/node_modules/npm/node_modules/libnpmexec/package.json +1 -1
  264. package/node_modules/npm/node_modules/pacote/lib/registry.js +71 -2
  265. package/node_modules/npm/node_modules/pacote/package.json +3 -2
  266. package/node_modules/npm/node_modules/semver/classes/range.js +2 -2
  267. package/node_modules/npm/node_modules/semver/internal/constants.js +30 -0
  268. package/node_modules/npm/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
  269. package/node_modules/npm/node_modules/semver/package.json +1 -1
  270. package/node_modules/npm/node_modules/undici/docs/docs/api/Client.md +2 -0
  271. package/node_modules/npm/node_modules/undici/lib/dispatcher/agent.js +6 -2
  272. package/node_modules/npm/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
  273. package/node_modules/npm/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
  274. package/node_modules/npm/node_modules/undici/lib/dispatcher/client.js +3 -2
  275. package/node_modules/npm/node_modules/undici/lib/dispatcher/dispatcher-base.js +9 -0
  276. package/node_modules/npm/node_modules/undici/lib/web/eventsource/eventsource-stream.js +91 -10
  277. package/node_modules/npm/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
  278. package/node_modules/npm/node_modules/undici/lib/web/fetch/index.js +7 -9
  279. package/node_modules/npm/node_modules/undici/lib/web/websocket/receiver.js +14 -0
  280. package/node_modules/npm/node_modules/undici/package.json +1 -1
  281. package/node_modules/npm/package.json +5 -5
  282. package/node_modules/semver/classes/range.js +2 -2
  283. package/node_modules/semver/internal/constants.js +30 -0
  284. package/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
  285. package/node_modules/semver/package.json +1 -1
  286. package/oclif.manifest.json +1 -1
  287. package/package.json +6 -6
  288. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/MSVSUtil.cpython-314.pyc +0 -0
  289. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/MSVSVersion.cpython-314.pyc +0 -0
  290. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/__init__.cpython-314.pyc +0 -0
  291. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/common.cpython-314.pyc +0 -0
  292. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/input.cpython-314.pyc +0 -0
  293. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/msvs_emulation.cpython-314.pyc +0 -0
  294. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/ninja_syntax.cpython-314.pyc +0 -0
  295. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/simple_copy.cpython-314.pyc +0 -0
  296. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/xcode_emulation.cpython-314.pyc +0 -0
  297. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/xcode_ninja.cpython-314.pyc +0 -0
  298. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/xcodeproj_file.cpython-314.pyc +0 -0
  299. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__pycache__/__init__.cpython-314.pyc +0 -0
  300. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__pycache__/make.cpython-314.pyc +0 -0
  301. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__pycache__/ninja.cpython-314.pyc +0 -0
  302. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__pycache__/xcode.cpython-314.pyc +0 -0
  303. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/__pycache__/__init__.cpython-314.pyc +0 -0
  304. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/__pycache__/_structures.cpython-314.pyc +0 -0
  305. package/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/__pycache__/version.cpython-314.pyc +0 -0
package/README.md CHANGED
@@ -25,7 +25,7 @@ $ npm install -g @salesforce/cli
25
25
  $ sf COMMAND
26
26
  running command...
27
27
  $ sf (--version|-v)
28
- @salesforce/cli/2.158.7 linux-x64 node-v26.13.0
28
+ @salesforce/cli/2.159.1 linux-x64 node-v26.13.0
29
29
  $ sf --help [COMMAND]
30
30
  USAGE
31
31
  $ sf COMMAND
@@ -9271,7 +9271,7 @@ EXAMPLES
9271
9271
  $ sf plugins
9272
9272
  ```
9273
9273
 
9274
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/index.ts)_
9274
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/index.ts)_
9275
9275
 
9276
9276
  ## `sf plugins discover`
9277
9277
 
@@ -9316,7 +9316,7 @@ EXAMPLES
9316
9316
  $ sf plugins inspect @salesforce/plugin-packaging
9317
9317
  ```
9318
9318
 
9319
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/inspect.ts)_
9319
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/inspect.ts)_
9320
9320
 
9321
9321
  ## `sf plugins install PLUGIN`
9322
9322
 
@@ -9365,7 +9365,7 @@ EXAMPLES
9365
9365
  $ sf plugins install someuser/someplugin
9366
9366
  ```
9367
9367
 
9368
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/install.ts)_
9368
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/install.ts)_
9369
9369
 
9370
9370
  ## `sf plugins link PATH`
9371
9371
 
@@ -9396,7 +9396,7 @@ EXAMPLES
9396
9396
  $ sf plugins link @salesforce/plugin-packaging
9397
9397
  ```
9398
9398
 
9399
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/link.ts)_
9399
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/link.ts)_
9400
9400
 
9401
9401
  ## `sf plugins reset`
9402
9402
 
@@ -9411,7 +9411,7 @@ FLAGS
9411
9411
  --reinstall Reinstall all plugins after uninstalling.
9412
9412
  ```
9413
9413
 
9414
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/reset.ts)_
9414
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/reset.ts)_
9415
9415
 
9416
9416
  ## `sf plugins trust allowlist add`
9417
9417
 
@@ -9448,7 +9448,7 @@ EXAMPLES
9448
9448
  $ sf plugins trust allowlist add --name @scope/my-plugin --name another-plugin
9449
9449
  ```
9450
9450
 
9451
- _See code: [@salesforce/plugin-trust](https://github.com/salesforcecli/plugin-trust/blob/4.1.0/src/commands/plugins/trust/allowlist/add.ts)_
9451
+ _See code: [@salesforce/plugin-trust](https://github.com/salesforcecli/plugin-trust/blob/4.1.1/src/commands/plugins/trust/allowlist/add.ts)_
9452
9452
 
9453
9453
  ## `sf plugins trust allowlist list`
9454
9454
 
@@ -9476,7 +9476,7 @@ EXAMPLES
9476
9476
  $ sf plugins trust allowlist list
9477
9477
  ```
9478
9478
 
9479
- _See code: [@salesforce/plugin-trust](https://github.com/salesforcecli/plugin-trust/blob/4.1.0/src/commands/plugins/trust/allowlist/list.ts)_
9479
+ _See code: [@salesforce/plugin-trust](https://github.com/salesforcecli/plugin-trust/blob/4.1.1/src/commands/plugins/trust/allowlist/list.ts)_
9480
9480
 
9481
9481
  ## `sf plugins trust allowlist remove`
9482
9482
 
@@ -9513,7 +9513,7 @@ EXAMPLES
9513
9513
  $ sf plugins trust allowlist remove --name @scope/my-plugin --name another-plugin
9514
9514
  ```
9515
9515
 
9516
- _See code: [@salesforce/plugin-trust](https://github.com/salesforcecli/plugin-trust/blob/4.1.0/src/commands/plugins/trust/allowlist/remove.ts)_
9516
+ _See code: [@salesforce/plugin-trust](https://github.com/salesforcecli/plugin-trust/blob/4.1.1/src/commands/plugins/trust/allowlist/remove.ts)_
9517
9517
 
9518
9518
  ## `sf plugins trust verify`
9519
9519
 
@@ -9542,7 +9542,7 @@ EXAMPLES
9542
9542
  $ sf plugins trust verify --npm @scope/npmName
9543
9543
  ```
9544
9544
 
9545
- _See code: [@salesforce/plugin-trust](https://github.com/salesforcecli/plugin-trust/blob/4.1.0/src/commands/plugins/trust/verify.ts)_
9545
+ _See code: [@salesforce/plugin-trust](https://github.com/salesforcecli/plugin-trust/blob/4.1.1/src/commands/plugins/trust/verify.ts)_
9546
9546
 
9547
9547
  ## `sf plugins uninstall [PLUGIN]`
9548
9548
 
@@ -9570,7 +9570,7 @@ EXAMPLES
9570
9570
  $ sf plugins uninstall @salesforce/plugin-packaging
9571
9571
  ```
9572
9572
 
9573
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/uninstall.ts)_
9573
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/uninstall.ts)_
9574
9574
 
9575
9575
  ## `sf plugins update`
9576
9576
 
@@ -9588,7 +9588,7 @@ DESCRIPTION
9588
9588
  Update installed plugins.
9589
9589
  ```
9590
9590
 
9591
- _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/update.ts)_
9591
+ _See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/update.ts)_
9592
9592
 
9593
9593
  ## `sf project convert mdapi`
9594
9594
 
@@ -117,7 +117,7 @@ EXAMPLES
117
117
  $ mycli plugins
118
118
  ```
119
119
 
120
- _See code: [src/commands/plugins/index.ts](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/index.ts)_
120
+ _See code: [src/commands/plugins/index.ts](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/index.ts)_
121
121
 
122
122
  ## `mycli plugins add PLUGIN`
123
123
 
@@ -191,7 +191,7 @@ EXAMPLES
191
191
  $ mycli plugins inspect myplugin
192
192
  ```
193
193
 
194
- _See code: [src/commands/plugins/inspect.ts](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/inspect.ts)_
194
+ _See code: [src/commands/plugins/inspect.ts](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/inspect.ts)_
195
195
 
196
196
  ## `mycli plugins install PLUGIN`
197
197
 
@@ -240,7 +240,7 @@ EXAMPLES
240
240
  $ mycli plugins install someuser/someplugin
241
241
  ```
242
242
 
243
- _See code: [src/commands/plugins/install.ts](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/install.ts)_
243
+ _See code: [src/commands/plugins/install.ts](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/install.ts)_
244
244
 
245
245
  ## `mycli plugins link PATH`
246
246
 
@@ -271,7 +271,7 @@ EXAMPLES
271
271
  $ mycli plugins link myplugin
272
272
  ```
273
273
 
274
- _See code: [src/commands/plugins/link.ts](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/link.ts)_
274
+ _See code: [src/commands/plugins/link.ts](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/link.ts)_
275
275
 
276
276
  ## `mycli plugins remove [PLUGIN]`
277
277
 
@@ -312,7 +312,7 @@ FLAGS
312
312
  --reinstall Reinstall all plugins after uninstalling.
313
313
  ```
314
314
 
315
- _See code: [src/commands/plugins/reset.ts](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/reset.ts)_
315
+ _See code: [src/commands/plugins/reset.ts](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/reset.ts)_
316
316
 
317
317
  ## `mycli plugins uninstall [PLUGIN]`
318
318
 
@@ -340,7 +340,7 @@ EXAMPLES
340
340
  $ mycli plugins uninstall myplugin
341
341
  ```
342
342
 
343
- _See code: [src/commands/plugins/uninstall.ts](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/uninstall.ts)_
343
+ _See code: [src/commands/plugins/uninstall.ts](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/uninstall.ts)_
344
344
 
345
345
  ## `mycli plugins unlink [PLUGIN]`
346
346
 
@@ -384,7 +384,7 @@ DESCRIPTION
384
384
  Update installed plugins.
385
385
  ```
386
386
 
387
- _See code: [src/commands/plugins/update.ts](https://github.com/oclif/plugin-plugins/blob/7.0.13/src/commands/plugins/update.ts)_
387
+ _See code: [src/commands/plugins/update.ts](https://github.com/oclif/plugin-plugins/blob/7.0.14/src/commands/plugins/update.ts)_
388
388
  <!-- commandsstop -->
389
389
 
390
390
  # Contributing
@@ -393,5 +393,5 @@
393
393
  ]
394
394
  }
395
395
  },
396
- "version": "7.0.13"
396
+ "version": "7.0.14"
397
397
  }
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@oclif/plugin-plugins",
3
3
  "description": "plugins plugin for oclif",
4
- "version": "7.0.13",
4
+ "version": "7.0.14",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/plugin-plugins/issues",
7
7
  "dependencies": {
8
8
  "@oclif/core": "^5.1.9",
9
9
  "ansis": "^3.17.0",
10
10
  "debug": "^4.4.0",
11
- "npm": "^11.21.0",
11
+ "npm": "^11.21.2",
12
12
  "npm-package-arg": "^11.0.3",
13
13
  "npm-run-path": "^5.3.0",
14
14
  "object-treeify": "^4.0.1",
@@ -21,8 +21,8 @@
21
21
  "@commitlint/config-conventional": "^19",
22
22
  "@eslint/compat": "^1.4.1",
23
23
  "@oclif/plugin-help": "^6",
24
- "@oclif/prettier-config": "^0.2.1",
25
- "@oclif/test": "^5.0.1",
24
+ "@oclif/prettier-config": "^0.2.2",
25
+ "@oclif/test": "^5.0.3",
26
26
  "@types/chai": "^4.3.16",
27
27
  "@types/debug": "^4.1.12",
28
28
  "@types/mocha": "^10.0.10",
@@ -34,14 +34,14 @@
34
34
  "@types/which": "^3.0.4",
35
35
  "chai": "^4.5.0",
36
36
  "commitlint": "^19",
37
- "eslint": "^10.12.0",
38
- "eslint-config-oclif": "^7.1.4",
37
+ "eslint": "^10.13.0",
38
+ "eslint-config-oclif": "^7.1.10",
39
39
  "eslint-config-prettier": "^10",
40
40
  "husky": "^9.1.7",
41
41
  "lint-staged": "^15.5.2",
42
42
  "mocha": "^11",
43
43
  "oclif": "^4.24.0",
44
- "prettier": "^3.9.6",
44
+ "prettier": "^3.9.10",
45
45
  "shx": "^0.4.0",
46
46
  "sinon": "^18",
47
47
  "ts-node": "^10.9.2",
@@ -152,6 +152,11 @@ function isAnyValueInternal(val, visited) {
152
152
  if (val instanceof Uint8Array) return true;
153
153
  if (visited.has(val)) return false;
154
154
  visited.add(val);
155
+ const isValid = isAnyValueObject(val, visited);
156
+ visited.delete(val);
157
+ return isValid;
158
+ }
159
+ function isAnyValueObject(val, visited) {
155
160
  if (Array.isArray(val)) {
156
161
  for (const item of val) if (item !== void 0 && !isAnyValueInternal(item, visited)) return false;
157
162
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.cjs","names":[],"sources":["../../src/common/attributes.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * OTel JS attributes handling utilities.\n *\n * In earlier OTel spec versions, attributes (e.g. on spans) were restricted\n * to a relatively \"simple\" set of allowed types:\n * - scalar values: string, number, boolean\n * - homogeneous array of scalar values\n *\n * OTEP 4485 defined a wider, extended, more *complex* set of types, adding:\n * - byte arrays (Uint8Array in JS)\n * - heterogenous arrays\n * - key/value-mappings (`KeyValueList` in proto, a plain `object` in JS)\n *\n * OTel SDKs \"MUST\" or \"MAY\" support for attributes, depending.\n * See https://github.com/open-telemetry/opentelemetry-specification/blob/main/oteps/4485-extending-attributes-to-support-complex-values.md#sdk\n *\n * In OTel JS SDK 3.0 and `@opentelemetry/api@1.10.0` support was added\n * for those extended attributes types. The `api` was updated to accept\n * TypeScript type `unknown` for attribute values via:\n * type AnyValue = unknown;\n *\n * The intent is that users of the `api` can (and will, this is JavaScript)\n * pass whatever types as attribute values. SDK implementations need to handle\n * API users passing in extended attribute types.\n * Two options:\n *\n * 1. Support the \"simple\" set of types. Use `cleanSimpleAttributes()` and\n * `maybeAddSimpleAttribute()`. (Or use `sanitizeAttributes()`, kept for\n * backward compatibility.)\n * 2. Support the extended types. Use `cleanAttributes()`, `isAnyValue()`, and\n * `maybeAddAttribute()`; and test the SDK implementation with newer\n * attribute value types.\n */\n\nimport type { AnyValue, Attributes } from '@opentelemetry/api';\nimport { diag } from '@opentelemetry/api';\n\n/**\n * A simpler attribute value with limited supported types.\n * This is the set of types that `Attributes` supported in versions of\n * `@opentelemetry/api` before v1.10.0.\n */\ntype SimpleAttributeValue =\n | string\n | number\n | boolean\n | Array<null | undefined | string>\n | Array<null | undefined | number>\n | Array<null | undefined | boolean>;\n\nexport enum AddAttributeDecision {\n DROP_UNDEFINED = 0,\n DROP_INVALID = 1,\n DROP_LIMIT_REACHED = 2,\n ADD_NEW = 3,\n ADD_OVERWRITE_EXISTING = 4,\n}\n\ntype AttributeLimits = {\n attributeCountLimit: number;\n attributeValueLengthLimit: number;\n};\n\n// https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#attribute-limits\nconst DEFAULT_ATTRIBUTE_LIMITS: AttributeLimits = {\n attributeCountLimit: 128,\n attributeValueLengthLimit: Infinity,\n};\n\ntype MaybeAddAttributeOpts = {\n key: string;\n value: AnyValue;\n attributes: Attributes;\n limits: AttributeLimits;\n currentAttributesCount: number;\n};\n\n/**\n * Maybe add the `key`/`val` attribute to the given `attributes`.\n * - \"Maybe\" because this ensures the `key` is valid (the string is not empty),\n * the `val` is an accepted spec AnyValue type (see `isAnyValue` below),\n * and the attribute does not need to be dropped because of a count limit.\n * Note that the TypeScript `AnyValue` type is *looser* than the spec\n * `AnyValue`.\n * - This also applies attribute count and value length limits.\n * - This returns an `AddAttributeDecision` enum value indicating whether,\n * why, and how the attribute was added. This can be relevant for the\n * caller updating metrics (e.g. `droppedAttributesCount`).\n */\nexport function maybeAddAttribute(\n opts: MaybeAddAttributeOpts\n): AddAttributeDecision {\n return maybeAddAttributeInternal(opts, isAnyValue);\n}\n\n/**\n * A version of `maybeAddAttribute` that limits allowed attribute value\n * types to \"simple\" types (`SimpleAttributeValue`).\n */\nexport function maybeAddSimpleAttribute(\n opts: MaybeAddAttributeOpts\n): AddAttributeDecision {\n return maybeAddAttributeInternal(opts, isSimpleAttributeValue);\n}\n\nfunction maybeAddAttributeInternal(\n opts: MaybeAddAttributeOpts,\n isValidValue: (value: unknown) => boolean\n): AddAttributeDecision {\n if (opts.value === undefined) {\n // Silently drop undefined values.\n return AddAttributeDecision.DROP_UNDEFINED;\n }\n\n if (opts.key.length === 0) {\n diag.warn(`Invalid attribute key: ${opts.key}`);\n return AddAttributeDecision.DROP_INVALID;\n }\n\n const isNewKey = !Object.hasOwn(opts.attributes, opts.key);\n if (\n isNewKey &&\n opts.currentAttributesCount >= opts.limits.attributeCountLimit\n ) {\n return AddAttributeDecision.DROP_LIMIT_REACHED;\n }\n\n if (!isValidValue(opts.value)) {\n diag.warn(`Invalid attribute value set for key: ${opts.key}`);\n return AddAttributeDecision.DROP_INVALID;\n }\n\n let attributeValueLengthLimit = opts.limits.attributeValueLengthLimit;\n if (attributeValueLengthLimit <= 0) {\n diag.warn(\n `Invalid attributeValueLengthLimit: must be positive, got ${attributeValueLengthLimit} (ignoring)`\n );\n attributeValueLengthLimit = Infinity;\n }\n opts.attributes[opts.key] = copyAndTruncAnyValue(\n opts.value,\n attributeValueLengthLimit\n );\n if (isNewKey) {\n return AddAttributeDecision.ADD_NEW;\n }\n return AddAttributeDecision.ADD_OVERWRITE_EXISTING;\n}\n\n/**\n * Clean a given set of attributes.\n * - `undefined` values, at the top-level and properties of nested objects,\n * are silently dropped\n * - invalid attribute value types are removed, with a warning\n * - attribute count and value length *limits* are applied\n *\n * The call signature is meant to make it ergonomic for creating SDK things\n * that take `attributes` and `droppedAttributesCount` arguments, e.g.:\n * this.links({\n * context: opts.context,\n * ...cleanAttributes(opts.attributes, attributeLimits)\n * });\n *\n * If the given `inAttributes` is undefined, then the properties in the\n * return value will be undefined.\n */\nexport function cleanAttributes(\n inAttributes: unknown,\n limits: AttributeLimits\n): {\n attributes?: Attributes;\n droppedAttributesCount?: number;\n} {\n return cleanAttributesInternal(inAttributes, limits, isAnyValue);\n}\n\n/**\n * A version of `cleanAttributes` that limits allowed attribute value types to\n * \"simple\" types (`SimpleAttributeValue`).\n */\nexport function cleanSimpleAttributes(\n inAttributes: unknown,\n limits: AttributeLimits\n): {\n attributes?: Attributes;\n droppedAttributesCount?: number;\n} {\n return cleanAttributesInternal(inAttributes, limits, isSimpleAttributeValue);\n}\n\nfunction cleanAttributesInternal(\n inAttributes: unknown,\n limits: AttributeLimits,\n isValidValue: (value: unknown) => boolean\n): {\n attributes?: Attributes;\n droppedAttributesCount?: number;\n} {\n if (typeof inAttributes !== 'object' || inAttributes == null) {\n return {};\n }\n\n const attributes: Attributes = {};\n let droppedAttributesCount = 0;\n\n let attributeValueLengthLimit = limits.attributeValueLengthLimit;\n if (attributeValueLengthLimit <= 0) {\n diag.warn(\n `Invalid attributeValueLengthLimit: must be positive, got ${attributeValueLengthLimit} (ignoring)`\n );\n attributeValueLengthLimit = Infinity;\n }\n\n let count = 0;\n for (const [key, val] of Object.entries(inAttributes)) {\n if (val === undefined) {\n // Silently drop undefined values.\n continue;\n }\n if (count >= limits.attributeCountLimit) {\n droppedAttributesCount++;\n continue;\n }\n if (key.length === 0) {\n diag.warn(`Invalid attribute key: ${key}`);\n droppedAttributesCount++;\n continue;\n }\n if (!isValidValue(val)) {\n diag.warn(`Invalid attribute value set for key: ${key}`);\n droppedAttributesCount++;\n continue;\n }\n attributes[key] = copyAndTruncAnyValue(val, attributeValueLengthLimit);\n count++;\n }\n\n return { attributes, droppedAttributesCount };\n}\n\n/**\n * Returns true iff the given value is a supported AnyValue per\n * https://opentelemetry.io/docs/specs/otel/common/#anyvalue\n *\n * - Primitives/scalars: string, boolean, number\n * (Note that this *excludes* BigInt and Symbol)\n * - Byte arrays (Uint8Array, Buffer)\n * - Arrays of AnyValue (heterogeneous arrays allowed)\n * - Maps from string to AnyValue (nested objects)\n * - Empty values (null)\n *\n * Notes:\n * - `undefined` is *not* considered an AnyValue.\n *\n * @param val\n * @returns true if the value is a valid AnyValue, false otherwise\n */\nexport function isAnyValue(val: unknown): boolean {\n return isAnyValueInternal(val, new WeakSet());\n}\n\nfunction isAnyValueInternal(\n val: unknown,\n visited: WeakSet<object>\n): val is AnyValue {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#description\n switch (typeof val) {\n case 'undefined':\n case 'bigint':\n case 'symbol':\n case 'function':\n return false;\n case 'string':\n case 'number':\n case 'boolean':\n return true;\n case 'object':\n // Handled below.\n break;\n default:\n // JavaScript added a new primitive type!?\n // Default to *not* supporting this new type as an AnyValue.\n return false;\n }\n\n if (val === null) {\n return true;\n }\n\n // Byte arrays\n if (val instanceof Uint8Array) {\n return true;\n }\n\n // This leaves objects and arrays. Check for circular references.\n if (visited.has(val)) {\n // Circular reference detected - reject it\n return false;\n }\n visited.add(val);\n\n // Arrays (can contain any AnyValue, including heterogeneous)\n if (Array.isArray(val)) {\n for (const item of val) {\n // Special case: `undefined` in an array is allowed because it has\n // meaning (the array index of subsequent items). It gets serialized\n // as an empty value, the same as `null`.\n if (item !== undefined && !isAnyValueInternal(item, visited)) {\n return false;\n }\n }\n return true;\n }\n\n // Only accept plain objects (not objects like Date, RegExp, Error, etc.).\n const obj = val as Record<string, unknown>;\n if (obj.constructor !== Object && obj.constructor !== undefined) {\n return false;\n }\n\n // Plain objects\n for (const k of Object.keys(obj)) {\n const v = obj[k];\n // Allow undefined properties on an object. This allows the pattern of\n // building structured objects with optional fields. The undefined\n // properties will be dropped by `cleanAttributes` and `maybeAddAttribute`.\n if (v !== undefined && !isAnyValueInternal(v, visited)) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Attribute value length limiting/truncation per:\n * https://opentelemetry.io/docs/specs/otel/common/#attribute-limits\n *\n * For arrays and objects, this also returns a deep copy to avoid mutating data\n * passed in by calling code.\n *\n * @param {AnyValue} val - The attribute value. We are assuming this has\n * already been guarded by `isAnyValue`. This filters out non-plain objects,\n * like RegExp & Date, and circular references.\n */\nfunction copyAndTruncAnyValue(val: AnyValue, limit: number): AnyValue {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#description\n switch (typeof val) {\n // Currently some of these aren't allowed AnyValue's, but having these\n // here is resilient for later changes (e.g. allowing bigint) and they help\n // with type narrowing.\n case 'number':\n case 'boolean':\n case 'undefined':\n case 'bigint':\n case 'symbol':\n case 'function':\n return val;\n case 'string':\n if (val.length <= limit) {\n return val;\n } else {\n return val.substring(0, limit);\n }\n case 'object':\n // Handled below.\n break;\n default:\n // JavaScript added a new primitive type!?\n // Assume we cannot meaningfully copy/trunc this new type.\n return val;\n }\n\n if (val === null) {\n return val;\n }\n\n // Byte arrays\n if (val instanceof Uint8Array) {\n if (val.length <= limit) {\n return val;\n } else {\n return val.slice(0, limit);\n }\n }\n\n // Arrays\n if (Array.isArray(val)) {\n return val.map(elem => copyAndTruncAnyValue(elem, limit));\n }\n\n // Plain objects\n const truncObj: Record<string, AnyValue> = {};\n const obj = val as Record<string, AnyValue>;\n for (const k of Object.keys(obj)) {\n const v = obj[k];\n // Silently drop undefined properties. They are allowed by isAnyValue()\n // with the expectation they will be dropped here.\n if (v !== undefined) {\n truncObj[k] = copyAndTruncAnyValue(obj[k], limit);\n }\n }\n return truncObj;\n}\n\n/**\n * Clean the given attributes to just those with \"simple\" attribute types.\n * This remains for backwards compatibility with 2.x.\n *\n * Changes to previous behavior:\n * - a default attribute count limit of 128 is applied\n * - nullish values (except in arrays) are removed\n *\n * @deprecated Use `cleanAttributes` or `cleanSimpleAttributes`.\n */\nexport function sanitizeAttributes(inAttributes: unknown): Attributes {\n const { attributes } = cleanSimpleAttributes(\n inAttributes,\n DEFAULT_ATTRIBUTE_LIMITS\n );\n return attributes ?? {};\n}\n\n/**\n * Return true if the given attribute value is a \"simple\" attribute value type.\n *\n * Changes to previous behavior: nullish values now return *false*.\n *\n * @deprecated use `isAnyValue`, or `isSimpleAttributeValue`.\n */\nexport const isAttributeValue = isSimpleAttributeValue;\n\nexport function isSimpleAttributeValue(\n val: unknown\n): val is SimpleAttributeValue {\n if (Array.isArray(val)) {\n return isHomogeneousAttributeValueArray(val);\n }\n return isValidPrimitiveAttributeValueType(typeof val);\n}\n\nfunction isHomogeneousAttributeValueArray(arr: unknown[]): boolean {\n let type: string | undefined;\n\n for (const element of arr) {\n // null/undefined elements are allowed\n if (element == null) continue;\n const elementType = typeof element;\n\n if (elementType === type) {\n continue;\n }\n\n if (!type) {\n if (isValidPrimitiveAttributeValueType(elementType)) {\n type = elementType;\n continue;\n }\n // encountered an invalid primitive\n return false;\n }\n\n return false;\n }\n\n return true;\n}\n\nfunction isValidPrimitiveAttributeValueType(valType: string): boolean {\n switch (valType) {\n case 'number':\n case 'boolean':\n case 'string':\n return true;\n }\n\n return false;\n}\n"],"mappings":";;AAuDA,IAAY,uBAAL,yBAAA,sBAAA;CACL,qBAAA,qBAAA,oBAAA,KAAA;CACA,qBAAA,qBAAA,kBAAA,KAAA;CACA,qBAAA,qBAAA,wBAAA,KAAA;CACA,qBAAA,qBAAA,aAAA,KAAA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,WAAW,GAAG;IACnD,OAAO;IACP;GACF;GAEA,OAAO;EACT;EAEA,OAAO;CACT;CAEA,OAAO;AACT;AAEA,SAAS,mCAAmC,SAA0B;CACpE,QAAQ,SAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK,UACH,OAAO;CACX;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"attributes.cjs","names":[],"sources":["../../src/common/attributes.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * OTel JS attributes handling utilities.\n *\n * In earlier OTel spec versions, attributes (e.g. on spans) were restricted\n * to a relatively \"simple\" set of allowed types:\n * - scalar values: string, number, boolean\n * - homogeneous array of scalar values\n *\n * OTEP 4485 defined a wider, extended, more *complex* set of types, adding:\n * - byte arrays (Uint8Array in JS)\n * - heterogenous arrays\n * - key/value-mappings (`KeyValueList` in proto, a plain `object` in JS)\n *\n * OTel SDKs \"MUST\" or \"MAY\" support for attributes, depending.\n * See https://github.com/open-telemetry/opentelemetry-specification/blob/main/oteps/4485-extending-attributes-to-support-complex-values.md#sdk\n *\n * In OTel JS SDK 3.0 and `@opentelemetry/api@1.10.0` support was added\n * for those extended attributes types. The `api` was updated to accept\n * TypeScript type `unknown` for attribute values via:\n * type AnyValue = unknown;\n *\n * The intent is that users of the `api` can (and will, this is JavaScript)\n * pass whatever types as attribute values. SDK implementations need to handle\n * API users passing in extended attribute types.\n * Two options:\n *\n * 1. Support the \"simple\" set of types. Use `cleanSimpleAttributes()` and\n * `maybeAddSimpleAttribute()`. (Or use `sanitizeAttributes()`, kept for\n * backward compatibility.)\n * 2. Support the extended types. Use `cleanAttributes()`, `isAnyValue()`, and\n * `maybeAddAttribute()`; and test the SDK implementation with newer\n * attribute value types.\n */\n\nimport type { AnyValue, Attributes } from '@opentelemetry/api';\nimport { diag } from '@opentelemetry/api';\n\n/**\n * A simpler attribute value with limited supported types.\n * This is the set of types that `Attributes` supported in versions of\n * `@opentelemetry/api` before v1.10.0.\n */\ntype SimpleAttributeValue =\n | string\n | number\n | boolean\n | Array<null | undefined | string>\n | Array<null | undefined | number>\n | Array<null | undefined | boolean>;\n\nexport enum AddAttributeDecision {\n DROP_UNDEFINED = 0,\n DROP_INVALID = 1,\n DROP_LIMIT_REACHED = 2,\n ADD_NEW = 3,\n ADD_OVERWRITE_EXISTING = 4,\n}\n\ntype AttributeLimits = {\n attributeCountLimit: number;\n attributeValueLengthLimit: number;\n};\n\n// https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#attribute-limits\nconst DEFAULT_ATTRIBUTE_LIMITS: AttributeLimits = {\n attributeCountLimit: 128,\n attributeValueLengthLimit: Infinity,\n};\n\ntype MaybeAddAttributeOpts = {\n key: string;\n value: AnyValue;\n attributes: Attributes;\n limits: AttributeLimits;\n currentAttributesCount: number;\n};\n\n/**\n * Maybe add the `key`/`val` attribute to the given `attributes`.\n * - \"Maybe\" because this ensures the `key` is valid (the string is not empty),\n * the `val` is an accepted spec AnyValue type (see `isAnyValue` below),\n * and the attribute does not need to be dropped because of a count limit.\n * Note that the TypeScript `AnyValue` type is *looser* than the spec\n * `AnyValue`.\n * - This also applies attribute count and value length limits.\n * - This returns an `AddAttributeDecision` enum value indicating whether,\n * why, and how the attribute was added. This can be relevant for the\n * caller updating metrics (e.g. `droppedAttributesCount`).\n */\nexport function maybeAddAttribute(\n opts: MaybeAddAttributeOpts\n): AddAttributeDecision {\n return maybeAddAttributeInternal(opts, isAnyValue);\n}\n\n/**\n * A version of `maybeAddAttribute` that limits allowed attribute value\n * types to \"simple\" types (`SimpleAttributeValue`).\n */\nexport function maybeAddSimpleAttribute(\n opts: MaybeAddAttributeOpts\n): AddAttributeDecision {\n return maybeAddAttributeInternal(opts, isSimpleAttributeValue);\n}\n\nfunction maybeAddAttributeInternal(\n opts: MaybeAddAttributeOpts,\n isValidValue: (value: unknown) => boolean\n): AddAttributeDecision {\n if (opts.value === undefined) {\n // Silently drop undefined values.\n return AddAttributeDecision.DROP_UNDEFINED;\n }\n\n if (opts.key.length === 0) {\n diag.warn(`Invalid attribute key: ${opts.key}`);\n return AddAttributeDecision.DROP_INVALID;\n }\n\n const isNewKey = !Object.hasOwn(opts.attributes, opts.key);\n if (\n isNewKey &&\n opts.currentAttributesCount >= opts.limits.attributeCountLimit\n ) {\n return AddAttributeDecision.DROP_LIMIT_REACHED;\n }\n\n if (!isValidValue(opts.value)) {\n diag.warn(`Invalid attribute value set for key: ${opts.key}`);\n return AddAttributeDecision.DROP_INVALID;\n }\n\n let attributeValueLengthLimit = opts.limits.attributeValueLengthLimit;\n if (attributeValueLengthLimit <= 0) {\n diag.warn(\n `Invalid attributeValueLengthLimit: must be positive, got ${attributeValueLengthLimit} (ignoring)`\n );\n attributeValueLengthLimit = Infinity;\n }\n opts.attributes[opts.key] = copyAndTruncAnyValue(\n opts.value,\n attributeValueLengthLimit\n );\n if (isNewKey) {\n return AddAttributeDecision.ADD_NEW;\n }\n return AddAttributeDecision.ADD_OVERWRITE_EXISTING;\n}\n\n/**\n * Clean a given set of attributes.\n * - `undefined` values, at the top-level and properties of nested objects,\n * are silently dropped\n * - invalid attribute value types are removed, with a warning\n * - attribute count and value length *limits* are applied\n *\n * The call signature is meant to make it ergonomic for creating SDK things\n * that take `attributes` and `droppedAttributesCount` arguments, e.g.:\n * this.links({\n * context: opts.context,\n * ...cleanAttributes(opts.attributes, attributeLimits)\n * });\n *\n * If the given `inAttributes` is undefined, then the properties in the\n * return value will be undefined.\n */\nexport function cleanAttributes(\n inAttributes: unknown,\n limits: AttributeLimits\n): {\n attributes?: Attributes;\n droppedAttributesCount?: number;\n} {\n return cleanAttributesInternal(inAttributes, limits, isAnyValue);\n}\n\n/**\n * A version of `cleanAttributes` that limits allowed attribute value types to\n * \"simple\" types (`SimpleAttributeValue`).\n */\nexport function cleanSimpleAttributes(\n inAttributes: unknown,\n limits: AttributeLimits\n): {\n attributes?: Attributes;\n droppedAttributesCount?: number;\n} {\n return cleanAttributesInternal(inAttributes, limits, isSimpleAttributeValue);\n}\n\nfunction cleanAttributesInternal(\n inAttributes: unknown,\n limits: AttributeLimits,\n isValidValue: (value: unknown) => boolean\n): {\n attributes?: Attributes;\n droppedAttributesCount?: number;\n} {\n if (typeof inAttributes !== 'object' || inAttributes == null) {\n return {};\n }\n\n const attributes: Attributes = {};\n let droppedAttributesCount = 0;\n\n let attributeValueLengthLimit = limits.attributeValueLengthLimit;\n if (attributeValueLengthLimit <= 0) {\n diag.warn(\n `Invalid attributeValueLengthLimit: must be positive, got ${attributeValueLengthLimit} (ignoring)`\n );\n attributeValueLengthLimit = Infinity;\n }\n\n let count = 0;\n for (const [key, val] of Object.entries(inAttributes)) {\n if (val === undefined) {\n // Silently drop undefined values.\n continue;\n }\n if (count >= limits.attributeCountLimit) {\n droppedAttributesCount++;\n continue;\n }\n if (key.length === 0) {\n diag.warn(`Invalid attribute key: ${key}`);\n droppedAttributesCount++;\n continue;\n }\n if (!isValidValue(val)) {\n diag.warn(`Invalid attribute value set for key: ${key}`);\n droppedAttributesCount++;\n continue;\n }\n attributes[key] = copyAndTruncAnyValue(val, attributeValueLengthLimit);\n count++;\n }\n\n return { attributes, droppedAttributesCount };\n}\n\n/**\n * Returns true iff the given value is a supported AnyValue per\n * https://opentelemetry.io/docs/specs/otel/common/#anyvalue\n *\n * - Primitives/scalars: string, boolean, number\n * (Note that this *excludes* BigInt and Symbol)\n * - Byte arrays (Uint8Array, Buffer)\n * - Arrays of AnyValue (heterogeneous arrays allowed)\n * - Maps from string to AnyValue (nested objects)\n * - Empty values (null)\n *\n * Notes:\n * - `undefined` is *not* considered an AnyValue.\n *\n * @param val\n * @returns true if the value is a valid AnyValue, false otherwise\n */\nexport function isAnyValue(val: unknown): boolean {\n return isAnyValueInternal(val, new WeakSet());\n}\n\nfunction isAnyValueInternal(\n val: unknown,\n visited: WeakSet<object>\n): val is AnyValue {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#description\n switch (typeof val) {\n case 'undefined':\n case 'bigint':\n case 'symbol':\n case 'function':\n return false;\n case 'string':\n case 'number':\n case 'boolean':\n return true;\n case 'object':\n // Handled below.\n break;\n default:\n // JavaScript added a new primitive type!?\n // Default to *not* supporting this new type as an AnyValue.\n return false;\n }\n\n if (val === null) {\n return true;\n }\n\n // Byte arrays\n if (val instanceof Uint8Array) {\n return true;\n }\n\n // This leaves objects and arrays. Check for circular references. Only the\n // values on the path currently being walked are tracked, so a value that is\n // referenced more than once without forming a cycle remains valid: it still\n // serializes to a finite tree.\n if (visited.has(val)) {\n // Circular reference detected - reject it\n return false;\n }\n visited.add(val);\n const isValid = isAnyValueObject(val, visited);\n visited.delete(val);\n return isValid;\n}\n\nfunction isAnyValueObject(val: object, visited: WeakSet<object>): boolean {\n // Arrays (can contain any AnyValue, including heterogeneous)\n if (Array.isArray(val)) {\n for (const item of val) {\n // Special case: `undefined` in an array is allowed because it has\n // meaning (the array index of subsequent items). It gets serialized\n // as an empty value, the same as `null`.\n if (item !== undefined && !isAnyValueInternal(item, visited)) {\n return false;\n }\n }\n return true;\n }\n\n // Only accept plain objects (not objects like Date, RegExp, Error, etc.).\n const obj = val as Record<string, unknown>;\n if (obj.constructor !== Object && obj.constructor !== undefined) {\n return false;\n }\n\n // Plain objects\n for (const k of Object.keys(obj)) {\n const v = obj[k];\n // Allow undefined properties on an object. This allows the pattern of\n // building structured objects with optional fields. The undefined\n // properties will be dropped by `cleanAttributes` and `maybeAddAttribute`.\n if (v !== undefined && !isAnyValueInternal(v, visited)) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Attribute value length limiting/truncation per:\n * https://opentelemetry.io/docs/specs/otel/common/#attribute-limits\n *\n * For arrays and objects, this also returns a deep copy to avoid mutating data\n * passed in by calling code.\n *\n * @param {AnyValue} val - The attribute value. We are assuming this has\n * already been guarded by `isAnyValue`. This filters out non-plain objects,\n * like RegExp & Date, and circular references.\n */\nfunction copyAndTruncAnyValue(val: AnyValue, limit: number): AnyValue {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#description\n switch (typeof val) {\n // Currently some of these aren't allowed AnyValue's, but having these\n // here is resilient for later changes (e.g. allowing bigint) and they help\n // with type narrowing.\n case 'number':\n case 'boolean':\n case 'undefined':\n case 'bigint':\n case 'symbol':\n case 'function':\n return val;\n case 'string':\n if (val.length <= limit) {\n return val;\n } else {\n return val.substring(0, limit);\n }\n case 'object':\n // Handled below.\n break;\n default:\n // JavaScript added a new primitive type!?\n // Assume we cannot meaningfully copy/trunc this new type.\n return val;\n }\n\n if (val === null) {\n return val;\n }\n\n // Byte arrays\n if (val instanceof Uint8Array) {\n if (val.length <= limit) {\n return val;\n } else {\n return val.slice(0, limit);\n }\n }\n\n // Arrays\n if (Array.isArray(val)) {\n return val.map(elem => copyAndTruncAnyValue(elem, limit));\n }\n\n // Plain objects\n const truncObj: Record<string, AnyValue> = {};\n const obj = val as Record<string, AnyValue>;\n for (const k of Object.keys(obj)) {\n const v = obj[k];\n // Silently drop undefined properties. They are allowed by isAnyValue()\n // with the expectation they will be dropped here.\n if (v !== undefined) {\n truncObj[k] = copyAndTruncAnyValue(obj[k], limit);\n }\n }\n return truncObj;\n}\n\n/**\n * Clean the given attributes to just those with \"simple\" attribute types.\n * This remains for backwards compatibility with 2.x.\n *\n * Changes to previous behavior:\n * - a default attribute count limit of 128 is applied\n * - nullish values (except in arrays) are removed\n *\n * @deprecated Use `cleanAttributes` or `cleanSimpleAttributes`.\n */\nexport function sanitizeAttributes(inAttributes: unknown): Attributes {\n const { attributes } = cleanSimpleAttributes(\n inAttributes,\n DEFAULT_ATTRIBUTE_LIMITS\n );\n return attributes ?? {};\n}\n\n/**\n * Return true if the given attribute value is a \"simple\" attribute value type.\n *\n * Changes to previous behavior: nullish values now return *false*.\n *\n * @deprecated use `isAnyValue`, or `isSimpleAttributeValue`.\n */\nexport const isAttributeValue = isSimpleAttributeValue;\n\nexport function isSimpleAttributeValue(\n val: unknown\n): val is SimpleAttributeValue {\n if (Array.isArray(val)) {\n return isHomogeneousAttributeValueArray(val);\n }\n return isValidPrimitiveAttributeValueType(typeof val);\n}\n\nfunction isHomogeneousAttributeValueArray(arr: unknown[]): boolean {\n let type: string | undefined;\n\n for (const element of arr) {\n // null/undefined elements are allowed\n if (element == null) continue;\n const elementType = typeof element;\n\n if (elementType === type) {\n continue;\n }\n\n if (!type) {\n if (isValidPrimitiveAttributeValueType(elementType)) {\n type = elementType;\n continue;\n }\n // encountered an invalid primitive\n return false;\n }\n\n return false;\n }\n\n return true;\n}\n\nfunction isValidPrimitiveAttributeValueType(valType: string): boolean {\n switch (valType) {\n case 'number':\n case 'boolean':\n case 'string':\n return true;\n }\n\n return false;\n}\n"],"mappings":";;AAuDA,IAAY,uBAAL,yBAAA,sBAAA;CACL,qBAAA,qBAAA,oBAAA,KAAA;CACA,qBAAA,qBAAA,kBAAA,KAAA;CACA,qBAAA,qBAAA,wBAAA,KAAA;CACA,qBAAA,qBAAA,aAAA,KAAA;CACA,qBAAA,qBAAA,4BAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AAQA,MAAM,2BAA4C;CAChD,qBAAqB;CACrB,2BAA2B;AAC7B;;;;;;;;;;;;;AAsBA,SAAgB,kBACd,MACsB;CACtB,OAAO,0BAA0B,MAAM,UAAU;AACnD;;;;;AAMA,SAAgB,wBACd,MACsB;CACtB,OAAO,0BAA0B,MAAM,sBAAsB;AAC/D;AAEA,SAAS,0BACP,MACA,cACsB;CACtB,IAAI,KAAK,UAAU,KAAA,GAEjB,OAAA;CAGF,IAAI,KAAK,IAAI,WAAW,GAAG;EACzB,mBAAA,KAAK,KAAK,0BAA0B,KAAK,KAAK;EAC9C,OAAA;CACF;CAEA,MAAM,WAAW,CAAC,OAAO,OAAO,KAAK,YAAY,KAAK,GAAG;CACzD,IACE,YACA,KAAK,0BAA0B,KAAK,OAAO,qBAE3C,OAAA;CAGF,IAAI,CAAC,aAAa,KAAK,KAAK,GAAG;EAC7B,mBAAA,KAAK,K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;CAGA,IAAI,MAAM,QAAQ,GAAG,GACnB,OAAO,IAAI,KAAI,SAAQ,qBAAqB,MAAM,KAAK,CAAC;CAI1D,MAAM,WAAqC,CAAC;CAC5C,MAAM,MAAM;CACZ,KAAK,MAAM,KAAK,OAAO,KAAK,GAAG,GAI7B,IAHU,IAAI,OAGJ,KAAA,GACR,SAAS,KAAK,qBAAqB,IAAI,IAAI,KAAK;CAGpD,OAAO;AACT;;;;;;;;;;;AAYA,SAAgB,mBAAmB,cAAmC;CACpE,MAAM,EAAE,eAAe,sBACrB,cACA,wBACF;CACA,OAAO,cAAc,CAAC;AACxB;;;;;;;;AASA,MAAa,mBAAmB;AAEhC,SAAgB,uBACd,KAC6B;CAC7B,IAAI,MAAM,QAAQ,GAAG,GACnB,OAAO,iCAAiC,GAAG;CAE7C,OAAO,mCAAmC,OAAO,GAAG;AACtD;AAEA,SAAS,iCAAiC,KAAyB;CACjE,IAAI;CAEJ,KAAK,MAAM,WAAW,KAAK;EAEzB,IAAI,WAAW,MAAM;EACrB,MAAM,cAAc,OAAO;EAE3B,IAAI,gBAAgB,MAClB;EAGF,IAAI,CAAC,MAAM;GACT,IAAI,mCAAmC,WAAW,GAAG;IACnD,OAAO;IACP;GACF;GAEA,OAAO;EACT;EAEA,OAAO;CACT;CAEA,OAAO;AACT;AAEA,SAAS,mCAAmC,SAA0B;CACpE,QAAQ,SAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK,UACH,OAAO;CACX;CAEA,OAAO;AACT"}
@@ -152,6 +152,11 @@ function isAnyValueInternal(val, visited) {
152
152
  if (val instanceof Uint8Array) return true;
153
153
  if (visited.has(val)) return false;
154
154
  visited.add(val);
155
+ const isValid = isAnyValueObject(val, visited);
156
+ visited.delete(val);
157
+ return isValid;
158
+ }
159
+ function isAnyValueObject(val, visited) {
155
160
  if (Array.isArray(val)) {
156
161
  for (const item of val) if (item !== void 0 && !isAnyValueInternal(item, visited)) return false;
157
162
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"attributes.mjs","names":[],"sources":["../../src/common/attributes.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * OTel JS attributes handling utilities.\n *\n * In earlier OTel spec versions, attributes (e.g. on spans) were restricted\n * to a relatively \"simple\" set of allowed types:\n * - scalar values: string, number, boolean\n * - homogeneous array of scalar values\n *\n * OTEP 4485 defined a wider, extended, more *complex* set of types, adding:\n * - byte arrays (Uint8Array in JS)\n * - heterogenous arrays\n * - key/value-mappings (`KeyValueList` in proto, a plain `object` in JS)\n *\n * OTel SDKs \"MUST\" or \"MAY\" support for attributes, depending.\n * See https://github.com/open-telemetry/opentelemetry-specification/blob/main/oteps/4485-extending-attributes-to-support-complex-values.md#sdk\n *\n * In OTel JS SDK 3.0 and `@opentelemetry/api@1.10.0` support was added\n * for those extended attributes types. The `api` was updated to accept\n * TypeScript type `unknown` for attribute values via:\n * type AnyValue = unknown;\n *\n * The intent is that users of the `api` can (and will, this is JavaScript)\n * pass whatever types as attribute values. SDK implementations need to handle\n * API users passing in extended attribute types.\n * Two options:\n *\n * 1. Support the \"simple\" set of types. Use `cleanSimpleAttributes()` and\n * `maybeAddSimpleAttribute()`. (Or use `sanitizeAttributes()`, kept for\n * backward compatibility.)\n * 2. Support the extended types. Use `cleanAttributes()`, `isAnyValue()`, and\n * `maybeAddAttribute()`; and test the SDK implementation with newer\n * attribute value types.\n */\n\nimport type { AnyValue, Attributes } from '@opentelemetry/api';\nimport { diag } from '@opentelemetry/api';\n\n/**\n * A simpler attribute value with limited supported types.\n * This is the set of types that `Attributes` supported in versions of\n * `@opentelemetry/api` before v1.10.0.\n */\ntype SimpleAttributeValue =\n | string\n | number\n | boolean\n | Array<null | undefined | string>\n | Array<null | undefined | number>\n | Array<null | undefined | boolean>;\n\nexport enum AddAttributeDecision {\n DROP_UNDEFINED = 0,\n DROP_INVALID = 1,\n DROP_LIMIT_REACHED = 2,\n ADD_NEW = 3,\n ADD_OVERWRITE_EXISTING = 4,\n}\n\ntype AttributeLimits = {\n attributeCountLimit: number;\n attributeValueLengthLimit: number;\n};\n\n// https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#attribute-limits\nconst DEFAULT_ATTRIBUTE_LIMITS: AttributeLimits = {\n attributeCountLimit: 128,\n attributeValueLengthLimit: Infinity,\n};\n\ntype MaybeAddAttributeOpts = {\n key: string;\n value: AnyValue;\n attributes: Attributes;\n limits: AttributeLimits;\n currentAttributesCount: number;\n};\n\n/**\n * Maybe add the `key`/`val` attribute to the given `attributes`.\n * - \"Maybe\" because this ensures the `key` is valid (the string is not empty),\n * the `val` is an accepted spec AnyValue type (see `isAnyValue` below),\n * and the attribute does not need to be dropped because of a count limit.\n * Note that the TypeScript `AnyValue` type is *looser* than the spec\n * `AnyValue`.\n * - This also applies attribute count and value length limits.\n * - This returns an `AddAttributeDecision` enum value indicating whether,\n * why, and how the attribute was added. This can be relevant for the\n * caller updating metrics (e.g. `droppedAttributesCount`).\n */\nexport function maybeAddAttribute(\n opts: MaybeAddAttributeOpts\n): AddAttributeDecision {\n return maybeAddAttributeInternal(opts, isAnyValue);\n}\n\n/**\n * A version of `maybeAddAttribute` that limits allowed attribute value\n * types to \"simple\" types (`SimpleAttributeValue`).\n */\nexport function maybeAddSimpleAttribute(\n opts: MaybeAddAttributeOpts\n): AddAttributeDecision {\n return maybeAddAttributeInternal(opts, isSimpleAttributeValue);\n}\n\nfunction maybeAddAttributeInternal(\n opts: MaybeAddAttributeOpts,\n isValidValue: (value: unknown) => boolean\n): AddAttributeDecision {\n if (opts.value === undefined) {\n // Silently drop undefined values.\n return AddAttributeDecision.DROP_UNDEFINED;\n }\n\n if (opts.key.length === 0) {\n diag.warn(`Invalid attribute key: ${opts.key}`);\n return AddAttributeDecision.DROP_INVALID;\n }\n\n const isNewKey = !Object.hasOwn(opts.attributes, opts.key);\n if (\n isNewKey &&\n opts.currentAttributesCount >= opts.limits.attributeCountLimit\n ) {\n return AddAttributeDecision.DROP_LIMIT_REACHED;\n }\n\n if (!isValidValue(opts.value)) {\n diag.warn(`Invalid attribute value set for key: ${opts.key}`);\n return AddAttributeDecision.DROP_INVALID;\n }\n\n let attributeValueLengthLimit = opts.limits.attributeValueLengthLimit;\n if (attributeValueLengthLimit <= 0) {\n diag.warn(\n `Invalid attributeValueLengthLimit: must be positive, got ${attributeValueLengthLimit} (ignoring)`\n );\n attributeValueLengthLimit = Infinity;\n }\n opts.attributes[opts.key] = copyAndTruncAnyValue(\n opts.value,\n attributeValueLengthLimit\n );\n if (isNewKey) {\n return AddAttributeDecision.ADD_NEW;\n }\n return AddAttributeDecision.ADD_OVERWRITE_EXISTING;\n}\n\n/**\n * Clean a given set of attributes.\n * - `undefined` values, at the top-level and properties of nested objects,\n * are silently dropped\n * - invalid attribute value types are removed, with a warning\n * - attribute count and value length *limits* are applied\n *\n * The call signature is meant to make it ergonomic for creating SDK things\n * that take `attributes` and `droppedAttributesCount` arguments, e.g.:\n * this.links({\n * context: opts.context,\n * ...cleanAttributes(opts.attributes, attributeLimits)\n * });\n *\n * If the given `inAttributes` is undefined, then the properties in the\n * return value will be undefined.\n */\nexport function cleanAttributes(\n inAttributes: unknown,\n limits: AttributeLimits\n): {\n attributes?: Attributes;\n droppedAttributesCount?: number;\n} {\n return cleanAttributesInternal(inAttributes, limits, isAnyValue);\n}\n\n/**\n * A version of `cleanAttributes` that limits allowed attribute value types to\n * \"simple\" types (`SimpleAttributeValue`).\n */\nexport function cleanSimpleAttributes(\n inAttributes: unknown,\n limits: AttributeLimits\n): {\n attributes?: Attributes;\n droppedAttributesCount?: number;\n} {\n return cleanAttributesInternal(inAttributes, limits, isSimpleAttributeValue);\n}\n\nfunction cleanAttributesInternal(\n inAttributes: unknown,\n limits: AttributeLimits,\n isValidValue: (value: unknown) => boolean\n): {\n attributes?: Attributes;\n droppedAttributesCount?: number;\n} {\n if (typeof inAttributes !== 'object' || inAttributes == null) {\n return {};\n }\n\n const attributes: Attributes = {};\n let droppedAttributesCount = 0;\n\n let attributeValueLengthLimit = limits.attributeValueLengthLimit;\n if (attributeValueLengthLimit <= 0) {\n diag.warn(\n `Invalid attributeValueLengthLimit: must be positive, got ${attributeValueLengthLimit} (ignoring)`\n );\n attributeValueLengthLimit = Infinity;\n }\n\n let count = 0;\n for (const [key, val] of Object.entries(inAttributes)) {\n if (val === undefined) {\n // Silently drop undefined values.\n continue;\n }\n if (count >= limits.attributeCountLimit) {\n droppedAttributesCount++;\n continue;\n }\n if (key.length === 0) {\n diag.warn(`Invalid attribute key: ${key}`);\n droppedAttributesCount++;\n continue;\n }\n if (!isValidValue(val)) {\n diag.warn(`Invalid attribute value set for key: ${key}`);\n droppedAttributesCount++;\n continue;\n }\n attributes[key] = copyAndTruncAnyValue(val, attributeValueLengthLimit);\n count++;\n }\n\n return { attributes, droppedAttributesCount };\n}\n\n/**\n * Returns true iff the given value is a supported AnyValue per\n * https://opentelemetry.io/docs/specs/otel/common/#anyvalue\n *\n * - Primitives/scalars: string, boolean, number\n * (Note that this *excludes* BigInt and Symbol)\n * - Byte arrays (Uint8Array, Buffer)\n * - Arrays of AnyValue (heterogeneous arrays allowed)\n * - Maps from string to AnyValue (nested objects)\n * - Empty values (null)\n *\n * Notes:\n * - `undefined` is *not* considered an AnyValue.\n *\n * @param val\n * @returns true if the value is a valid AnyValue, false otherwise\n */\nexport function isAnyValue(val: unknown): boolean {\n return isAnyValueInternal(val, new WeakSet());\n}\n\nfunction isAnyValueInternal(\n val: unknown,\n visited: WeakSet<object>\n): val is AnyValue {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#description\n switch (typeof val) {\n case 'undefined':\n case 'bigint':\n case 'symbol':\n case 'function':\n return false;\n case 'string':\n case 'number':\n case 'boolean':\n return true;\n case 'object':\n // Handled below.\n break;\n default:\n // JavaScript added a new primitive type!?\n // Default to *not* supporting this new type as an AnyValue.\n return false;\n }\n\n if (val === null) {\n return true;\n }\n\n // Byte arrays\n if (val instanceof Uint8Array) {\n return true;\n }\n\n // This leaves objects and arrays. Check for circular references.\n if (visited.has(val)) {\n // Circular reference detected - reject it\n return false;\n }\n visited.add(val);\n\n // Arrays (can contain any AnyValue, including heterogeneous)\n if (Array.isArray(val)) {\n for (const item of val) {\n // Special case: `undefined` in an array is allowed because it has\n // meaning (the array index of subsequent items). It gets serialized\n // as an empty value, the same as `null`.\n if (item !== undefined && !isAnyValueInternal(item, visited)) {\n return false;\n }\n }\n return true;\n }\n\n // Only accept plain objects (not objects like Date, RegExp, Error, etc.).\n const obj = val as Record<string, unknown>;\n if (obj.constructor !== Object && obj.constructor !== undefined) {\n return false;\n }\n\n // Plain objects\n for (const k of Object.keys(obj)) {\n const v = obj[k];\n // Allow undefined properties on an object. This allows the pattern of\n // building structured objects with optional fields. The undefined\n // properties will be dropped by `cleanAttributes` and `maybeAddAttribute`.\n if (v !== undefined && !isAnyValueInternal(v, visited)) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Attribute value length limiting/truncation per:\n * https://opentelemetry.io/docs/specs/otel/common/#attribute-limits\n *\n * For arrays and objects, this also returns a deep copy to avoid mutating data\n * passed in by calling code.\n *\n * @param {AnyValue} val - The attribute value. We are assuming this has\n * already been guarded by `isAnyValue`. This filters out non-plain objects,\n * like RegExp & Date, and circular references.\n */\nfunction copyAndTruncAnyValue(val: AnyValue, limit: number): AnyValue {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#description\n switch (typeof val) {\n // Currently some of these aren't allowed AnyValue's, but having these\n // here is resilient for later changes (e.g. allowing bigint) and they help\n // with type narrowing.\n case 'number':\n case 'boolean':\n case 'undefined':\n case 'bigint':\n case 'symbol':\n case 'function':\n return val;\n case 'string':\n if (val.length <= limit) {\n return val;\n } else {\n return val.substring(0, limit);\n }\n case 'object':\n // Handled below.\n break;\n default:\n // JavaScript added a new primitive type!?\n // Assume we cannot meaningfully copy/trunc this new type.\n return val;\n }\n\n if (val === null) {\n return val;\n }\n\n // Byte arrays\n if (val instanceof Uint8Array) {\n if (val.length <= limit) {\n return val;\n } else {\n return val.slice(0, limit);\n }\n }\n\n // Arrays\n if (Array.isArray(val)) {\n return val.map(elem => copyAndTruncAnyValue(elem, limit));\n }\n\n // Plain objects\n const truncObj: Record<string, AnyValue> = {};\n const obj = val as Record<string, AnyValue>;\n for (const k of Object.keys(obj)) {\n const v = obj[k];\n // Silently drop undefined properties. They are allowed by isAnyValue()\n // with the expectation they will be dropped here.\n if (v !== undefined) {\n truncObj[k] = copyAndTruncAnyValue(obj[k], limit);\n }\n }\n return truncObj;\n}\n\n/**\n * Clean the given attributes to just those with \"simple\" attribute types.\n * This remains for backwards compatibility with 2.x.\n *\n * Changes to previous behavior:\n * - a default attribute count limit of 128 is applied\n * - nullish values (except in arrays) are removed\n *\n * @deprecated Use `cleanAttributes` or `cleanSimpleAttributes`.\n */\nexport function sanitizeAttributes(inAttributes: unknown): Attributes {\n const { attributes } = cleanSimpleAttributes(\n inAttributes,\n DEFAULT_ATTRIBUTE_LIMITS\n );\n return attributes ?? {};\n}\n\n/**\n * Return true if the given attribute value is a \"simple\" attribute value type.\n *\n * Changes to previous behavior: nullish values now return *false*.\n *\n * @deprecated use `isAnyValue`, or `isSimpleAttributeValue`.\n */\nexport const isAttributeValue = isSimpleAttributeValue;\n\nexport function isSimpleAttributeValue(\n val: unknown\n): val is SimpleAttributeValue {\n if (Array.isArray(val)) {\n return isHomogeneousAttributeValueArray(val);\n }\n return isValidPrimitiveAttributeValueType(typeof val);\n}\n\nfunction isHomogeneousAttributeValueArray(arr: unknown[]): boolean {\n let type: string | undefined;\n\n for (const element of arr) {\n // null/undefined elements are allowed\n if (element == null) continue;\n const elementType = typeof element;\n\n if (elementType === type) {\n continue;\n }\n\n if (!type) {\n if (isValidPrimitiveAttributeValueType(elementType)) {\n type = elementType;\n continue;\n }\n // encountered an invalid primitive\n return false;\n }\n\n return false;\n }\n\n return true;\n}\n\nfunction isValidPrimitiveAttributeValueType(valType: string): boolean {\n switch (valType) {\n case 'number':\n case 'boolean':\n case 'string':\n return true;\n }\n\n return false;\n}\n"],"mappings":";;AAuDA,IAAY,uBAAL,yBAAA,sBAAA;CACL,qBAAA,qBAAA,oBAAA,KAAA;CACA,qBAAA,qBAAA,kBAAA,KAAA;CACA,qBAAA,qBAAA,wBAAA,KAAA;CACA,qBAAA,qBAAA,aAAA,KAAA;CACA,qBAAA,qBAAA,4BAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AAQA,MAAM,2BAA4C;CAChD,qBAAqB;CACrB,2BAA2B;AAC7B;;;;;;;;;;;;;AAsBA,SAAgB,kBACd,MACsB;CACtB,OAAO,0BAA0B,MAAM,UAAU;AACnD;;;;;AAMA,SAAgB,wBACd,MACsB;CACtB,OAAO,0BAA0B,MAAM,sBAAsB;AAC/D;AAEA,SAAS,0BACP,MACA,cACsB;CACtB,IAAI,KAAK,UAAU,KAAA,GAEjB,OAAA;CAGF,IAAI,KAAK,IAAI,WAAW,GAAG;EACzB,KAAK,KAAK,0BAA0B,KAAK,KAAK;EAC9C,OAAA;CACF;CAEA,MAAM,WAAW,CAAC,OAAO,OAAO,KAAK,YAAY,KAAK,GAAG;CACzD,IACE,YACA,KAAK,0BAA0B,KAAK,OAAO,qBAE3C,OAAA;CAGF,IAAI,CAAC,aAAa,KAAK,KAAK,GAAG;EAC7B,KAAK,KAAK,wCAAwC,KAAK,KAAK;EAC5D,OAAA;CACF;CAEA,IAAI,4BAA4B,KAAK,OAAO;CAC5C,IAAI,6BAA6B,GAAG;EAClC,KAAK,KACH,4DAA4D,0BAA0B,YACxF;EACA,4BAA4B;CAC9B;CACA,KAAK,WAAW,KAAK,OAAO,qBAC1B,KAAK,OACL,yBACF;CACA,IAAI,UACF,OAAA;CAEF,OAAA;AACF;;;;;;;;;;;;;;;;;;AAmBA,SAAgB,gBACd,cACA,QAIA;CACA,OAAO,wBAAwB,cAAc,QAAQ,UAAU;AACjE;;;;;AAMA,SAAgB,sBACd,cACA,QAIA;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;AACtD;AAEA,SAAS,iCAAiC,KAAyB;CACjE,IAAI;CAEJ,KAAK,MAAM,WAAW,KAAK;EAEzB,IAAI,WAAW,MAAM;EACrB,MAAM,cAAc,OAAO;EAE3B,IAAI,gBAAgB,MAClB;EAGF,IAAI,CAAC,MAAM;GACT,IAAI,mCAAmC,WAAW,GAAG;IACnD,OAAO;IACP;GACF;GAEA,OAAO;EACT;EAEA,OAAO;CACT;CAEA,OAAO;AACT;AAEA,SAAS,mCAAmC,SAA0B;CACpE,QAAQ,SAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK,UACH,OAAO;CACX;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"attributes.mjs","names":[],"sources":["../../src/common/attributes.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n/**\n * OTel JS attributes handling utilities.\n *\n * In earlier OTel spec versions, attributes (e.g. on spans) were restricted\n * to a relatively \"simple\" set of allowed types:\n * - scalar values: string, number, boolean\n * - homogeneous array of scalar values\n *\n * OTEP 4485 defined a wider, extended, more *complex* set of types, adding:\n * - byte arrays (Uint8Array in JS)\n * - heterogenous arrays\n * - key/value-mappings (`KeyValueList` in proto, a plain `object` in JS)\n *\n * OTel SDKs \"MUST\" or \"MAY\" support for attributes, depending.\n * See https://github.com/open-telemetry/opentelemetry-specification/blob/main/oteps/4485-extending-attributes-to-support-complex-values.md#sdk\n *\n * In OTel JS SDK 3.0 and `@opentelemetry/api@1.10.0` support was added\n * for those extended attributes types. The `api` was updated to accept\n * TypeScript type `unknown` for attribute values via:\n * type AnyValue = unknown;\n *\n * The intent is that users of the `api` can (and will, this is JavaScript)\n * pass whatever types as attribute values. SDK implementations need to handle\n * API users passing in extended attribute types.\n * Two options:\n *\n * 1. Support the \"simple\" set of types. Use `cleanSimpleAttributes()` and\n * `maybeAddSimpleAttribute()`. (Or use `sanitizeAttributes()`, kept for\n * backward compatibility.)\n * 2. Support the extended types. Use `cleanAttributes()`, `isAnyValue()`, and\n * `maybeAddAttribute()`; and test the SDK implementation with newer\n * attribute value types.\n */\n\nimport type { AnyValue, Attributes } from '@opentelemetry/api';\nimport { diag } from '@opentelemetry/api';\n\n/**\n * A simpler attribute value with limited supported types.\n * This is the set of types that `Attributes` supported in versions of\n * `@opentelemetry/api` before v1.10.0.\n */\ntype SimpleAttributeValue =\n | string\n | number\n | boolean\n | Array<null | undefined | string>\n | Array<null | undefined | number>\n | Array<null | undefined | boolean>;\n\nexport enum AddAttributeDecision {\n DROP_UNDEFINED = 0,\n DROP_INVALID = 1,\n DROP_LIMIT_REACHED = 2,\n ADD_NEW = 3,\n ADD_OVERWRITE_EXISTING = 4,\n}\n\ntype AttributeLimits = {\n attributeCountLimit: number;\n attributeValueLengthLimit: number;\n};\n\n// https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#attribute-limits\nconst DEFAULT_ATTRIBUTE_LIMITS: AttributeLimits = {\n attributeCountLimit: 128,\n attributeValueLengthLimit: Infinity,\n};\n\ntype MaybeAddAttributeOpts = {\n key: string;\n value: AnyValue;\n attributes: Attributes;\n limits: AttributeLimits;\n currentAttributesCount: number;\n};\n\n/**\n * Maybe add the `key`/`val` attribute to the given `attributes`.\n * - \"Maybe\" because this ensures the `key` is valid (the string is not empty),\n * the `val` is an accepted spec AnyValue type (see `isAnyValue` below),\n * and the attribute does not need to be dropped because of a count limit.\n * Note that the TypeScript `AnyValue` type is *looser* than the spec\n * `AnyValue`.\n * - This also applies attribute count and value length limits.\n * - This returns an `AddAttributeDecision` enum value indicating whether,\n * why, and how the attribute was added. This can be relevant for the\n * caller updating metrics (e.g. `droppedAttributesCount`).\n */\nexport function maybeAddAttribute(\n opts: MaybeAddAttributeOpts\n): AddAttributeDecision {\n return maybeAddAttributeInternal(opts, isAnyValue);\n}\n\n/**\n * A version of `maybeAddAttribute` that limits allowed attribute value\n * types to \"simple\" types (`SimpleAttributeValue`).\n */\nexport function maybeAddSimpleAttribute(\n opts: MaybeAddAttributeOpts\n): AddAttributeDecision {\n return maybeAddAttributeInternal(opts, isSimpleAttributeValue);\n}\n\nfunction maybeAddAttributeInternal(\n opts: MaybeAddAttributeOpts,\n isValidValue: (value: unknown) => boolean\n): AddAttributeDecision {\n if (opts.value === undefined) {\n // Silently drop undefined values.\n return AddAttributeDecision.DROP_UNDEFINED;\n }\n\n if (opts.key.length === 0) {\n diag.warn(`Invalid attribute key: ${opts.key}`);\n return AddAttributeDecision.DROP_INVALID;\n }\n\n const isNewKey = !Object.hasOwn(opts.attributes, opts.key);\n if (\n isNewKey &&\n opts.currentAttributesCount >= opts.limits.attributeCountLimit\n ) {\n return AddAttributeDecision.DROP_LIMIT_REACHED;\n }\n\n if (!isValidValue(opts.value)) {\n diag.warn(`Invalid attribute value set for key: ${opts.key}`);\n return AddAttributeDecision.DROP_INVALID;\n }\n\n let attributeValueLengthLimit = opts.limits.attributeValueLengthLimit;\n if (attributeValueLengthLimit <= 0) {\n diag.warn(\n `Invalid attributeValueLengthLimit: must be positive, got ${attributeValueLengthLimit} (ignoring)`\n );\n attributeValueLengthLimit = Infinity;\n }\n opts.attributes[opts.key] = copyAndTruncAnyValue(\n opts.value,\n attributeValueLengthLimit\n );\n if (isNewKey) {\n return AddAttributeDecision.ADD_NEW;\n }\n return AddAttributeDecision.ADD_OVERWRITE_EXISTING;\n}\n\n/**\n * Clean a given set of attributes.\n * - `undefined` values, at the top-level and properties of nested objects,\n * are silently dropped\n * - invalid attribute value types are removed, with a warning\n * - attribute count and value length *limits* are applied\n *\n * The call signature is meant to make it ergonomic for creating SDK things\n * that take `attributes` and `droppedAttributesCount` arguments, e.g.:\n * this.links({\n * context: opts.context,\n * ...cleanAttributes(opts.attributes, attributeLimits)\n * });\n *\n * If the given `inAttributes` is undefined, then the properties in the\n * return value will be undefined.\n */\nexport function cleanAttributes(\n inAttributes: unknown,\n limits: AttributeLimits\n): {\n attributes?: Attributes;\n droppedAttributesCount?: number;\n} {\n return cleanAttributesInternal(inAttributes, limits, isAnyValue);\n}\n\n/**\n * A version of `cleanAttributes` that limits allowed attribute value types to\n * \"simple\" types (`SimpleAttributeValue`).\n */\nexport function cleanSimpleAttributes(\n inAttributes: unknown,\n limits: AttributeLimits\n): {\n attributes?: Attributes;\n droppedAttributesCount?: number;\n} {\n return cleanAttributesInternal(inAttributes, limits, isSimpleAttributeValue);\n}\n\nfunction cleanAttributesInternal(\n inAttributes: unknown,\n limits: AttributeLimits,\n isValidValue: (value: unknown) => boolean\n): {\n attributes?: Attributes;\n droppedAttributesCount?: number;\n} {\n if (typeof inAttributes !== 'object' || inAttributes == null) {\n return {};\n }\n\n const attributes: Attributes = {};\n let droppedAttributesCount = 0;\n\n let attributeValueLengthLimit = limits.attributeValueLengthLimit;\n if (attributeValueLengthLimit <= 0) {\n diag.warn(\n `Invalid attributeValueLengthLimit: must be positive, got ${attributeValueLengthLimit} (ignoring)`\n );\n attributeValueLengthLimit = Infinity;\n }\n\n let count = 0;\n for (const [key, val] of Object.entries(inAttributes)) {\n if (val === undefined) {\n // Silently drop undefined values.\n continue;\n }\n if (count >= limits.attributeCountLimit) {\n droppedAttributesCount++;\n continue;\n }\n if (key.length === 0) {\n diag.warn(`Invalid attribute key: ${key}`);\n droppedAttributesCount++;\n continue;\n }\n if (!isValidValue(val)) {\n diag.warn(`Invalid attribute value set for key: ${key}`);\n droppedAttributesCount++;\n continue;\n }\n attributes[key] = copyAndTruncAnyValue(val, attributeValueLengthLimit);\n count++;\n }\n\n return { attributes, droppedAttributesCount };\n}\n\n/**\n * Returns true iff the given value is a supported AnyValue per\n * https://opentelemetry.io/docs/specs/otel/common/#anyvalue\n *\n * - Primitives/scalars: string, boolean, number\n * (Note that this *excludes* BigInt and Symbol)\n * - Byte arrays (Uint8Array, Buffer)\n * - Arrays of AnyValue (heterogeneous arrays allowed)\n * - Maps from string to AnyValue (nested objects)\n * - Empty values (null)\n *\n * Notes:\n * - `undefined` is *not* considered an AnyValue.\n *\n * @param val\n * @returns true if the value is a valid AnyValue, false otherwise\n */\nexport function isAnyValue(val: unknown): boolean {\n return isAnyValueInternal(val, new WeakSet());\n}\n\nfunction isAnyValueInternal(\n val: unknown,\n visited: WeakSet<object>\n): val is AnyValue {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#description\n switch (typeof val) {\n case 'undefined':\n case 'bigint':\n case 'symbol':\n case 'function':\n return false;\n case 'string':\n case 'number':\n case 'boolean':\n return true;\n case 'object':\n // Handled below.\n break;\n default:\n // JavaScript added a new primitive type!?\n // Default to *not* supporting this new type as an AnyValue.\n return false;\n }\n\n if (val === null) {\n return true;\n }\n\n // Byte arrays\n if (val instanceof Uint8Array) {\n return true;\n }\n\n // This leaves objects and arrays. Check for circular references. Only the\n // values on the path currently being walked are tracked, so a value that is\n // referenced more than once without forming a cycle remains valid: it still\n // serializes to a finite tree.\n if (visited.has(val)) {\n // Circular reference detected - reject it\n return false;\n }\n visited.add(val);\n const isValid = isAnyValueObject(val, visited);\n visited.delete(val);\n return isValid;\n}\n\nfunction isAnyValueObject(val: object, visited: WeakSet<object>): boolean {\n // Arrays (can contain any AnyValue, including heterogeneous)\n if (Array.isArray(val)) {\n for (const item of val) {\n // Special case: `undefined` in an array is allowed because it has\n // meaning (the array index of subsequent items). It gets serialized\n // as an empty value, the same as `null`.\n if (item !== undefined && !isAnyValueInternal(item, visited)) {\n return false;\n }\n }\n return true;\n }\n\n // Only accept plain objects (not objects like Date, RegExp, Error, etc.).\n const obj = val as Record<string, unknown>;\n if (obj.constructor !== Object && obj.constructor !== undefined) {\n return false;\n }\n\n // Plain objects\n for (const k of Object.keys(obj)) {\n const v = obj[k];\n // Allow undefined properties on an object. This allows the pattern of\n // building structured objects with optional fields. The undefined\n // properties will be dropped by `cleanAttributes` and `maybeAddAttribute`.\n if (v !== undefined && !isAnyValueInternal(v, visited)) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Attribute value length limiting/truncation per:\n * https://opentelemetry.io/docs/specs/otel/common/#attribute-limits\n *\n * For arrays and objects, this also returns a deep copy to avoid mutating data\n * passed in by calling code.\n *\n * @param {AnyValue} val - The attribute value. We are assuming this has\n * already been guarded by `isAnyValue`. This filters out non-plain objects,\n * like RegExp & Date, and circular references.\n */\nfunction copyAndTruncAnyValue(val: AnyValue, limit: number): AnyValue {\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#description\n switch (typeof val) {\n // Currently some of these aren't allowed AnyValue's, but having these\n // here is resilient for later changes (e.g. allowing bigint) and they help\n // with type narrowing.\n case 'number':\n case 'boolean':\n case 'undefined':\n case 'bigint':\n case 'symbol':\n case 'function':\n return val;\n case 'string':\n if (val.length <= limit) {\n return val;\n } else {\n return val.substring(0, limit);\n }\n case 'object':\n // Handled below.\n break;\n default:\n // JavaScript added a new primitive type!?\n // Assume we cannot meaningfully copy/trunc this new type.\n return val;\n }\n\n if (val === null) {\n return val;\n }\n\n // Byte arrays\n if (val instanceof Uint8Array) {\n if (val.length <= limit) {\n return val;\n } else {\n return val.slice(0, limit);\n }\n }\n\n // Arrays\n if (Array.isArray(val)) {\n return val.map(elem => copyAndTruncAnyValue(elem, limit));\n }\n\n // Plain objects\n const truncObj: Record<string, AnyValue> = {};\n const obj = val as Record<string, AnyValue>;\n for (const k of Object.keys(obj)) {\n const v = obj[k];\n // Silently drop undefined properties. They are allowed by isAnyValue()\n // with the expectation they will be dropped here.\n if (v !== undefined) {\n truncObj[k] = copyAndTruncAnyValue(obj[k], limit);\n }\n }\n return truncObj;\n}\n\n/**\n * Clean the given attributes to just those with \"simple\" attribute types.\n * This remains for backwards compatibility with 2.x.\n *\n * Changes to previous behavior:\n * - a default attribute count limit of 128 is applied\n * - nullish values (except in arrays) are removed\n *\n * @deprecated Use `cleanAttributes` or `cleanSimpleAttributes`.\n */\nexport function sanitizeAttributes(inAttributes: unknown): Attributes {\n const { attributes } = cleanSimpleAttributes(\n inAttributes,\n DEFAULT_ATTRIBUTE_LIMITS\n );\n return attributes ?? {};\n}\n\n/**\n * Return true if the given attribute value is a \"simple\" attribute value type.\n *\n * Changes to previous behavior: nullish values now return *false*.\n *\n * @deprecated use `isAnyValue`, or `isSimpleAttributeValue`.\n */\nexport const isAttributeValue = isSimpleAttributeValue;\n\nexport function isSimpleAttributeValue(\n val: unknown\n): val is SimpleAttributeValue {\n if (Array.isArray(val)) {\n return isHomogeneousAttributeValueArray(val);\n }\n return isValidPrimitiveAttributeValueType(typeof val);\n}\n\nfunction isHomogeneousAttributeValueArray(arr: unknown[]): boolean {\n let type: string | undefined;\n\n for (const element of arr) {\n // null/undefined elements are allowed\n if (element == null) continue;\n const elementType = typeof element;\n\n if (elementType === type) {\n continue;\n }\n\n if (!type) {\n if (isValidPrimitiveAttributeValueType(elementType)) {\n type = elementType;\n continue;\n }\n // encountered an invalid primitive\n return false;\n }\n\n return false;\n }\n\n return true;\n}\n\nfunction isValidPrimitiveAttributeValueType(valType: string): boolean {\n switch (valType) {\n case 'number':\n case 'boolean':\n case 'string':\n return true;\n }\n\n return false;\n}\n"],"mappings":";;AAuDA,IAAY,uBAAL,yBAAA,sBAAA;CACL,qBAAA,qBAAA,oBAAA,KAAA;CACA,qBAAA,qBAAA,kBAAA,KAAA;CACA,qBAAA,qBAAA,wBAAA,KAAA;CACA,qBAAA,qBAAA,aAAA,KAAA;CACA,qBAAA,qBAAA,4BAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AAQA,MAAM,2BAA4C;CAChD,qBAAqB;CACrB,2BAA2B;AAC7B;;;;;;;;;;;;;AAsBA,SAAgB,kBACd,MACsB;CACtB,OAAO,0BAA0B,MAAM,UAAU;AACnD;;;;;AAMA,SAAgB,wBACd,MACsB;CACtB,OAAO,0BAA0B,MAAM,sBAAsB;AAC/D;AAEA,SAAS,0BACP,MACA,cACsB;CACtB,IAAI,KAAK,UAAU,KAAA,GAEjB,OAAA;CAGF,IAAI,KAAK,IAAI,WAAW,GAAG;EACzB,KAAK,KAAK,0BAA0B,KAAK,KAAK;EAC9C,O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":"version.cjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '3.0.0';\n"],"mappings":";AAMA,MAAa,UAAU"}
1
+ {"version":3,"file":"version.cjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '3.1.0';\n"],"mappings":";AAMA,MAAa,UAAU"}
@@ -1,5 +1,5 @@
1
1
  //#region src/version.ts
2
- const VERSION = "3.0.0";
2
+ const VERSION = "3.1.0";
3
3
  //#endregion
4
4
  export { VERSION };
5
5
 
@@ -1 +1 @@
1
- {"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '3.0.0';\n"],"mappings":";AAMA,MAAa,UAAU"}
1
+ {"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '3.1.0';\n"],"mappings":";AAMA,MAAa,UAAU"}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/core",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "OpenTelemetry Core provides constants and utilities shared by all OpenTelemetry SDK packages.",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",
@@ -99,5 +99,5 @@
99
99
  },
100
100
  "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-core",
101
101
  "sideEffects": false,
102
- "gitHead": "12a5817ad147c186a0e45a6637abd5abf423727a"
102
+ "gitHead": "9985264933cc7d93bfa4cbd02f1de562a050e9ce"
103
103
  }
@@ -3,7 +3,7 @@
3
3
  [![NPM Published Version][npm-img]][npm-url]
4
4
  [![Apache License][license-image]][license-image]
5
5
 
6
- The OpenTelemetry Resource is an immutable representation of the entity producing telemetry. For example, a process producing telemetry that is running in a container on Kubernetes has a Pod name, it is in a namespace and possibly is part of a Deployment which also has a name. All three of these attributes can be included in the `Resource`.
6
+ This package provides support for working with [OpenTelemetry Resource objects](https://opentelemetry.io/docs/specs/otel/resource/), e.g. `resourceFromAttributes(), and includes a number of *resource detectors* which gather resource attributes from the environment. (Other resource detectors, e.g. for cloud providers, are available in ["resource-detector-\*" packages in the opentelemetry-js-contrib.git repository](https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages).
7
7
 
8
8
  [This document][resource-semantic_conventions] defines standard attributes for resources which are accessible via [`@opentelemetry/semantic-conventions`](https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions).
9
9
 
@@ -30,6 +30,25 @@ const anotherResource = resourceFromAttributes({
30
30
  const mergedResource = resource.merge(anotherResource);
31
31
  ```
32
32
 
33
+ ## Resource detectors
34
+
35
+ ```ts
36
+ import { detectResources, processDetector, hostDetector } from '@opentelemetry/resources';
37
+
38
+ const resource = detectResources({
39
+ detectors: [ processDetector, hostDetector ],
40
+ });
41
+ ```
42
+
43
+ Included resource detectors:
44
+
45
+ - `hostDetector`: Detect `host.*` attributes per <https://opentelemetry.io/docs/specs/semconv/resource/host/>.
46
+ - `osDetector`: Detect `os.*` attributes per <https://opentelemetry.io/docs/specs/semconv/resource/os/>.
47
+ - `processDetector`: Detect `process.*` attributes per <https://opentelemetry.io/docs/specs/semconv/resource/process/>.
48
+ - `resourceAttributesEnvDetector`: Detect attributes from the `OTEL_RESOURCE_ATTRIBUTES` environment variable per <https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#general-sdk-configuration>.
49
+ - `serviceInstanceIdDetector`: Detect `service.instance.id` per <https://opentelemetry.io/docs/specs/semconv/resource/service/#service-instance>.
50
+ - `serviceNameEnvDetector`: Detect `service.name` from the `OTEL_SERVICE_NAME` environment variable per <https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#general-sdk-configuration>.
51
+
33
52
  ## Useful links
34
53
 
35
54
  - For more information on OpenTelemetry, visit: <https://opentelemetry.io/>
@@ -46,4 +65,4 @@ Apache 2.0 - See [LICENSE][license-url] for more information.
46
65
  [npm-url]: https://www.npmjs.com/package/@opentelemetry/resources
47
66
  [npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fresources.svg
48
67
 
49
- [resource-semantic_conventions]: https://github.com/open-telemetry/opentelemetry-specification/tree/master/specification/resource/semantic_conventions
68
+ [resource-semantic_conventions]: https://opentelemetry.io/docs/specs/semconv/resource/
@@ -1,15 +1,15 @@
1
+ const require_ResourceAttributesEnvDetector = require("./ResourceAttributesEnvDetector.cjs");
1
2
  let _opentelemetry_api = require("@opentelemetry/api");
2
3
  let _opentelemetry_core = require("@opentelemetry/core");
3
4
  let _opentelemetry_semantic_conventions = require("@opentelemetry/semantic-conventions");
4
5
  //#region src/detectors/EnvDetector.ts
5
6
  /**
6
- * EnvDetector can be used to detect the presence of and create a Resource
7
- * from the OTEL_RESOURCE_ATTRIBUTES environment variable.
7
+ * EnvDetector reads attributes from OTEL_RESOURCE_ATTRIBUTES and
8
+ * OTEL_SERVICE_NAME.
9
+ *
10
+ * @deprecated Use {ResourceAttributesEnvDetector} and {ServiceNameEnvDetector}
8
11
  */
9
- var EnvDetector = class {
10
- _MAX_LENGTH = 255;
11
- _COMMA_SEPARATOR = ",";
12
- _LABEL_KEY_VALUE_SPLITTER = "=";
12
+ var EnvDetector = class extends require_ResourceAttributesEnvDetector.ResourceAttributesEnvDetector {
13
13
  /**
14
14
  * Returns a {@link Resource} populated with attributes from the
15
15
  * OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async
@@ -30,48 +30,10 @@ var EnvDetector = class {
30
30
  if (serviceName) attributes[_opentelemetry_semantic_conventions.ATTR_SERVICE_NAME] = serviceName;
31
31
  return { attributes };
32
32
  }
33
- /**
34
- * Creates an attribute map from the OTEL_RESOURCE_ATTRIBUTES environment
35
- * variable.
36
- *
37
- * OTEL_RESOURCE_ATTRIBUTES: A comma-separated list of attributes in the
38
- * format "key1=value1,key2=value2". The ',' and '=' characters in keys
39
- * and values MUST be percent-encoded. Other characters MAY be percent-encoded.
40
- *
41
- * Per the spec, on any error (e.g., decoding failure), the entire environment
42
- * variable value is discarded.
43
- *
44
- * @param rawEnvAttributes The resource attributes as a comma-separated list
45
- * of key/value pairs.
46
- * @returns The parsed resource attributes.
47
- * @throws Error if parsing fails (caller handles by discarding all attributes)
48
- */
49
- _parseResourceAttributes(rawEnvAttributes) {
50
- if (!rawEnvAttributes) return {};
51
- const attributes = {};
52
- const rawAttributes = rawEnvAttributes.split(this._COMMA_SEPARATOR).filter((attr) => attr.trim() !== "");
53
- for (const rawAttribute of rawAttributes) {
54
- const keyValuePair = rawAttribute.split(this._LABEL_KEY_VALUE_SPLITTER);
55
- if (keyValuePair.length !== 2) throw new Error(`Invalid format for OTEL_RESOURCE_ATTRIBUTES: "${rawAttribute}". Expected format: key=value. The ',' and '=' characters must be percent-encoded in keys and values.`);
56
- const [rawKey, rawValue] = keyValuePair;
57
- const key = rawKey.trim();
58
- const value = rawValue.trim();
59
- if (key.length === 0) throw new Error(`Invalid OTEL_RESOURCE_ATTRIBUTES: empty attribute key in "${rawAttribute}".`);
60
- let decodedKey;
61
- let decodedValue;
62
- try {
63
- decodedKey = decodeURIComponent(key);
64
- decodedValue = decodeURIComponent(value);
65
- } catch (e) {
66
- throw new Error(`Failed to percent-decode OTEL_RESOURCE_ATTRIBUTES entry "${rawAttribute}": ${e instanceof Error ? e.message : e}`, { cause: e });
67
- }
68
- if (decodedKey.length > this._MAX_LENGTH) throw new Error(`Attribute key exceeds the maximum length of ${this._MAX_LENGTH} characters: "${decodedKey}".`);
69
- if (decodedValue.length > this._MAX_LENGTH) throw new Error(`Attribute value exceeds the maximum length of ${this._MAX_LENGTH} characters for key "${decodedKey}".`);
70
- attributes[decodedKey] = decodedValue;
71
- }
72
- return attributes;
73
- }
74
33
  };
34
+ /**
35
+ * @deprecated Use {resourceAttributesEnvDetector} and {serviceNameEnvDetector}
36
+ */
75
37
  const envDetector = new EnvDetector();
76
38
  //#endregion
77
39
  exports.envDetector = envDetector;
@@ -1 +1 @@
1
- {"version":3,"file":"EnvDetector.cjs","names":["getStringFromEnv","ATTR_SERVICE_NAME"],"sources":["../../src/detectors/EnvDetector.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Attributes } from '@opentelemetry/api';\nimport { diag } from '@opentelemetry/api';\nimport { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';\nimport type { ResourceDetectionConfig } from '../config';\nimport type { DetectedResource, ResourceDetector } from '../types';\nimport { getStringFromEnv } from '@opentelemetry/core';\n\n/**\n * EnvDetector can be used to detect the presence of and create a Resource\n * from the OTEL_RESOURCE_ATTRIBUTES environment variable.\n */\nclass EnvDetector implements ResourceDetector {\n // Type, attribute keys, and attribute values should not exceed 256 characters.\n private readonly _MAX_LENGTH = 255;\n\n // OTEL_RESOURCE_ATTRIBUTES is a comma-separated list of attributes.\n private readonly _COMMA_SEPARATOR = ',';\n\n // OTEL_RESOURCE_ATTRIBUTES contains key value pair separated by '='.\n private readonly _LABEL_KEY_VALUE_SPLITTER = '=';\n\n /**\n * Returns a {@link Resource} populated with attributes from the\n * OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async\n * function to conform to the Detector interface.\n *\n * @param config The resource detection config\n */\n detect(_config?: ResourceDetectionConfig): DetectedResource {\n const attributes: Attributes = {};\n\n const rawAttributes = getStringFromEnv('OTEL_RESOURCE_ATTRIBUTES');\n const serviceName = getStringFromEnv('OTEL_SERVICE_NAME');\n\n if (rawAttributes) {\n try {\n const parsedAttributes = this._parseResourceAttributes(rawAttributes);\n Object.assign(attributes, parsedAttributes);\n } catch (e) {\n diag.debug(`EnvDetector failed: ${e instanceof Error ? e.message : e}`);\n }\n }\n\n if (serviceName) {\n attributes[ATTR_SERVICE_NAME] = serviceName;\n }\n\n return { attributes };\n }\n\n /**\n * Creates an attribute map from the OTEL_RESOURCE_ATTRIBUTES environment\n * variable.\n *\n * OTEL_RESOURCE_ATTRIBUTES: A comma-separated list of attributes in the\n * format \"key1=value1,key2=value2\". The ',' and '=' characters in keys\n * and values MUST be percent-encoded. Other characters MAY be percent-encoded.\n *\n * Per the spec, on any error (e.g., decoding failure), the entire environment\n * variable value is discarded.\n *\n * @param rawEnvAttributes The resource attributes as a comma-separated list\n * of key/value pairs.\n * @returns The parsed resource attributes.\n * @throws Error if parsing fails (caller handles by discarding all attributes)\n */\n private _parseResourceAttributes(rawEnvAttributes?: string): Attributes {\n if (!rawEnvAttributes) return {};\n\n const attributes: Attributes = {};\n const rawAttributes: string[] = rawEnvAttributes\n .split(this._COMMA_SEPARATOR)\n .filter(attr => attr.trim() !== ''); // Filter out empty entries\n\n for (const rawAttribute of rawAttributes) {\n const keyValuePair: string[] = rawAttribute.split(\n this._LABEL_KEY_VALUE_SPLITTER\n );\n\n // Per spec: ',' and '=' MUST be percent-encoded in keys and values.\n // If we get != 2 parts, there's an unencoded '=' which is an error.\n if (keyValuePair.length !== 2) {\n throw new Error(\n `Invalid format for OTEL_RESOURCE_ATTRIBUTES: \"${rawAttribute}\". ` +\n \"Expected format: key=value. The ',' and '=' characters must be percent-encoded in keys and values.\"\n );\n }\n\n const [rawKey, rawValue] = keyValuePair;\n const key = rawKey.trim();\n const value = rawValue.trim();\n\n if (key.length === 0) {\n throw new Error(\n `Invalid OTEL_RESOURCE_ATTRIBUTES: empty attribute key in \"${rawAttribute}\".`\n );\n }\n\n let decodedKey: string;\n let decodedValue: string;\n try {\n decodedKey = decodeURIComponent(key);\n decodedValue = decodeURIComponent(value);\n } catch (e) {\n throw new Error(\n `Failed to percent-decode OTEL_RESOURCE_ATTRIBUTES entry \"${rawAttribute}\": ${e instanceof Error ? e.message : e}`,\n { cause: e }\n );\n }\n\n if (decodedKey.length > this._MAX_LENGTH) {\n throw new Error(\n `Attribute key exceeds the maximum length of ${this._MAX_LENGTH} characters: \"${decodedKey}\".`\n );\n }\n\n if (decodedValue.length > this._MAX_LENGTH) {\n throw new Error(\n `Attribute value exceeds the maximum length of ${this._MAX_LENGTH} characters for key \"${decodedKey}\".`\n );\n }\n\n attributes[decodedKey] = decodedValue;\n }\n\n return attributes;\n }\n}\n\nexport const envDetector = new EnvDetector();\n"],"mappings":";;;;;;;;AAgBA,IAAM,cAAN,MAA8C;CAE5C,cAA+B;CAG/B,mBAAoC;CAGpC,4BAA6C;;;;;;;;CAS7C,OAAO,SAAqD;EAC1D,MAAM,aAAyB,CAAC;EAEhC,MAAM,iBAAA,GAAgBA,oBAAAA,iBAAAA,CAAiB,0BAA0B;EACjE,MAAM,eAAA,GAAcA,oBAAAA,iBAAAA,CAAiB,mBAAmB;EAExD,IAAI,eACF,IAAI;GACF,MAAM,mBAAmB,KAAK,yBAAyB,aAAa;GACpE,OAAO,OAAO,YAAY,gBAAgB;EAC5C,SAAS,GAAG;GACV,mBAAA,KAAK,MAAM,uBAAuB,aAAa,QAAQ,EAAE,UAAU,GAAG;EACxE;EAGF,IAAI,aACF,WAAWC,oCAAAA,qBAAqB;EAGlC,OAAO,EAAE,WAAW;CACtB;;;;;;;;;;;;;;;;;CAkBA,yBAAiC,kBAAuC;EACtE,IAAI,CAAC,kBAAkB,OAAO,CAAC;EAE/B,MAAM,aAAyB,CAAC;EAChC,MAAM,gBAA0B,iBAC7B,MAAM,KAAK,gBAAgB,CAAC,CAC5B,QAAO,SAAQ,KAAK,KAAK,MAAM,EAAE;EAEpC,KAAK,MAAM,gBAAgB,eAAe;GACxC,MAAM,eAAyB,aAAa,MAC1C,KAAK,yBACP;GAIA,IAAI,aAAa,WAAW,GAC1B,MAAM,IAAI,MACR,iDAAiD,aAAa,sGAEhE;GAGF,MAAM,CAAC,QAAQ,YAAY;GAC3B,MAAM,MAAM,OAAO,KAAK;GACxB,MAAM,QAAQ,SAAS,KAAK;GAE5B,IAAI,IAAI,WAAW,GACjB,MAAM,IAAI,MACR,6DAA6D,aAAa,GAC5E;GAGF,IAAI;GACJ,IAAI;GACJ,IAAI;IACF,aAAa,mBAAmB,GAAG;IACnC,eAAe,mBAAmB,KAAK;GACzC,SAAS,GAAG;IACV,MAAM,IAAI,MACR,4DAA4D,aAAa,KAAK,aAAa,QAAQ,EAAE,UAAU,KAC/G,EAAE,OAAO,EAAE,CACb;GACF;GAEA,IAAI,WAAW,SAAS,KAAK,aAC3B,MAAM,IAAI,MACR,+CAA+C,KAAK,YAAY,gBAAgB,WAAW,GAC7F;GAGF,IAAI,aAAa,SAAS,KAAK,aAC7B,MAAM,IAAI,MACR,iDAAiD,KAAK,YAAY,uBAAuB,WAAW,GACtG;GAGF,WAAW,cAAc;EAC3B;EAEA,OAAO;CACT;AACF;AAEA,MAAa,cAAc,IAAI,YAAY"}
1
+ {"version":3,"file":"EnvDetector.cjs","names":["ResourceAttributesEnvDetector","getStringFromEnv","ATTR_SERVICE_NAME"],"sources":["../../src/detectors/EnvDetector.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Attributes } from '@opentelemetry/api';\nimport { diag } from '@opentelemetry/api';\nimport { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';\nimport type { ResourceDetectionConfig } from '../config';\nimport type { DetectedResource } from '../types';\nimport { getStringFromEnv } from '@opentelemetry/core';\nimport { ResourceAttributesEnvDetector } from './ResourceAttributesEnvDetector';\n\n/**\n * EnvDetector reads attributes from OTEL_RESOURCE_ATTRIBUTES and\n * OTEL_SERVICE_NAME.\n *\n * @deprecated Use {ResourceAttributesEnvDetector} and {ServiceNameEnvDetector}\n */\nclass EnvDetector extends ResourceAttributesEnvDetector {\n /**\n * Returns a {@link Resource} populated with attributes from the\n * OTEL_RESOURCE_ATTRIBUTES environment variable. Note this is an async\n * function to conform to the Detector interface.\n *\n * @param config The resource detection config\n */\n override detect(_config?: ResourceDetectionConfig): DetectedResource {\n const attributes: Attributes = {};\n\n const rawAttributes = getStringFromEnv('OTEL_RESOURCE_ATTRIBUTES');\n const serviceName = getStringFromEnv('OTEL_SERVICE_NAME');\n\n if (rawAttributes) {\n try {\n const parsedAttributes = this._parseResourceAttributes(rawAttributes);\n Object.assign(attributes, parsedAttributes);\n } catch (e) {\n diag.debug(`EnvDetector failed: ${e instanceof Error ? e.message : e}`);\n }\n }\n\n if (serviceName) {\n attributes[ATTR_SERVICE_NAME] = serviceName;\n }\n\n return { attributes };\n }\n}\n\n/**\n * @deprecated Use {resourceAttributesEnvDetector} and {serviceNameEnvDetector}\n */\nexport const envDetector = new EnvDetector();\n"],"mappings":";;;;;;;;;;;AAmBA,IAAM,cAAN,cAA0BA,sCAAAA,8BAA8B;;;;;;;;CAQtD,OAAgB,SAAqD;EACnE,MAAM,aAAyB,CAAC;EAEhC,MAAM,iBAAA,GAAgBC,oBAAAA,iBAAAA,CAAiB,0BAA0B;EACjE,MAAM,eAAA,GAAcA,oBAAAA,iBAAAA,CAAiB,mBAAmB;EAExD,IAAI,eACF,IAAI;GACF,MAAM,mBAAmB,KAAK,yBAAyB,aAAa;GACpE,OAAO,OAAO,YAAY,gBAAgB;EAC5C,SAAS,GAAG;GACV,mBAAA,KAAK,MAAM,uBAAuB,aAAa,QAAQ,EAAE,UAAU,GAAG;EACxE;EAGF,IAAI,aACF,WAAWC,oCAAAA,qBAAqB;EAGlC,OAAO,EAAE,WAAW;CACtB;AACF;;;;AAKA,MAAa,cAAc,IAAI,YAAY"}