diff --git a/.github/workflows/update_protos.yml b/.github/workflows/update_protos.yml index 93618e711..e3cef39bb 100644 --- a/.github/workflows/update_protos.yml +++ b/.github/workflows/update_protos.yml @@ -25,6 +25,11 @@ jobs: - name: Install package run: poetry install --all-extras + - name: Store API version + run: | + python3 etc/_update_version_metadata.py src/viam/version_metadata.py ${{ github.event.client_payload.tag }} + echo "Updated API version to ${{ github.event.client_payload.tag }} in src/viam/version_metadata.py" + - name: Generate buf run: make buf env: diff --git a/etc/_update_version_metadata.py b/etc/_update_version_metadata.py new file mode 100644 index 000000000..8d64e237e --- /dev/null +++ b/etc/_update_version_metadata.py @@ -0,0 +1,20 @@ +import re +import sys + + +def update_version(file_path: str, new_version: str): + with open(file_path, "r") as file: + data = file.read() + + data = re.sub(r'(API_VERSION\s*=\s*)"[0-9]+\.[0-9]+\.[0-9]+"', f'\\1"{new_version}"', data) + + with open(file_path, 'w') as file: + file.write(data) + + +if __name__ == "__main__": + if len(sys.argv) != 3: + print("Usage: python3 etc/update_version.py ") + sys.exit(1) + + update_version(sys.argv[1], sys.argv[2]) diff --git a/src/viam/rpc/dial.py b/src/viam/rpc/dial.py index e0f3b1e8f..5e0422d57 100644 --- a/src/viam/rpc/dial.py +++ b/src/viam/rpc/dial.py @@ -11,6 +11,7 @@ from grpclib.client import Channel, Stream from grpclib.const import Cardinality +from grpclib.events import SendRequest, listen from grpclib.metadata import Deadline, _MetadataLike from grpclib.protocol import H2Protocol from grpclib.stream import _RecvType, _SendType @@ -21,6 +22,7 @@ from viam.proto.rpc.auth import AuthenticateRequest, AuthServiceStub from viam.proto.rpc.auth import Credentials as PBCredentials from viam.utils import to_thread +from viam.version_metadata import API_VERSION, SDK_VERSION LOGGER = logging.getLogger(__name__) @@ -277,15 +279,20 @@ def free_str(self, ptr: ctypes.c_void_p): async def dial(address: str, options: Optional[DialOptions] = None) -> ViamChannel: + async def send_request(event: SendRequest): + event.metadata["viam-client"] = f"python;{SDK_VERSION};{API_VERSION}" + opts = options if options else DialOptions() if opts.disable_webrtc: channel = await _dial_direct(address, options) + listen(channel, SendRequest, send_request) return ViamChannel(channel, lambda: None) runtime = _Runtime() path, path_ptr = await runtime.dial(address, opts) if path: LOGGER.info(f"Connecting to socket: {path}") chan = Channel(path=path, ssl=None) + listen(chan, SendRequest, send_request) def release(): runtime.free_str(path_ptr) diff --git a/src/viam/version_metadata.py b/src/viam/version_metadata.py new file mode 100644 index 000000000..2d71c7aab --- /dev/null +++ b/src/viam/version_metadata.py @@ -0,0 +1,4 @@ +import viam + +API_VERSION = "0.1.327" +SDK_VERSION = viam.__version__