@salesforce/cli 2.159.0 → 2.159.2
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.
- package/README.md +12 -12
- package/node_modules/@oclif/plugin-plugins/README.md +7 -7
- package/node_modules/@oclif/plugin-plugins/oclif.manifest.json +1 -1
- package/node_modules/@oclif/plugin-plugins/package.json +7 -7
- package/node_modules/@opentelemetry/core/dist/common/attributes.cjs +5 -0
- package/node_modules/@opentelemetry/core/dist/common/attributes.cjs.map +1 -1
- package/node_modules/@opentelemetry/core/dist/common/attributes.mjs +5 -0
- package/node_modules/@opentelemetry/core/dist/common/attributes.mjs.map +1 -1
- package/node_modules/@opentelemetry/core/dist/version.cjs +1 -1
- package/node_modules/@opentelemetry/core/dist/version.cjs.map +1 -1
- package/node_modules/@opentelemetry/core/dist/version.mjs +1 -1
- package/node_modules/@opentelemetry/core/dist/version.mjs.map +1 -1
- package/node_modules/@opentelemetry/core/package.json +2 -2
- package/node_modules/@opentelemetry/resources/README.md +21 -2
- package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.cjs +9 -47
- package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.cjs.map +1 -1
- package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.d.cts +10 -24
- package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.d.cts.map +1 -1
- package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.d.mts +10 -24
- package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.d.mts.map +1 -1
- package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.mjs +9 -47
- package/node_modules/@opentelemetry/resources/dist/detectors/EnvDetector.mjs.map +1 -1
- package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.cjs +70 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.cjs.map +1 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.d.cts +35 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.d.cts.map +1 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.d.mts +35 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.d.mts.map +1 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.mjs +69 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ResourceAttributesEnvDetector.mjs.map +1 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.cjs +19 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.cjs.map +1 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.d.cts +12 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.d.cts.map +1 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.d.mts +12 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.d.mts.map +1 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.mjs +19 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/ServiceNameEnvDetector.mjs.map +1 -0
- package/node_modules/@opentelemetry/resources/dist/detectors/index.d.cts +3 -1
- package/node_modules/@opentelemetry/resources/dist/detectors/index.d.mts +3 -1
- package/node_modules/@opentelemetry/resources/dist/detectors/index.mjs +3 -1
- package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.cjs +0 -3
- package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.cjs.map +1 -1
- package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.d.cts +0 -3
- package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.d.cts.map +1 -1
- package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.d.mts +0 -3
- package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.d.mts.map +1 -1
- package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.mjs +0 -3
- package/node_modules/@opentelemetry/resources/dist/detectors/platform/node/ServiceInstanceIdDetector.mjs.map +1 -1
- package/node_modules/@opentelemetry/resources/dist/index.cjs +4 -0
- package/node_modules/@opentelemetry/resources/dist/index.d.cts +3 -1
- package/node_modules/@opentelemetry/resources/dist/index.d.mts +3 -1
- package/node_modules/@opentelemetry/resources/dist/index.mjs +3 -1
- package/node_modules/@opentelemetry/resources/package.json +3 -3
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_attributes.cjs +1461 -176
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_attributes.cjs.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_attributes.d.cts +1363 -171
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_attributes.d.cts.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_attributes.d.mts +1363 -171
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_attributes.d.mts.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_attributes.mjs +1363 -171
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_attributes.mjs.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_events.cjs +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_events.cjs.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_events.d.cts +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_events.d.mts +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_events.mjs +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_events.mjs.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_metrics.cjs +382 -95
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_metrics.cjs.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_metrics.d.cts +358 -94
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_metrics.d.cts.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_metrics.d.mts +358 -94
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_metrics.d.mts.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_metrics.mjs +358 -94
- package/node_modules/@opentelemetry/semantic-conventions/dist/experimental_metrics.mjs.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/index-incubating.cjs +132 -8
- package/node_modules/@opentelemetry/semantic-conventions/dist/index-incubating.d.cts +5 -5
- package/node_modules/@opentelemetry/semantic-conventions/dist/index-incubating.d.mts +5 -5
- package/node_modules/@opentelemetry/semantic-conventions/dist/index-incubating.mjs +5 -5
- package/node_modules/@opentelemetry/semantic-conventions/dist/index.cjs +8 -0
- package/node_modules/@opentelemetry/semantic-conventions/dist/index.d.cts +3 -3
- package/node_modules/@opentelemetry/semantic-conventions/dist/index.d.mts +3 -3
- package/node_modules/@opentelemetry/semantic-conventions/dist/index.mjs +3 -3
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_attributes.cjs +104 -13
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_attributes.cjs.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_attributes.d.cts +99 -14
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_attributes.d.cts.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_attributes.d.mts +99 -14
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_attributes.d.mts.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_attributes.mjs +99 -14
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_attributes.mjs.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_metrics.cjs +16 -0
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_metrics.cjs.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_metrics.d.cts +15 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_metrics.d.cts.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_metrics.d.mts +15 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_metrics.d.mts.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_metrics.mjs +15 -1
- package/node_modules/@opentelemetry/semantic-conventions/dist/stable_metrics.mjs.map +1 -1
- package/node_modules/@opentelemetry/semantic-conventions/package.json +2 -2
- package/node_modules/@salesforce/plugin-trust/README.md +14 -30
- package/node_modules/@salesforce/plugin-trust/oclif.manifest.json +1 -1
- package/node_modules/@salesforce/plugin-trust/package.json +4 -4
- package/node_modules/npm/docs/content/commands/npm-ls.md +1 -1
- package/node_modules/npm/docs/content/commands/npm.md +1 -1
- package/node_modules/npm/docs/output/commands/npm-access.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-adduser.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-approve-scripts.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-audit.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-bugs.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-cache.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-ci.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-completion.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-config.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-dedupe.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-deny-scripts.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-deprecate.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-diff.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-dist-tag.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-docs.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-doctor.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-edit.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-exec.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-explain.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-explore.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-find-dupes.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-fund.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-get.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-help-search.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-help.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-init.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-install-ci-test.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-install-scripts.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-install-test.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-install.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-link.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-ll.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-login.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-logout.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-ls.html +3 -3
- package/node_modules/npm/docs/output/commands/npm-org.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-outdated.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-owner.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-pack.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-ping.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-pkg.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-prefix.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-profile.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-prune.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-publish.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-query.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-rebuild.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-repo.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-restart.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-root.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-run.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-sbom.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-search.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-set.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-shrinkwrap.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-stage.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-star.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-stars.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-start.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-stop.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-team.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-test.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-token.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-trust.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-undeprecate.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-uninstall.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-unpublish.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-unstar.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-update.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-version.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-view.html +2 -2
- package/node_modules/npm/docs/output/commands/npm-whoami.html +2 -2
- package/node_modules/npm/docs/output/commands/npm.html +3 -3
- package/node_modules/npm/docs/output/commands/npx.html +2 -2
- package/node_modules/npm/docs/output/configuring-npm/folders.html +2 -2
- package/node_modules/npm/docs/output/configuring-npm/install.html +2 -2
- package/node_modules/npm/docs/output/configuring-npm/npm-global.html +2 -2
- package/node_modules/npm/docs/output/configuring-npm/npm-json.html +2 -2
- package/node_modules/npm/docs/output/configuring-npm/npm-shrinkwrap-json.html +2 -2
- package/node_modules/npm/docs/output/configuring-npm/npmrc.html +2 -2
- package/node_modules/npm/docs/output/configuring-npm/package-json.html +2 -2
- package/node_modules/npm/docs/output/configuring-npm/package-lock-json.html +2 -2
- package/node_modules/npm/docs/output/using-npm/config.html +2 -2
- package/node_modules/npm/docs/output/using-npm/dependency-selectors.html +2 -2
- package/node_modules/npm/docs/output/using-npm/developers.html +2 -2
- package/node_modules/npm/docs/output/using-npm/logging.html +2 -2
- package/node_modules/npm/docs/output/using-npm/orgs.html +2 -2
- package/node_modules/npm/docs/output/using-npm/package-spec.html +2 -2
- package/node_modules/npm/docs/output/using-npm/registry.html +2 -2
- package/node_modules/npm/docs/output/using-npm/removal.html +2 -2
- package/node_modules/npm/docs/output/using-npm/scope.html +2 -2
- package/node_modules/npm/docs/output/using-npm/scripts.html +2 -2
- package/node_modules/npm/docs/output/using-npm/workspaces.html +2 -2
- package/node_modules/npm/lib/cli/entry.js +1 -1
- package/node_modules/npm/man/man1/npm-access.1 +1 -1
- package/node_modules/npm/man/man1/npm-adduser.1 +1 -1
- package/node_modules/npm/man/man1/npm-approve-scripts.1 +1 -1
- package/node_modules/npm/man/man1/npm-audit.1 +1 -1
- package/node_modules/npm/man/man1/npm-bugs.1 +1 -1
- package/node_modules/npm/man/man1/npm-cache.1 +1 -1
- package/node_modules/npm/man/man1/npm-ci.1 +1 -1
- package/node_modules/npm/man/man1/npm-completion.1 +1 -1
- package/node_modules/npm/man/man1/npm-config.1 +1 -1
- package/node_modules/npm/man/man1/npm-dedupe.1 +1 -1
- package/node_modules/npm/man/man1/npm-deny-scripts.1 +1 -1
- package/node_modules/npm/man/man1/npm-deprecate.1 +1 -1
- package/node_modules/npm/man/man1/npm-diff.1 +1 -1
- package/node_modules/npm/man/man1/npm-dist-tag.1 +1 -1
- package/node_modules/npm/man/man1/npm-docs.1 +1 -1
- package/node_modules/npm/man/man1/npm-doctor.1 +1 -1
- package/node_modules/npm/man/man1/npm-edit.1 +1 -1
- package/node_modules/npm/man/man1/npm-exec.1 +1 -1
- package/node_modules/npm/man/man1/npm-explain.1 +1 -1
- package/node_modules/npm/man/man1/npm-explore.1 +1 -1
- package/node_modules/npm/man/man1/npm-find-dupes.1 +1 -1
- package/node_modules/npm/man/man1/npm-fund.1 +1 -1
- package/node_modules/npm/man/man1/npm-get.1 +1 -1
- package/node_modules/npm/man/man1/npm-help-search.1 +1 -1
- package/node_modules/npm/man/man1/npm-help.1 +1 -1
- package/node_modules/npm/man/man1/npm-init.1 +1 -1
- package/node_modules/npm/man/man1/npm-install-ci-test.1 +1 -1
- package/node_modules/npm/man/man1/npm-install-scripts.1 +1 -1
- package/node_modules/npm/man/man1/npm-install-test.1 +1 -1
- package/node_modules/npm/man/man1/npm-install.1 +1 -1
- package/node_modules/npm/man/man1/npm-link.1 +1 -1
- package/node_modules/npm/man/man1/npm-ll.1 +1 -1
- package/node_modules/npm/man/man1/npm-login.1 +1 -1
- package/node_modules/npm/man/man1/npm-logout.1 +1 -1
- package/node_modules/npm/man/man1/npm-ls.1 +2 -2
- package/node_modules/npm/man/man1/npm-org.1 +1 -1
- package/node_modules/npm/man/man1/npm-outdated.1 +1 -1
- package/node_modules/npm/man/man1/npm-owner.1 +1 -1
- package/node_modules/npm/man/man1/npm-pack.1 +1 -1
- package/node_modules/npm/man/man1/npm-ping.1 +1 -1
- package/node_modules/npm/man/man1/npm-pkg.1 +1 -1
- package/node_modules/npm/man/man1/npm-prefix.1 +1 -1
- package/node_modules/npm/man/man1/npm-profile.1 +1 -1
- package/node_modules/npm/man/man1/npm-prune.1 +1 -1
- package/node_modules/npm/man/man1/npm-publish.1 +1 -1
- package/node_modules/npm/man/man1/npm-query.1 +1 -1
- package/node_modules/npm/man/man1/npm-rebuild.1 +1 -1
- package/node_modules/npm/man/man1/npm-repo.1 +1 -1
- package/node_modules/npm/man/man1/npm-restart.1 +1 -1
- package/node_modules/npm/man/man1/npm-root.1 +1 -1
- package/node_modules/npm/man/man1/npm-run.1 +1 -1
- package/node_modules/npm/man/man1/npm-sbom.1 +1 -1
- package/node_modules/npm/man/man1/npm-search.1 +1 -1
- package/node_modules/npm/man/man1/npm-set.1 +1 -1
- package/node_modules/npm/man/man1/npm-shrinkwrap.1 +1 -1
- package/node_modules/npm/man/man1/npm-stage.1 +1 -1
- package/node_modules/npm/man/man1/npm-star.1 +1 -1
- package/node_modules/npm/man/man1/npm-stars.1 +1 -1
- package/node_modules/npm/man/man1/npm-start.1 +1 -1
- package/node_modules/npm/man/man1/npm-stop.1 +1 -1
- package/node_modules/npm/man/man1/npm-team.1 +1 -1
- package/node_modules/npm/man/man1/npm-test.1 +1 -1
- package/node_modules/npm/man/man1/npm-token.1 +1 -1
- package/node_modules/npm/man/man1/npm-trust.1 +1 -1
- package/node_modules/npm/man/man1/npm-undeprecate.1 +1 -1
- package/node_modules/npm/man/man1/npm-uninstall.1 +1 -1
- package/node_modules/npm/man/man1/npm-unpublish.1 +1 -1
- package/node_modules/npm/man/man1/npm-unstar.1 +1 -1
- package/node_modules/npm/man/man1/npm-update.1 +1 -1
- package/node_modules/npm/man/man1/npm-version.1 +1 -1
- package/node_modules/npm/man/man1/npm-view.1 +1 -1
- package/node_modules/npm/man/man1/npm-whoami.1 +1 -1
- package/node_modules/npm/man/man1/npm.1 +2 -2
- package/node_modules/npm/man/man1/npx.1 +1 -1
- package/node_modules/npm/man/man5/folders.5 +1 -1
- package/node_modules/npm/man/man5/install.5 +1 -1
- package/node_modules/npm/man/man5/npm-global.5 +1 -1
- package/node_modules/npm/man/man5/npm-json.5 +1 -1
- package/node_modules/npm/man/man5/npm-shrinkwrap-json.5 +1 -1
- package/node_modules/npm/man/man5/npmrc.5 +1 -1
- package/node_modules/npm/man/man5/package-json.5 +1 -1
- package/node_modules/npm/man/man5/package-lock-json.5 +1 -1
- package/node_modules/npm/man/man7/config.7 +1 -1
- package/node_modules/npm/man/man7/dependency-selectors.7 +1 -1
- package/node_modules/npm/man/man7/developers.7 +1 -1
- package/node_modules/npm/man/man7/logging.7 +1 -1
- package/node_modules/npm/man/man7/orgs.7 +1 -1
- package/node_modules/npm/man/man7/package-spec.7 +1 -1
- package/node_modules/npm/man/man7/registry.7 +1 -1
- package/node_modules/npm/man/man7/removal.7 +1 -1
- package/node_modules/npm/man/man7/scope.7 +1 -1
- package/node_modules/npm/man/man7/scripts.7 +1 -1
- package/node_modules/npm/man/man7/workspaces.7 +1 -1
- package/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js +9 -2
- package/node_modules/npm/node_modules/@npmcli/promise-spawn/package.json +3 -2
- package/node_modules/npm/node_modules/bin-links/lib/get-paths.js +2 -0
- package/node_modules/npm/node_modules/bin-links/package.json +2 -1
- package/node_modules/npm/node_modules/ip-address/dist/common.js +2 -2
- package/node_modules/npm/node_modules/ip-address/dist/ipv4.js +7 -0
- package/node_modules/npm/node_modules/ip-address/dist/ipv6.js +7 -4
- package/node_modules/npm/node_modules/ip-address/dist/v6/constants.js +3 -0
- package/node_modules/npm/node_modules/ip-address/package.json +3 -2
- package/node_modules/npm/node_modules/libnpmexec/README.md +9 -1
- package/node_modules/npm/node_modules/libnpmexec/lib/index.js +6 -2
- package/node_modules/npm/node_modules/libnpmexec/lib/run-script.js +22 -5
- package/node_modules/npm/node_modules/libnpmexec/package.json +1 -1
- package/node_modules/npm/node_modules/pacote/lib/registry.js +71 -2
- package/node_modules/npm/node_modules/pacote/package.json +3 -2
- package/node_modules/npm/node_modules/semver/classes/range.js +2 -2
- package/node_modules/npm/node_modules/semver/internal/constants.js +30 -0
- package/node_modules/npm/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
- package/node_modules/npm/node_modules/semver/package.json +1 -1
- package/node_modules/npm/node_modules/undici/docs/docs/api/Client.md +2 -0
- package/node_modules/npm/node_modules/undici/lib/dispatcher/agent.js +6 -2
- package/node_modules/npm/node_modules/undici/lib/dispatcher/client-h1.js +0 -2
- package/node_modules/npm/node_modules/undici/lib/dispatcher/client-h2.js +0 -4
- package/node_modules/npm/node_modules/undici/lib/dispatcher/client.js +3 -2
- package/node_modules/npm/node_modules/undici/lib/dispatcher/dispatcher-base.js +9 -0
- package/node_modules/npm/node_modules/undici/lib/web/eventsource/eventsource-stream.js +91 -10
- package/node_modules/npm/node_modules/undici/lib/web/eventsource/eventsource.js +4 -1
- package/node_modules/npm/node_modules/undici/lib/web/fetch/index.js +7 -9
- package/node_modules/npm/node_modules/undici/lib/web/websocket/receiver.js +14 -0
- package/node_modules/npm/node_modules/undici/package.json +1 -1
- package/node_modules/npm/package.json +5 -5
- package/node_modules/semver/classes/range.js +2 -2
- package/node_modules/semver/internal/constants.js +30 -0
- package/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
- package/node_modules/semver/package.json +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +6 -6
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/MSVSUtil.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/MSVSVersion.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/__init__.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/common.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/input.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/msvs_emulation.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/ninja_syntax.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/simple_copy.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/xcode_emulation.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/xcode_ninja.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__pycache__/xcodeproj_file.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__pycache__/__init__.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__pycache__/make.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__pycache__/ninja.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__pycache__/xcode.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/__pycache__/__init__.cpython-314.pyc +0 -0
- package/node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/__pycache__/_structures.cpython-314.pyc +0 -0
- 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.159.
|
|
28
|
+
@salesforce/cli/2.159.2 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.
|
|
9274
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.15/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.
|
|
9319
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.15/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.
|
|
9368
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.15/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.
|
|
9399
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.15/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.
|
|
9414
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.15/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.
|
|
9451
|
+
_See code: [@salesforce/plugin-trust](https://github.com/salesforcecli/plugin-trust/blob/4.1.2/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.
|
|
9479
|
+
_See code: [@salesforce/plugin-trust](https://github.com/salesforcecli/plugin-trust/blob/4.1.2/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.
|
|
9516
|
+
_See code: [@salesforce/plugin-trust](https://github.com/salesforcecli/plugin-trust/blob/4.1.2/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.
|
|
9545
|
+
_See code: [@salesforce/plugin-trust](https://github.com/salesforcecli/plugin-trust/blob/4.1.2/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.
|
|
9573
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.15/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.
|
|
9591
|
+
_See code: [@oclif/plugin-plugins](https://github.com/oclif/plugin-plugins/blob/7.0.15/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.
|
|
120
|
+
_See code: [src/commands/plugins/index.ts](https://github.com/oclif/plugin-plugins/blob/7.0.15/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.
|
|
194
|
+
_See code: [src/commands/plugins/inspect.ts](https://github.com/oclif/plugin-plugins/blob/7.0.15/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.
|
|
243
|
+
_See code: [src/commands/plugins/install.ts](https://github.com/oclif/plugin-plugins/blob/7.0.15/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.
|
|
274
|
+
_See code: [src/commands/plugins/link.ts](https://github.com/oclif/plugin-plugins/blob/7.0.15/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.
|
|
315
|
+
_See code: [src/commands/plugins/reset.ts](https://github.com/oclif/plugin-plugins/blob/7.0.15/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.
|
|
343
|
+
_See code: [src/commands/plugins/uninstall.ts](https://github.com/oclif/plugin-plugins/blob/7.0.15/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.
|
|
387
|
+
_See code: [src/commands/plugins/update.ts](https://github.com/oclif/plugin-plugins/blob/7.0.15/src/commands/plugins/update.ts)_
|
|
388
388
|
<!-- commandsstop -->
|
|
389
389
|
|
|
390
390
|
# Contributing
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/plugin-plugins",
|
|
3
3
|
"description": "plugins plugin for oclif",
|
|
4
|
-
"version": "7.0.
|
|
4
|
+
"version": "7.0.15",
|
|
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.
|
|
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.
|
|
25
|
-
"@oclif/test": "^5.0.
|
|
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.
|
|
38
|
-
"eslint-config-oclif": "^7.1.
|
|
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.
|
|
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;CACA,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,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,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B;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,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C6B;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"}
|
|
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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.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
|
+
{"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 +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.
|
|
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.
|
|
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": "
|
|
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
|
-
|
|
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://
|
|
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
|
|
7
|
-
*
|
|
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
|
|
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"}
|