From cd9d4f0a2e9463c350e0ade229ea8928342053b2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 9 Feb 2024 20:34:23 +0100 Subject: [PATCH] chore(deps): bump `protobufjs` & `tape` patch versions. Fix load of `.proto` files (#66) Contains a temporary workaround for https://github.com/protobufjs/protobuf.js/issues/1971. Loading a file with non relative imports fail. --- package-lock.json | 71 ++++++++++++------------ packages/mockotlpserver/lib/proto.js | 54 ++++++++++++------ packages/mockotlpserver/package.json | 2 +- packages/opentelemetry-node/package.json | 2 +- 4 files changed, 77 insertions(+), 52 deletions(-) diff --git a/package-lock.json b/package-lock.json index f3ed06b7..bfb46f03 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2346,13 +2346,16 @@ } }, "node_modules/has-dynamic-import": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/has-dynamic-import/-/has-dynamic-import-2.0.1.tgz", - "integrity": "sha512-X3fbtsZmwb6W7fJGR9o7x65fZoodygCrZ3TVycvghP62yYQfS0t4RS0Qcz+j5tQYUKeSWS09tHkWW6WhFV3XhQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/has-dynamic-import/-/has-dynamic-import-2.1.0.tgz", + "integrity": "sha512-su0anMkNEnJKZ/rB99jn3y6lV/J8Ro96hBJ28YAeVzj5rWxH+YL/AdCyiYYA1HDLV9YhmvqpWSJJj2KLo1MX6g==", "dev": true, "dependencies": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.1" + "call-bind": "^1.0.5", + "get-intrinsic": "^1.2.2" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -3482,9 +3485,9 @@ } }, "node_modules/protobufjs": { - "version": "7.2.5", - "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.5.tgz", - "integrity": "sha512-gGXRSXvxQ7UiPgfw8gevrfRWcTlSbOFg+p/N+JVJEK5VhueL2miT6qTymqAmjr1Q5WbOCyJbyrk6JfWKwlFn6A==", + "version": "7.2.6", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.6.tgz", + "integrity": "sha512-dgJaEDDL6x8ASUZ1YqWciTRrdOuYNzoOf27oHNfdyvKqHr5i0FV7FSLU+aIeFjyFgVxrpTOtQUi0BLLBymZaBw==", "hasInstallScript": true, "dependencies": { "@protobufjs/aspromise": "^1.1.2", @@ -4163,31 +4166,31 @@ } }, "node_modules/tape": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/tape/-/tape-5.7.2.tgz", - "integrity": "sha512-cvSyprYahyOYXbtBwV/B7nrx7kINeZ3VZ9fKoSywoPwZN3oQ1WVLvt+Vl0XCz/gi37CDrY3dlW790nzviIzoPw==", + "version": "5.7.4", + "resolved": "https://registry.npmjs.org/tape/-/tape-5.7.4.tgz", + "integrity": "sha512-uaigP+5H9+E8aaMLKMbGkDd33G5TKu4UFpapqT7um+8xSHQQUS2lJNd+hTj9fFVQLg8bmcIofwc8b9f6+ISSfQ==", "dev": true, "dependencies": { "@ljharb/resumer": "^0.0.1", "@ljharb/through": "^2.3.11", "array.prototype.every": "^1.1.5", "call-bind": "^1.0.5", - "deep-equal": "^2.2.2", + "deep-equal": "^2.2.3", "defined": "^1.0.1", "dotignore": "^0.1.2", "for-each": "^0.3.3", "get-package-type": "^0.1.0", "glob": "^7.2.3", - "has-dynamic-import": "^2.0.1", + "has-dynamic-import": "^2.1.0", "hasown": "^2.0.0", "inherits": "^2.0.4", "is-regex": "^1.1.4", "minimist": "^1.2.8", - "mock-property": "^1.0.2", + "mock-property": "^1.0.3", "object-inspect": "^1.13.1", "object-is": "^1.1.5", "object-keys": "^1.1.1", - "object.assign": "^4.1.4", + "object.assign": "^4.1.5", "resolve": "^2.0.0-next.5", "string.prototype.trim": "^1.2.8" }, @@ -4603,7 +4606,7 @@ "@grpc/proto-loader": "^0.7.10", "dashdash": "^2.0.0", "long": "^5.2.3", - "protobufjs": "^7.2.5", + "protobufjs": "^7.2.6", "safe-stable-stringify": "^2.4.3" }, "bin": { @@ -4855,7 +4858,7 @@ "express": "^4.18.2", "module-details-from-path": "^1.0.3", "semver": "^7.6.0", - "tape": "^5.7.2" + "tape": "^5.7.4" }, "engines": { "node": ">=14" @@ -5121,7 +5124,7 @@ "@opentelemetry/sdk-node": "^0.47.0", "dashdash": "^2.0.0", "long": "^5.2.3", - "protobufjs": "^7.2.5", + "protobufjs": "^7.2.6", "safe-stable-stringify": "^2.4.3" }, "dependencies": { @@ -5294,7 +5297,7 @@ "module-details-from-path": "^1.0.3", "safe-stable-stringify": "^2.4.3", "semver": "^7.6.0", - "tape": "^5.7.2" + "tape": "^5.7.4" }, "dependencies": { "@opentelemetry/context-async-hooks": { @@ -7172,13 +7175,13 @@ "dev": true }, "has-dynamic-import": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/has-dynamic-import/-/has-dynamic-import-2.0.1.tgz", - "integrity": "sha512-X3fbtsZmwb6W7fJGR9o7x65fZoodygCrZ3TVycvghP62yYQfS0t4RS0Qcz+j5tQYUKeSWS09tHkWW6WhFV3XhQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/has-dynamic-import/-/has-dynamic-import-2.1.0.tgz", + "integrity": "sha512-su0anMkNEnJKZ/rB99jn3y6lV/J8Ro96hBJ28YAeVzj5rWxH+YL/AdCyiYYA1HDLV9YhmvqpWSJJj2KLo1MX6g==", "dev": true, "requires": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.1" + "call-bind": "^1.0.5", + "get-intrinsic": "^1.2.2" } }, "has-flag": { @@ -7986,9 +7989,9 @@ } }, "protobufjs": { - "version": "7.2.5", - "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.5.tgz", - "integrity": "sha512-gGXRSXvxQ7UiPgfw8gevrfRWcTlSbOFg+p/N+JVJEK5VhueL2miT6qTymqAmjr1Q5WbOCyJbyrk6JfWKwlFn6A==", + "version": "7.2.6", + "resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-7.2.6.tgz", + "integrity": "sha512-dgJaEDDL6x8ASUZ1YqWciTRrdOuYNzoOf27oHNfdyvKqHr5i0FV7FSLU+aIeFjyFgVxrpTOtQUi0BLLBymZaBw==", "requires": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", @@ -8448,31 +8451,31 @@ "integrity": "sha512-xQada8ByGGFoRXJaUptGgddn3i7IjtSdqNdCKzB8xkzsM7pHnfLYBWxkPdGzhZ0Z/l+W1yo+aZQZ74d2isj8kw==" }, "tape": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/tape/-/tape-5.7.2.tgz", - "integrity": "sha512-cvSyprYahyOYXbtBwV/B7nrx7kINeZ3VZ9fKoSywoPwZN3oQ1WVLvt+Vl0XCz/gi37CDrY3dlW790nzviIzoPw==", + "version": "5.7.4", + "resolved": "https://registry.npmjs.org/tape/-/tape-5.7.4.tgz", + "integrity": "sha512-uaigP+5H9+E8aaMLKMbGkDd33G5TKu4UFpapqT7um+8xSHQQUS2lJNd+hTj9fFVQLg8bmcIofwc8b9f6+ISSfQ==", "dev": true, "requires": { "@ljharb/resumer": "^0.0.1", "@ljharb/through": "^2.3.11", "array.prototype.every": "^1.1.5", "call-bind": "^1.0.5", - "deep-equal": "^2.2.2", + "deep-equal": "^2.2.3", "defined": "^1.0.1", "dotignore": "^0.1.2", "for-each": "^0.3.3", "get-package-type": "^0.1.0", "glob": "^7.2.3", - "has-dynamic-import": "^2.0.1", + "has-dynamic-import": "^2.1.0", "hasown": "^2.0.0", "inherits": "^2.0.4", "is-regex": "^1.1.4", "minimist": "^1.2.8", - "mock-property": "^1.0.2", + "mock-property": "^1.0.3", "object-inspect": "^1.13.1", "object-is": "^1.1.5", "object-keys": "^1.1.1", - "object.assign": "^4.1.4", + "object.assign": "^4.1.5", "resolve": "^2.0.0-next.5", "string.prototype.trim": "^1.2.8" }, diff --git a/packages/mockotlpserver/lib/proto.js b/packages/mockotlpserver/lib/proto.js index 62ac1f72..24bca029 100644 --- a/packages/mockotlpserver/lib/proto.js +++ b/packages/mockotlpserver/lib/proto.js @@ -2,29 +2,51 @@ * Some utilities for working with the OpenTelemetry proto files. */ -const path = require('path'); +const {resolve} = require('path'); -const protobuf = require('protobufjs'); +const {Root} = require('protobufjs'); // TODO: for now `proto` files are copied from -// https://github.com/open-telemetry/opentelemetry-proto +// https://github.com/open-telemetry/opentelemetry-proto/releases/tag/v1.0.0 // but maybe its better to have a submodule like otel-js does -const prefix = path.resolve(__dirname, '../opentelemetry/proto/'); +const prefix = resolve(__dirname, '..'); const paths = [ - '/common/v1/common.proto', - '/resource/v1/resource.proto', - '/logs/v1/logs.proto', - '/metrics/v1/metrics.proto', - '/trace/v1/trace.proto', - '/collector/logs/v1/logs_service.proto', - '/collector/metrics/v1/metrics_service.proto', - '/collector/trace/v1/trace_service.proto', + '/opentelemetry/proto/common/v1/common.proto', + '/opentelemetry/proto/resource/v1/resource.proto', + '/opentelemetry/proto/logs/v1/logs.proto', + '/opentelemetry/proto/metrics/v1/metrics.proto', + '/opentelemetry/proto/trace/v1/trace.proto', + '/opentelemetry/proto/collector/logs/v1/logs_service.proto', + '/opentelemetry/proto/collector/metrics/v1/metrics_service.proto', + '/opentelemetry/proto/collector/trace/v1/trace_service.proto', ]; -let root; -for (const p of paths) { - root = protobuf.loadSync(`${prefix}${p}`, root); -} +// Craete a new Root so we can patch it +const root = new Root(); + +// This function is patched because the Root class does not have any +// referece of which is the root path of the proto files. Instead it +// takes the folder of current file being processed as the root path +// resulting in duplicated subpaths +// Example: resource.proto file importing common.proto results in +// /Users/.../mockotlpserver/opentelemetry/proto/resource/v1/opentelemetry/proto/common/v1/common.proto +root.resolvePath = function patchResolvePath(filename) { + let path = Root.prototype.resolvePath.apply(root, arguments); + if (filename) { + const folder = resolve(filename, '..'); + path = prefix + path.replace(folder, ''); + } + return path; +}; + +// Load the files at once +root.loadSync(paths.map((p) => `${prefix}${p}`)); + +/** + * Return `any` for now itherwise we get type errors when using + * `root.lookupType(...)` in `normalize.js + * @returns {any} + */ function getProtoRoot() { return root; } diff --git a/packages/mockotlpserver/package.json b/packages/mockotlpserver/package.json index 5e6613b6..217b6f57 100644 --- a/packages/mockotlpserver/package.json +++ b/packages/mockotlpserver/package.json @@ -43,7 +43,7 @@ "@grpc/proto-loader": "^0.7.10", "dashdash": "^2.0.0", "long": "^5.2.3", - "protobufjs": "^7.2.5", + "protobufjs": "^7.2.6", "safe-stable-stringify": "^2.4.3" }, "devDependencies": { diff --git a/packages/opentelemetry-node/package.json b/packages/opentelemetry-node/package.json index 1f14ef67..f07e8bd8 100644 --- a/packages/opentelemetry-node/package.json +++ b/packages/opentelemetry-node/package.json @@ -48,6 +48,6 @@ "express": "^4.18.2", "module-details-from-path": "^1.0.3", "semver": "^7.6.0", - "tape": "^5.7.2" + "tape": "^5.7.4" } }