-
Notifications
You must be signed in to change notification settings - Fork 1
Add telemetry support #144
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
Merged
+580
−479
Merged
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e300bb4
update formatting
anvacaru 3487f19
emit events when installing packages
anvacaru 1c7a716
remove print stmt
anvacaru dd3e233
Merge remote-tracking branch 'origin/master' into kup-telemetry
anvacaru df770f5
update telemetry script
anvacaru 5cb8514
revert formatting
anvacaru 8da0e56
review suggestions
anvacaru 9f69291
[DO NOT MERGE] bump python verison
anvacaru 70aad59
[DO NOT MERGE] bump python in flake.nix to 3.11
anvacaru ff657a7
revert tomli version to 2.0.1
anvacaru 92efe54
Revert "[DO NOT MERGE] bump python in flake.nix to 3.11"
anvacaru c571459
Revert "[DO NOT MERGE] bump python verison"
anvacaru 662ba7f
Merge remote-tracking branch 'origin/master' into kup-telemetry
anvacaru 68282ad
bump version 0.2.5 -> 0.2.6
anvacaru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import os | ||
| import uuid | ||
| from pathlib import Path | ||
| from typing import Final | ||
|
|
||
| import requests | ||
| import tomli | ||
| import tomli_w | ||
|
|
||
| _LOGGER: Final = logging.getLogger(__name__) | ||
|
|
||
| KPROFILE_CONFIG_DIR: Final = Path.home() / '.config' / 'kprofile' | ||
| KPROFILE_CONFIG_FILE: Final = KPROFILE_CONFIG_DIR / 'config.toml' | ||
| TELEMETRY_MESSAGE: Final = f'Telemetry: sending anonymous usage data. You can opt out by setting KPROFILE_TELEMETRY_DISABLED=true or consent=false in {KPROFILE_CONFIG_FILE}' | ||
|
|
||
|
|
||
| def _get_user_id() -> str: | ||
| """Get or create persistent anonymous user ID""" | ||
| if not KPROFILE_CONFIG_FILE.exists(): | ||
| KPROFILE_CONFIG_FILE.parent.mkdir(parents=True, exist_ok=True) | ||
| config = {'user': {'user_id': str(uuid.uuid4()), 'consent': True}} | ||
| with open(KPROFILE_CONFIG_FILE, 'wb') as f: | ||
| tomli_w.dump(config, f) | ||
| return str(config['user']['user_id']) | ||
|
|
||
| with open(KPROFILE_CONFIG_FILE, 'rb') as f: | ||
| config = tomli.load(f) | ||
|
|
||
| return str(config['user']['user_id']) | ||
|
|
||
|
|
||
| def _has_permission() -> bool: | ||
| """Check if telemetry is enabled""" | ||
| if os.getenv('KPROFILE_TELEMETRY_DISABLED', '').lower() == 'true': | ||
| return False | ||
|
|
||
| _get_user_id() | ||
|
|
||
| with open(KPROFILE_CONFIG_FILE, 'rb') as f: | ||
| config = tomli.load(f) | ||
|
|
||
| return config.get('user', {}).get('consent', True) | ||
|
|
||
|
|
||
| def _emit_event(event: str, properties: dict | None = None) -> None: | ||
| """Send telemetry event to proxy server""" | ||
| if not _has_permission(): | ||
| return | ||
|
|
||
| _LOGGER.info(TELEMETRY_MESSAGE) | ||
|
|
||
| try: | ||
| requests.post( | ||
| 'https://ojlk1fzi13.execute-api.us-east-1.amazonaws.com/dev/track', | ||
| json={'user_id': _get_user_id(), 'event': event, 'properties': properties}, | ||
| timeout=2, | ||
| ) | ||
| except Exception: | ||
| pass # Fail silently | ||
juliankuners marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.