Skip to content

Commit 39d57cc

Browse files
committed
Add optional callback into HTTPClient.request
1 parent 0b859f4 commit 39d57cc

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

cognite/client/_http_client.py

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from cognite.client.config import global_config
1515
from cognite.client.exceptions import CogniteConnectionError, CogniteConnectionRefused, CogniteReadTimeout
16+
from cognite.client.utils._api_usage import RequestDetails
1617

1718

1819
class BlockAll(cookiejar.CookiePolicy):
@@ -114,6 +115,10 @@ def request(self, method: str, url: str, **kwargs: Any) -> requests.Response:
114115
while True:
115116
try:
116117
res = self._do_request(method=method, url=url, **kwargs)
118+
if global_config.usage_tracking_callback:
119+
# We use the RequestDetails as an indirection to avoid the user mutating the request:
120+
global_config.usage_tracking_callback(RequestDetails.from_response(res))
121+
117122
last_status = res.status_code
118123
retry_tracker.status += 1
119124
if not retry_tracker.should_retry(status_code=last_status):

0 commit comments

Comments
 (0)