Skip to content
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

Rework telemetry to support installation_id #2480

Merged
merged 5 commits into from Jan 31, 2024
Merged

Conversation

jackie-pc
Copy link
Contributor

No description provided.

@jackie-pc jackie-pc marked this pull request as ready for review January 29, 2024 19:42
@jackie-pc jackie-pc requested review from picklelo, masenf and Alek99 and removed request for picklelo and masenf January 29, 2024 19:42
reflex/reflex.py Outdated
@@ -80,6 +81,10 @@ def _init(

prerequisites.check_latest_package_version(constants.Reflex.MODULE_NAME)

prerequisites.initialize_reflex_user_directory()

ensure_reflex_distinct_id()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this just go inside of initialize_reflex_user_directory to keep everything in the prerequisites file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is in the prerequisite file. Removed the separate import. It will say prerequisites.ensure_reflex_distinct_id() now.

"""Ensures that a reflex distinct id has been generated and stored in the reflex directory.

Returns:
Distinct id (int).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't need to annotate return types since we use annotations

Distinct id (int).
"""
initialize_reflex_user_directory()
distinct_id_file = os.path.join(constants.Reflex.DIR, "distinct_id")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call the file reflex.json to match how we do it in the .web folder, we can reuse the file parsing/writing functions for it too then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't really any existing logic, it's all raw json.loads into dictionary, etc.

The reason I was leaning to a flat, single purpose file is for simplicity. Without any further things to be stashed, it would be better to keep it minimal.

We can discuss the naming further - we can finalize a name on Discord and just update it to that.

@jackie-pc jackie-pc changed the title Rework telemetry to have distinct_id AND distinct_app_id Rework telemetry to support installation_id Jan 29, 2024
picklelo
picklelo previously approved these changes Jan 30, 2024
pass

if installation_id is None:
installation_id = random.getrandbits(128)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use uuid4 instead of random bits in both places?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with what was there already. It seems acceptable for our purpose. What would drive us to change it to uuid?

@@ -80,6 +80,10 @@ def _init(

prerequisites.check_latest_package_version(constants.Reflex.MODULE_NAME)

prerequisites.initialize_reflex_user_directory()

prerequisites.ensure_reflex_installation_id()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we do this, even if the user has disabled telemetry? my thought is TELEMETRY_DISABLED=1 and we don't generate a marker file at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, project_hash has exactly the same nature - it is only used for telemetry, and yet we always generate it even if TELEMETRY_DISABLED=1. I.e. we persist something, but we just never send out.

Checking for the flag costs some incremental complexity. Note even if we did do it, it would not be clean. Suppose telemetry was only disabled after initial use. The file would have already been created.

Don't really feel strongly either way about it - if others do, of course we can just add the check!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can keep the file, as long as we never send the data when the flag is enabled

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ensure_reflex_installation_id already calls initialize_reflex_user_directory() do we need both calls? that's what I was thinking originally - just calling ensure_reflex_installation_id at the end of initialize_ every time

Comment on lines 851 to 852
with open(installation_id_file, "w") as f:
f.write(str(installation_id))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we cannot write out the file for some reason, i don't think reflex should just raise an exception and exit, that seems like a potentially poor UX

Copy link
Contributor Author

@jackie-pc jackie-pc Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AGREE that this is not supposed to be a UX at all.

From this viewpoint, the most we should do is perhaps catch exception and add a console.log.debug.

@@ -80,6 +80,10 @@ def _init(

prerequisites.check_latest_package_version(constants.Reflex.MODULE_NAME)

prerequisites.initialize_reflex_user_directory()

prerequisites.ensure_reflex_installation_id()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ensure_reflex_installation_id already calls initialize_reflex_user_directory() do we need both calls? that's what I was thinking originally - just calling ensure_reflex_installation_id at the end of initialize_ every time

@picklelo picklelo merged commit 80c9eb3 into main Jan 31, 2024
44 of 45 checks passed
@masenf masenf deleted the jackie-distinct-id branch February 8, 2024 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants