feat: wire minimal telemetry into emissions tracker#1200
Open
davidberenstein1957 wants to merge 19 commits into
Open
feat: wire minimal telemetry into emissions tracker#1200davidberenstein1957 wants to merge 19 commits into
davidberenstein1957 wants to merge 19 commits into
Conversation
- Move hardcoded TELEMETRY_API_KEY to environment variable with fallback - Add comment clarifying it's a public key with limited permissions - Add module docstring describing Tier 1 and Tier 2 telemetry - Improve type hints on collect_tier1_payload (dict[str, Any]) - Remove unused 'import sys' from test_telemetry.py - Convert test from function-based to class-based unittest.TestCase style - All tests passing
- Implement send_tier1_telemetry() function that POSTs environment metadata to the telemetry API once per session - Module-level _TIER1_SENT flag ensures deduplication (returns False on duplicate calls within same session) - Silent failure handling: catches all exceptions, logs error, returns False - Tests verify: deduplication prevents multiple POSTs, exceptions are caught and logged without being raised Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…nd_telemetry=False)
Align Tier 1 send path with PR #1171 schemas and HTTP 201 contract while keeping session dedup and emissions tracker opt-out wiring. Co-authored-by: Cursor <cursoragent@cursor.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## feat/telemetry-backend #1200 +/- ##
==========================================================
- Coverage 88.98% 88.00% -0.98%
==========================================================
Files 47 52 +5
Lines 4411 4826 +415
==========================================================
+ Hits 3925 4247 +322
- Misses 486 579 +93 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ved session handling - Introduced `build_minimal_telemetry_dict` to create a minimal telemetry payload from tracker configuration. - Updated `send_tier1_telemetry` to utilize the new payload builder and handle optional API endpoint URLs. - Refactored tests to validate the new telemetry structure and ensure deduplication logic remains intact. - Improved error handling and logging for telemetry sending failures.
…ion handling - Added support for telemetry level configuration via `.codecarbon.config`, allowing users to specify tiers (disabled, minimal, extensive). - Introduced `get_config_file_settings` to read configuration settings from global and local files. - Updated `BaseEmissionsTracker` to utilize the new telemetry level parameter, improving flexibility in telemetry data collection. - Refactored telemetry sending methods to handle new configurations and ensure proper logging and error handling. - Enhanced tests to cover new telemetry configurations and ensure correct behavior across different scenarios.
- Updated `resolve_telemetry_level` to incorporate external configuration, allowing for more flexible telemetry tier resolution. - Improved handling of telemetry level overrides from environment variables and configuration files. - Enhanced documentation to clarify telemetry configuration options and resolution order. - Added tests to validate new behavior for telemetry level resolution and ensure correct precedence of settings.
- Updated warning message for amdsmi configuration issues to provide clearer guidance on potential causes and solutions. - Adjusted test to reflect the new warning message format, ensuring accurate validation of GPU import warnings.
- Added new fields to the TelemetryBase schema, including `on_cloud`, `python_package_manager`, `integration_surface`, `offline_mode`, and `save_to_api_enabled`. - Updated MINIMAL_TELEMETRY_FIELDS to include new fields for improved telemetry data collection. - Refactored telemetry sending methods to utilize the new schema and ensure accurate data transmission. - Enhanced tests to validate the new telemetry fields and their integration into the existing telemetry framework.
- Replaced MINIMAL_TELEMETRY_FIELDS with a dynamic frozenset that excludes privacy-related fields. - Introduced EXCLUDED_PRIVACY_TELEMETRY_FIELDS to ensure sensitive data is not collected. - Updated telemetry payload building methods to accept a telemetry level parameter, allowing for more flexible data handling. - Enhanced tests to validate the acceptance of framework versions and rejection of privacy fields in telemetry submissions. - Improved documentation to clarify the changes in telemetry data collection and privacy considerations.
- Removed sensitive fields from the TelemetryBase schema, including `longitude`, `latitude`, and `python_executable_hash`. - Consolidated privacy-related field management into a single frozenset, `PRIVATE_TELEMETRY_FIELDS`. - Updated telemetry payload building methods to reflect the new schema and ensure compliance with privacy standards. - Refactored tests to validate the rejection of unknown fields and ensure proper handling of telemetry submissions. - Improved documentation to clarify the changes in telemetry data collection and privacy considerations.
- Removed version tracking for ML frameworks from telemetry payload to improve privacy. - Updated the framework packages list to exclude version fields, focusing solely on presence flags. - Adjusted telemetry context collection to reflect the changes in framework detection. - Modified tests to ensure the telemetry payload omits framework versions as intended. - Updated documentation to clarify the changes in ML stack data collection.
- Replaced the TelemetryClient class with a standalone function, post_private_telemetry, for sending telemetry data. - Updated telemetry payload construction to improve clarity and maintainability. - Refactored telemetry warning handling to ensure it is shown only once during execution. - Enhanced tests to validate the new telemetry sending method and ensure proper payload structure. - Improved error handling and logging for telemetry requests, including handling of connection errors and HTTP response statuses.
- Replaced the existing telemetry client and settings management with a more modular approach, introducing a dedicated Telemetry class for dispatching telemetry data. - Consolidated telemetry payload construction and validation into a streamlined process, enhancing clarity and maintainability. - Removed deprecated telemetry client and settings files, ensuring a cleaner codebase. - Updated telemetry context collection to improve data accuracy and privacy compliance. - Enhanced tests to validate the new telemetry structure and ensure proper functionality across various scenarios.
- Reorganized imports in emissions_tracker.py for clarity and consistency. - Simplified the definition of CONTAINER_RUNTIME_ENV in collect.py for better readability. - Enhanced formatting in settings.py and various test files to maintain consistent code style. - Updated test cases to improve readability and ensure proper mocking of telemetry functions.
…ment - Added a new telemetry module to handle product telemetry at tracker stop, including necessary imports and payload construction. - Updated tests to ensure proper handling of telemetry levels and error management with the Typer library. - Improved clarity and organization of telemetry-related code for better maintainability.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
TelemetryClient/TelemetryCreatestack from feat: first version of telemetry #1171send_telemetry(opt-out, default on) intoBaseEmissionsTrackerandOfflineEmissionsTrackerwith once-per-session deduplicationconfto the minimal API schema (timestamp,telemetry_level, hardware/geo fields,ram_total_size_gb, etc.)Builds on PR #1171 (
feat/telemetry-backend) — intended to merge into that branch beforemaster.Test plan
uv run pytest tests/test_telemetry.py tests/test_telemetry_client.pyEmissionsTracker(send_telemetry=True)and confirmPOST /telemetryreturns 201 against local APIMade with Cursor