Skip to content

feat: add SDK telemetry into emissions tracker - #1200

Open
davidberenstein1957 wants to merge 1 commit into
masterfrom
feat/add-telemetry
Open

feat: add SDK telemetry into emissions tracker#1200
davidberenstein1957 wants to merge 1 commit 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
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 92.46575% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.69%. Comparing base (3ec31a0) to head (fd7a63b).

Files with missing lines Patch % Lines
codecarbon/core/telemetry/collect.py 88.05% 19 Missing ⚠️
codecarbon/core/telemetry/dispatcher.py 90.47% 4 Missing ⚠️
codecarbon/core/api_client.py 75.00% 3 Missing ⚠️
codecarbon/core/telemetry/settings.py 92.10% 3 Missing ⚠️
codecarbon/cli/telemetry_cli.py 98.14% 2 Missing ⚠️
codecarbon/core/telemetry/client.py 95.65% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1200      +/-   ##
==========================================
+ Coverage   91.43%   91.69%   +0.25%     
==========================================
  Files          49       54       +5     
  Lines        5057     5452     +395     
==========================================
+ Hits         4624     4999     +375     
- Misses        433      453      +20     

☔ 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.

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
Comment thread codecarbon/core/telemetry/settings.py Fixed
Comment thread codecarbon/core/telemetry/settings.py Fixed
@davidberenstein1957

Copy link
Copy Markdown
Collaborator Author

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

davidberenstein1957 added a commit that referenced this pull request Jun 17, 2026
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>
@davidberenstein1957 davidberenstein1957 changed the title feat: wire minimal telemetry into emissions tracker feat: add SDK telemetry into emissions tracker Jul 18, 2026
Comment thread codecarbon/emissions_tracker.py
Comment thread .gitignore Outdated
.codecarbon.config*
scripts/agent-vm.personal.config.sh

# Added by ggshield

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe this is not needed as discussed

@inimaz inimaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this PR @davidberenstein1957 . I have left some comments

raise typer.BadParameter(str(error)) from error


def resolve_config_path(config: Optional[Path], *, create: bool = False) -> Path:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe this is not needed. get_hierarchical_config handles it?

Comment thread codecarbon/emissions_tracker.py Outdated

# logger.info("base tracker init")
self._external_conf = get_hierarchical_config()
self._config_file_conf = get_config_file_settings()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not needed

Suggested change
self._config_file_conf = get_config_file_settings()

project_token_service: ProjectTokenService = Depends(
Provide[ServerContainer.project_token_service]
),
x_api_token: str = Header(None),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

does this work? Should it not be x_api_token: str = Header(None, alias="x-api-token")?

),
x_api_token: str = Header(None),
) -> UUID:
project_token_service.project_token_has_access(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

you are not doing anything with the response here, it should be if allowed--> do the action n?

Comment thread codecarbon/core/telemetry/collect.py Outdated
return importlib.util.find_spec(name) is not None


def _round_coordinate(value: Any) -> float | None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

maybe reuse the same function of _round_coordinate ApiClient so that both return the same if None.

Send product telemetry at tracker stop, with the tier resolved from
config, environment, or the EmissionsTracker(telemetry_level=...) kwarg.

The send runs on a daemon thread so stop() never blocks on the network,
and every request of one send shares a single 2s wall-clock budget, so
the extensive tier cannot cost more just because it makes two calls.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add internal and public telemetry

4 participants