diff --git a/scripts/plugin.py b/scripts/plugin.py index c5fd931..15cbf96 100755 --- a/scripts/plugin.py +++ b/scripts/plugin.py @@ -31,6 +31,7 @@ INLINE_OPTIMIZATION = True FILE_PATH_PREFIX = "snowflake.telemetry._internal" FILE_NAME_SUFFIX = "_marshaler" +OPENTELEMETRY_PROTO_DIR = os.environ["OPENTELEMETRY_PROTO_DIR"] # Inline utility functions @@ -293,7 +294,7 @@ def from_descriptor(descriptor: FileDescriptorProto) -> "FileTemplate": # In the case of the opentelemetry-proto files, the preamble is the license header # Each line of the preamble is prefixed with "//" preamble = "" - with open(f'/tmp/opentelemetry-proto/{descriptor.name}', "r") as f: + with open(f'{OPENTELEMETRY_PROTO_DIR}/{descriptor.name}', "r") as f: line = f.readline() while line and line.startswith("//"): preamble += line.replace("//", "#", 1) diff --git a/scripts/proto_codegen.sh b/scripts/proto_codegen.sh index 9db288f..4c7b08b 100755 --- a/scripts/proto_codegen.sh +++ b/scripts/proto_codegen.sh @@ -60,7 +60,7 @@ find opentelemetry/proto/ -regex ".*_marshaler\.py" -exec rm {} + # generate proto code for all protos all_protos=$(find $PROTO_REPO_DIR/ -iname "*.proto") -python -m grpc_tools.protoc \ +OPENTELEMETRY_PROTO_DIR=$PROTO_REPO_DIR python -m grpc_tools.protoc \ -I $PROTO_REPO_DIR \ --plugin=protoc-gen-custom-plugin=$repo_root/scripts/plugin.py \ --custom-plugin_out=. \ diff --git a/tests/test_protoc_plugin.py b/tests/test_protoc_plugin.py index b0508d3..c27d923 100644 --- a/tests/test_protoc_plugin.py +++ b/tests/test_protoc_plugin.py @@ -60,6 +60,8 @@ def test_protoc_plugin(self): proto_file_dir = os.path.dirname(proto_file.name) proto_file_name = os.path.basename(proto_file.name) + os.environ["OPENTELEMETRY_PROTO_DIR"] = proto_file_dir + # Run protoc with custom plugin to generate serialization code for messages result = subprocess.run([ "python",