-
Notifications
You must be signed in to change notification settings - Fork 5
chore(deps): bump protobufjs
& tape
patch versions. Fix load of .proto
files
#66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4c2563a
f597be0
0d26e13
76f6c27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. Was the intent to move away from this hack eventually once we have a process to build/commit a proto.json and load that instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes! I think as part of the process of updating the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it possibly work to add a mostly-empty root.proto file at the top-level dir, load that first, then use its returned |
||
|
||
// 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; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we really using v1.0.0?
I thought it looked like opentelemetry-js.git was using a pre-1.0.0 tag version of the protos. I've no idea if it matters, however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be compatible but I'll sync up in a follow up PR