-
Notifications
You must be signed in to change notification settings - Fork 20
Add usage analytics tracking #106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f7dd018
7528d9b
7c5b26d
b577b3f
0086416
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
from tabpfn_client.constants import CACHE_DIR | ||
from tabpfn_client.browser_auth import BrowserAuthHandler | ||
from tabpfn_client.tabpfn_common_utils.utils import Singleton | ||
from tabpfn_client.tabpfn_common_utils.usage_analytics import AnalyticsHttpClient | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -157,15 +158,20 @@ class ServiceClient(Singleton): | |
httpx_timeout_s = ( | ||
4 * 5 * 60 + 15 # temporary workaround for slow computation on server side | ||
) | ||
httpx_client = httpx.Client( | ||
httpx_client = AnalyticsHttpClient( | ||
Jabb0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
base_url=base_url, | ||
timeout=httpx_timeout_s, | ||
headers={"client-version": get_client_version()}, | ||
module_name="tabpfn_client", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure there is no way of getting the module name programmatically? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least not robustly, in my opinion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I was hoping there is a better way to get the module name than iterating the call stack. |
||
) | ||
|
||
_access_token = None | ||
dataset_uid_cache_manager = DatasetUIDCacheManager() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be private btw. |
||
|
||
@classmethod | ||
def set_module_name(cls, module_name: str) -> None: | ||
cls.httpx_client.set_module_name(module_name) | ||
|
||
@classmethod | ||
def get_access_token(cls): | ||
return cls._access_token | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,10 @@ def __new__(cls, *args, **kwargs): | |
use_server = False | ||
|
||
|
||
def init(use_server=True): | ||
def init( | ||
use_server=True, | ||
module_name="tabpfn_client", | ||
): | ||
# initialize config | ||
Config.use_server = use_server | ||
|
||
|
@@ -30,6 +33,8 @@ def init(use_server=True): | |
return | ||
|
||
if use_server: | ||
ServiceClient.set_module_name(module_name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are not expecting this to change during service run. It should be ONLY in the constructor of ServiceClient and then stored as a private member. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ServiceClient is a singleton class, hence we don't have an constructor as per say. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be. Singletons are to be handled with cautions, because as for global variables, they can be changed in multiple places and thus introduce side-effects. Also they are harder to test, because dependency injection does not work. I'd need to think more about this here. But one way would be to create a client instance. And then this instance needs to be passed when calls are made. |
||
|
||
# check connection to server | ||
if not UserAuthenticationClient.is_accessible_connection(): | ||
raise RuntimeError( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests missing.