From 56bc3d537d3fabce6298ea02da1da45d0dd260e8 Mon Sep 17 00:00:00 2001 From: Tobias McVey Date: Thu, 5 Dec 2024 09:45:38 +0100 Subject: [PATCH 1/7] improved logging for cohort api --- src/amplitude_data_wrapper/analytics_api.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/amplitude_data_wrapper/analytics_api.py b/src/amplitude_data_wrapper/analytics_api.py index 304c576..c385a3d 100644 --- a/src/amplitude_data_wrapper/analytics_api.py +++ b/src/amplitude_data_wrapper/analytics_api.py @@ -148,9 +148,8 @@ def get_cohort( ) response.raise_for_status() json_response = response.json() - print("JSON Response") for key, value in json_response.items(): - print(key, ":", value, "\n") + logging.info("%s : %s", key, value) header_status = 0 request_id = json_response["request_id"] while header_status != 200: @@ -165,15 +164,11 @@ def get_cohort( status_response.raise_for_status() if status_response.status_code == 202: - print(f"Waiting for {request_id} to be completed. Current status:") - print(f"{status_response.headers}") - json_status = status_response.json() - for key, value in json_status.items(): - print(key, ":", value, "\n") + logging.info("Waiting for request_id %s to be completed", request_id) time.sleep(5) elif status_response.status_code == 200: download_url = f"{url[region]}/api/5/cohorts/request/{request_id}/file" - print(f"Downloading from {download_url}") + logging.info("Downloading from %s", download_url) file_download = s.get( download_url, headers=headers, @@ -183,7 +178,6 @@ def get_cohort( proxies=proxy, ) file_download.raise_for_status() - print(f"{file_download.headers}") with tqdm.wrapattr( open(filename, "wb"), "write", @@ -191,12 +185,11 @@ def get_cohort( total=int(file_download.headers.get("content-length", 0)), desc=filename, ) as fout: - print(file_download.headers) for chunk in file_download.iter_content(chunk_size=8192): fout.write(chunk) header_status = 200 else: - print( + logging.ERROR( f"An error occurred, retrying to reach request ID {request_id} and request URL {download_url} in 10 seconds" ) time.sleep(10) From 90e2e8d78d8c114ee7fc39dfeaf7a02f26480901 Mon Sep 17 00:00:00 2001 From: Tobias McVey Date: Thu, 5 Dec 2024 09:50:39 +0100 Subject: [PATCH 2/7] improved logging for export api --- src/amplitude_data_wrapper/analytics_api.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/amplitude_data_wrapper/analytics_api.py b/src/amplitude_data_wrapper/analytics_api.py index c385a3d..a5dbbcb 100644 --- a/src/amplitude_data_wrapper/analytics_api.py +++ b/src/amplitude_data_wrapper/analytics_api.py @@ -356,25 +356,19 @@ def export_project_data( stream=True, proxies=proxy, ) - print(f"Export request submitted") + logging.info("Export request submitted") response.raise_for_status() header_status = 0 while header_status != 200: - print(f"Waiting for response") + logging.info("Waiting for response") if response.status_code == 400: - print( - f"The file size of the exported data is too large. Shorten the time ranges and try again. The limit size is 4GB." - ) + logging.info("The file size of the exported data is too large. Shorten the time ranges and try again. The limit size is 4GB.") elif response.status_code == 404: - print( - f"Request data for a time range during which no data has been collected for the project, then you will receive a 404 response from our server." - ) + logging.info("Request data for a time range during which no data has been collected for the project, then you will receive a 404 response from our server.") elif response.status_code == 504: - print( - f"The amount of data is large causing a timeout. For large amounts of data, the Amazon S3 destination is recommended." - ) + logging.info("The amount of data is large causing a timeout. For large amounts of data, the Amazon S3 destination is recommended.") elif response.status_code == 200: - print(f"Success. downloading file as {filename}") + logging.info("Success. Downloading file as %s", filename) with tqdm.wrapattr( open(filename, "wb"), "write", @@ -382,12 +376,11 @@ def export_project_data( total=int(response.headers.get("content-length", 0)), desc=filename, ) as fout: - print(response.headers) for chunk in response.iter_content(chunk_size=8192): fout.write(chunk) header_status = 200 else: - print(f"Some other error occurred. Retrying again in 10 seconds.") + logging.ERROR("Some other error occurred. Retrying again in 10 seconds.") time.sleep(10) return filename From 582ffba8f59542b3890db6029724ccc4a3cf6ba3 Mon Sep 17 00:00:00 2001 From: Tobias McVey Date: Thu, 5 Dec 2024 09:51:28 +0100 Subject: [PATCH 3/7] improved logging for deletion api --- src/amplitude_data_wrapper/analytics_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/amplitude_data_wrapper/analytics_api.py b/src/amplitude_data_wrapper/analytics_api.py index a5dbbcb..5010a9d 100644 --- a/src/amplitude_data_wrapper/analytics_api.py +++ b/src/amplitude_data_wrapper/analytics_api.py @@ -254,7 +254,7 @@ def delete_user_data( auth=(api_key, secret), proxies=proxy, ) - print(f"Sletter brukere") + logging.info("Sletter brukere") return r From 2fda7cfdc16893e0d956d91f4d7194c8ceccfabe Mon Sep 17 00:00:00 2001 From: Tobias McVey Date: Thu, 5 Dec 2024 09:53:25 +0100 Subject: [PATCH 4/7] better logging for chart api and user search api --- src/amplitude_data_wrapper/analytics_api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/amplitude_data_wrapper/analytics_api.py b/src/amplitude_data_wrapper/analytics_api.py index 5010a9d..d3d47ab 100644 --- a/src/amplitude_data_wrapper/analytics_api.py +++ b/src/amplitude_data_wrapper/analytics_api.py @@ -51,6 +51,7 @@ def get_chart( auth=(api_key, secret), proxies=proxy, ) + logging.info("Success. Retrieved data for chart_id %s", chart_id) return r @@ -91,6 +92,7 @@ def find_user( auth=(api_key, secret), proxies=proxy, ) + logging.info("Success. Found user %s", user) return r From 761c1be2b5ff0fe6593632e4c0ec49ce19b8edcf Mon Sep 17 00:00:00 2001 From: Tobias McVey Date: Thu, 5 Dec 2024 09:53:59 +0100 Subject: [PATCH 5/7] increment version number of package --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b7a57b5..b38b948 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "amplitude-data-wrapper" -version = "0.5.1" +version = "0.5.2" description = "python wrapper for using the amplitude analytics and taxonomy APIs" authors = [ {name = "Tobias McVey", email = "tobias.mcvey@nav.no"}, From cde35b8903634cb2598cc66bc623d92256789fec Mon Sep 17 00:00:00 2001 From: Tobias McVey Date: Thu, 5 Dec 2024 09:54:35 +0100 Subject: [PATCH 6/7] update dev dependencies --- requirements/dev.txt | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 4987eed..48b1eb0 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -6,7 +6,7 @@ # appnope==0.1.4 # via ipykernel -asttokens==2.4.1 +asttokens==3.0.0 # via stack-data backports-tarfile==1.2.0 # via jaraco-context @@ -37,12 +37,10 @@ executing==2.1.0 idna==3.10 # via requests importlib-metadata==8.5.0 - # via - # keyring - # twine + # via keyring ipykernel==6.29.5 # via amplitude-data-wrapper (pyproject.toml) -ipython==8.29.0 +ipython==8.30.0 # via ipykernel isort==5.13.2 # via amplitude-data-wrapper (pyproject.toml) @@ -84,13 +82,14 @@ mypy-extensions==1.0.0 # mypy nest-asyncio==1.6.0 # via ipykernel -nh3==0.2.18 +nh3==0.2.19 # via readme-renderer packaging==24.2 # via # black # build # ipykernel + # twine parso==0.8.4 # via jedi pathspec==0.12.1 @@ -99,7 +98,7 @@ pexpect==4.9.0 # via ipython pip-tools==7.4.1 # via amplitude-data-wrapper (pyproject.toml) -pkginfo==1.10.0 +pkginfo==1.12.0 # via twine platformdirs==4.3.6 # via @@ -143,13 +142,11 @@ rfc3986==2.0.0 # via twine rich==13.9.4 # via twine -six==1.16.0 - # via - # asttokens - # python-dateutil +six==1.17.0 + # via python-dateutil stack-data==0.6.3 # via ipython -tomli==2.1.0 +tomli==2.2.1 # via # black # build @@ -169,7 +166,7 @@ traitlets==5.14.3 # jupyter-client # jupyter-core # matplotlib-inline -twine==5.1.1 +twine==6.0.1 # via amplitude-data-wrapper (pyproject.toml) typing-extensions==4.12.2 # via From b45ebf76ee1d08160df16d3c02a4f297b590fc0c Mon Sep 17 00:00:00 2001 From: Tobias McVey Date: Thu, 5 Dec 2024 09:56:24 +0100 Subject: [PATCH 7/7] use correct error log level --- src/amplitude_data_wrapper/analytics_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/amplitude_data_wrapper/analytics_api.py b/src/amplitude_data_wrapper/analytics_api.py index d3d47ab..9491ee4 100644 --- a/src/amplitude_data_wrapper/analytics_api.py +++ b/src/amplitude_data_wrapper/analytics_api.py @@ -191,7 +191,7 @@ def get_cohort( fout.write(chunk) header_status = 200 else: - logging.ERROR( + logging.error( f"An error occurred, retrying to reach request ID {request_id} and request URL {download_url} in 10 seconds" ) time.sleep(10) @@ -382,7 +382,7 @@ def export_project_data( fout.write(chunk) header_status = 200 else: - logging.ERROR("Some other error occurred. Retrying again in 10 seconds.") + logging.error("Some other error occurred. Retrying again in 10 seconds.") time.sleep(10) return filename