Skip to content

feat: wire minimal telemetry into emissions tracker#1200

Open
davidberenstein1957 wants to merge 29 commits into
masterfrom
feat/add-telemetry
Open

feat: wire minimal telemetry into emissions tracker#1200
davidberenstein1957 wants to merge 29 commits into
masterfrom
feat/add-telemetry

Conversation

@davidberenstein1957

Copy link
Copy Markdown
Collaborator

Summary

  • Adds tracker-facing minimal telemetry on top of the shared TelemetryClient / TelemetryCreate stack from feat: first version of telemetry #1171
  • Wires send_telemetry (opt-out, default on) into BaseEmissionsTracker and OfflineEmissionsTracker with once-per-session deduplication
  • Maps tracker conf to 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 before master.

Test plan

  • uv run pytest tests/test_telemetry.py tests/test_telemetry_client.py
  • Run carbonserver telemetry API tests after DB migration exists
  • Manual smoke: start EmissionsTracker(send_telemetry=True) and confirm POST /telemetry returns 201 against local API

Made with Cursor

davidberenstein1957 and others added 8 commits April 29, 2026 19:44
- 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>
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>
@davidberenstein1957 davidberenstein1957 requested a review from a team as a code owner May 19, 2026 18:01
@codecov

codecov Bot commented May 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.55556% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.85%. Comparing base (58acafa) to head (2145b61).

Files with missing lines Patch % Lines
codecarbon/core/telemetry/collect.py 89.53% 18 Missing ⚠️
codecarbon/cli/telemetry_cli.py 98.18% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1200      +/-   ##
==========================================
+ Coverage   89.17%   89.85%   +0.67%     
==========================================
  Files          47       52       +5     
  Lines        4510     4917     +407     
==========================================
+ Hits         4022     4418     +396     
- Misses        488      499      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…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.
Comment thread codecarbon/cli/telemetry_cli.py Outdated
Base automatically changed from feat/telemetry-backend to master June 7, 2026 08:37
@davidberenstein1957 davidberenstein1957 linked an issue Jun 9, 2026 that may be closed by this pull request
Integrate latest master (refactored EmissionsTracker init, output methods,
carbon intensity parsing) while preserving the telemetry package, CLI, docs,
and tracker stop-time telemetry wiring.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread codecarbon/core/telemetry/settings.py Fixed
davidberenstein1957 and others added 2 commits June 15, 2026 19:47
Match minimal/extensive tier contracts to carbonserver DB fields, split payload
building by tier, and trim redundant tracker state and docstrings after ponytail
pass. Update docs and tests to drop Tier 1/2 jargon.

Co-authored-by: Cursor <cursoragent@cursor.com>
Fix isort and black on collect tests after local pre-commit run.

Co-authored-by: Cursor <cursoragent@cursor.com>
Resolve api key resolution after tier logging to avoid clear-text secret
taint, drop debug logging of telemetry request bodies, and add tests for
client error paths, schema validation, and collect environment probes.

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread codecarbon/core/telemetry/settings.py Fixed
davidberenstein1957 and others added 3 commits June 17, 2026 17:47
Co-authored-by: Cursor <cursoragent@cursor.com>
…f sensitive information'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@davidberenstein1957

Copy link
Copy Markdown
Collaborator Author

@inimaz, before merging, we should still add the hardcoded experiment and project for the codecarbon api.

Add CLI helper and interactive-flow tests, cover coordinate rounding in
ApiClient, and extend collect environment probes to satisfy Codecov patch
and project thresholds on PR #1200.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

Add internal and public telemetry

4 participants