-
Notifications
You must be signed in to change notification settings - Fork 162
Upstream anonymous telemetry module #4909
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
automergerpr-permission-manager
merged 5 commits into
develop
from
anvacaru/telemetry-2
Apr 10, 2026
+545
−425
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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,63 @@ | ||
| 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' | ||
| f' or by setting consent=false in {KPROFILE_CONFIG_FILE}' | ||
| ) | ||
|
|
||
|
|
||
| def _load_config() -> tuple[str, bool]: | ||
|
anvacaru marked this conversation as resolved.
Outdated
|
||
| """Load or create the kprofile config, returning (user_id, consent).""" | ||
| 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) | ||
| print(TELEMETRY_MESSAGE) | ||
| return str(config['user']['user_id']), True | ||
|
|
||
| with open(KPROFILE_CONFIG_FILE, 'rb') as f: | ||
| config = tomli.load(f) | ||
|
|
||
| user = config.get('user', {}) | ||
| return str(user['user_id']), bool(user.get('consent', True)) | ||
|
|
||
|
|
||
| def emit_event(event: str, properties: dict | None = None) -> None: | ||
| """Send a telemetry event to the proxy server. | ||
|
|
||
| Args: | ||
| event: Event name to track. | ||
| properties: Optional key/value metadata (e.g. ``{'version': '1.2.3'}``). | ||
| """ | ||
| if os.getenv('KPROFILE_TELEMETRY_DISABLED', '').lower() == 'true': | ||
|
anvacaru marked this conversation as resolved.
Outdated
|
||
| return | ||
|
|
||
| user_id, consent = _load_config() | ||
| if not consent: | ||
| return | ||
|
|
||
| try: | ||
| requests.post( | ||
| 'https://ojlk1fzi13.execute-api.us-east-1.amazonaws.com/dev/track', | ||
|
anvacaru marked this conversation as resolved.
Outdated
|
||
| json={'user_id': user_id, 'event': event, 'properties': properties or {}}, | ||
| timeout=2, | ||
| ) | ||
| except requests.exceptions.ReadTimeout: | ||
| _LOGGER.debug(f'Telemetry event timed out: {event}') | ||
| except Exception as e: | ||
| _LOGGER.warning(f'Telemetry event failed: {event}', exc_info=e) | ||
Oops, something went wrong.
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.