Skip to content

feat(cli): track CLI usage via ConnectionConfig integration header#1517

Draft
mishushakov wants to merge 3 commits into
mainfrom
mishushakov/cli-usage-tracking
Draft

feat(cli): track CLI usage via ConnectionConfig integration header#1517
mishushakov wants to merge 3 commits into
mainfrom
mishushakov/cli-usage-tracking

Conversation

@mishushakov

@mishushakov mishushakov commented Jun 30, 2026

Copy link
Copy Markdown
Member

Tags all CLI traffic to the API with an e2b-cli/<version> identifier in the User-Agent header so CLI usage and version distribution can be tracked server-side, with no SDK changes and no new dependencies.

The first commit tagged the shared ConnectionConfig, but the auth, sandbox-lifecycle, and template build commands build their own connection from per-call options and were still sending untagged requests (flagged by Cursor Bugbot + Codex). This adds a withCliIntegration helper (and a CLI_INTEGRATION constant) in packages/cli/src/api.ts and threads it through every remaining call site: auth login/configure, sandbox create/connect/resume/kill/pause/list/info/metrics/exec, and template build.

integration is accepted at runtime by every ConnectionConfig the SDK builds internally, but isn't part of the narrower option types the Sandbox.*/Template.* static methods declare — the helper centralizes that single cast so the call sites stay clean. Direct new ConnectionConfig(...) sites (auth) pass integration inline since the constructor's type already declares it.

Usage

$ e2b sandbox create my-template
$ e2b sandbox list
$ e2b auth login
$ e2b template build
# Every request now sends:  User-Agent: e2b-js-sdk/<sdk-version> e2b-cli/<cli-version>

Server-side, filter API logs by User-Agent containing e2b-cli/ to measure CLI vs SDK traffic and version distribution, broken down by team/user via the existing auth headers.

Tests

  • api_integration_header.test.ts covers CLI_INTEGRATION, the module-level config, and the withCliIntegration helper.
  • create_lifecycle.test.ts now asserts Sandbox.create is called with the integration field, locking in the threading as a regression guard.

🤖 Generated with Claude Code

Set the `integration` field on the CLI's ConnectionConfig so every API
request carries `e2b-cli/<version>` in the User-Agent header, enabling
CLI usage and version distribution to be tracked server-side.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cursor

cursor Bot commented Jun 30, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Observability-only header changes with no auth or business-logic changes; template builds are deliberately excluded to avoid known backend rejection.

Overview
Adds CLI_INTEGRATION (e2b-cli/<version>) and a withCliIntegration helper so the SDK’s User-Agent identifies CLI traffic for server-side analytics.

The shared connectionConfig and one-off auth ConnectionConfig instances (login, configure) now set integration. Every Sandbox.* call site that passes its own options—create, connect, resume, kill, pause, list, info, metrics, exec, and shared helpers like isRunning—wraps those options with withCliIntegration.

Template.build is explicitly left untagged (documented in code) because the template build backend rejects the custom User-Agent. New api_integration_header tests cover the constant, headers, and helper; sandbox tests assert integration is passed through to Sandbox.create.

Reviewed by Cursor Bugbot for commit 0e21abf. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d7d102c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@e2b/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from f0359fb. Download artifacts from this workflow run.

JS SDK (e2b@2.31.1-mishushakov-cli-usage-tracking.0):

npm install ./e2b-2.31.1-mishushakov-cli-usage-tracking.0.tgz

CLI (@e2b/cli@2.13.1-mishushakov-cli-usage-tracking.0):

npm install ./e2b-cli-2.13.1-mishushakov-cli-usage-tracking.0.tgz

Python SDK (e2b==2.30.0+mishushakov-cli-usage-tracking):

pip install ./e2b-2.30.0+mishushakov.cli.usage.tracking-py3-none-any.whl

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6d408b1. Configure here.

Comment thread packages/cli/src/api.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6d408b15d8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/cli/src/api.ts Outdated
Comment thread packages/cli/src/api.ts Outdated
The single tagged ConnectionConfig only covered requests routed through the
shared API client. Auth, sandbox lifecycle (create/connect/resume/kill/
pause/list/info/metrics/exec) and `template build` commands build their own
connection from per-call options and were sending untagged requests.

Add a `withCliIntegration` helper (and `CLI_INTEGRATION` constant) and thread
it through every such call site so all CLI traffic carries `e2b-cli/<version>`
in the User-Agent. No SDK changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mishushakov mishushakov requested a review from huv1k July 1, 2026 10:26
@mishushakov mishushakov force-pushed the mishushakov/cli-usage-tracking branch from 0e21abf to d7d102c Compare July 1, 2026 10:43
@mishushakov

Copy link
Copy Markdown
Member Author

waiting until the backend team enables integration header on the backend

@mishushakov mishushakov marked this pull request as draft July 1, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant