Skip to content

Commit

Permalink
Make x-xata-agent consistent with ts libary (#181)
Browse files Browse the repository at this point in the history
* x-xata-agent consistent with ts libary

* Fixed tests

* Added comment explaining format

* fixed helpers.py

* align helper telemetry params

---------

Co-authored-by: Philip Krauss <[email protected]>
  • Loading branch information
richardgill and philkra authored Nov 9, 2023
1 parent 3c2c10b commit 455dee3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/unit-tests/client_telemetry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_telemetry_headers(self):
assert utils.PATTERNS_UUID4.match(headers1["x-xata-session-id"])
assert headers1["x-xata-client-id"] != headers1["x-xata-session-id"]
assert "x-xata-agent" in headers1
assert headers1["x-xata-agent"] == f"client=PY_SDK;version={__version__};"
assert headers1["x-xata-agent"] == f"client=PY_SDK; version={__version__}"

api_key = "this-key-42"
client2 = XataClient(api_key=api_key, workspace_id="ws_id")
Expand Down
3 changes: 2 additions & 1 deletion xata/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ def __init__(
"connection": "keep-alive",
"x-xata-client-id": str(uuid.uuid4()),
"x-xata-session-id": str(uuid.uuid4()),
"x-xata-agent": f"client=PY_SDK;version={__version__};",
# the format is key1=value; key2=value (with spaces and no trailing ;)
"x-xata-agent": f"client=PY_SDK; version={__version__}",
}

# init namespaces
Expand Down
4 changes: 2 additions & 2 deletions xata/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(
raise Exception("batch size can not be less than one, default: %d" % BP_DEFAULT_BATCH_SIZE)

self.client = client
telemetry = "%shelper=bp;v=%s" % (self.client.get_headers()["x-xata-agent"], BP_VERSION)
telemetry = "%s; helper=bp:%s" % (self.client.get_headers()["x-xata-agent"], BP_VERSION)
self.client.set_header("x-xata-agent", telemetry)

self.processing_timeout = processing_timeout
Expand Down Expand Up @@ -321,7 +321,7 @@ def __init__(
:param client: XataClient
"""
self.client = client
telemetry = "%shelper=trx;v=%s" % (self.client.get_headers()["x-xata-agent"], TRX_VERSION)
telemetry = "%s; helper=trx:%s" % (self.client.get_headers()["x-xata-agent"], TRX_VERSION)
self.client.set_header("x-xata-agent", telemetry)
self.logger = logging.getLogger(f"{__name__}.{self.__class__.__name__}")

Expand Down

0 comments on commit 455dee3

Please sign in to comment.