Skip to content

feat(cli): Add Analytic tracking to CLI commands#224

Open
blainekasten wants to merge 1 commit intonextfrom
blaine/dx-183-implement-event-tracking-on-python-cli-for-v2-library2
Open

feat(cli): Add Analytic tracking to CLI commands#224
blainekasten wants to merge 1 commit intonextfrom
blaine/dx-183-implement-event-tracking-on-python-cli-for-v2-library2

Conversation

@blainekasten
Copy link
Contributor

@blainekasten blainekasten commented Jan 27, 2026

This adds analytics to the CLI. Here is an example of logs going through via the --debug flag:

(together) ➜  sites together --debug beta jig list   
[2026-03-19 15:31:48 - together:45 - DEBUG] args="{'command': 'jig list', 'arguments': {}}" event_name=cli_command_started message='Analytics event sending'
[2026-03-19 15:31:48 - together._base_client:484 - DEBUG] Request options: {'method': 'get', 'url': '/deployments', 'headers': {'X-Stainless-Raw-Response': 'raw'}}
[2026-03-19 15:31:48 - together._base_client:999 - DEBUG] Sending HTTP Request: GET https://api.together.xyz/v1/deployments
[2026-03-19 15:31:48 - together:45 - DEBUG] args="{'url': 'https://api.together.xyz/v1/deployments', 'method': 'GET', 'body': ''}" event_name=cli_command_api_request message='Analytics event sending'
[2026-03-19 15:31:48 - httpx:1025 - INFO] HTTP Request: POST https://api.together.ai/together/gateway/pub/v1/httpRequest "HTTP/1.1 200 OK"
[2026-03-19 15:31:48 - httpx:1025 - INFO] HTTP Request: POST https://api.together.ai/together/gateway/pub/v1/httpRequest "HTTP/1.1 200 OK"
[2026-03-19 15:31:48 - httpx:1025 - INFO] HTTP Request: GET https://api.together.xyz/v1/deployments "HTTP/1.1 200 OK"
[2026-03-19 15:31:48 - together._base_client:1037 - DEBUG] HTTP Response: GET https://api.together.xyz/v1/deployments "200 OK" Headers({'date': 'Thu, 19 Mar 2026 20:31:48 GMT', 'content-type': 'application/json; charset=utf-8', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'content-encoding': 'gzip', 'x-trace-id': '20e67c94-8196-44a3-ad5b-5f30811b215d', 'cf-cache-status': 'DYNAMIC', 'strict-transport-security': 'max-age=15552000; includeSubDomains', 'server': 'cloudflare', 'cf-ray': '9def3e286c8da1e5-MSP', 'alt-svc': 'h3=":443"; ma=86400'})
[2026-03-19 15:31:48 - together:45 - DEBUG] args="{'command': 'jig list', 'arguments': {}}" event_name=cli_commmand_completed message='Analytics event sending'
[2026-03-19 15:31:49 - httpx:1025 - INFO] HTTP Request: POST https://api.together.ai/together/gateway/pub/v1/httpRequest "HTTP/1.1 200 OK"

Notably see the lines with event_name in them.

We are currently sending the following events:

  1. cli_command_started for every command start
  2. cli_command_user_aborted if the user aborts the command before it finishes
  3. cli_command_failed if the command fails with any other exception
  4. cli_commmand_completed for successful completions
  5. cli_command_api_request for any api request that is fired within the command

Users can opt out with:

TOGETHER_TELEMETRY_DISABLED=1 or together telemetry disable

together telemetry has the following help output:

Usage: together telemetry [OPTIONS] COMMAND [ARGS]...

  Together collects usage data by default and can be controlled with this
  command, or by setting TOGETHER_TELEMETRY_DISABLED=1

Options:
  --help  Show this message and exit.

Commands:
  disable  Explicitly Disable telemetry
  enable   Enable telemetry
  status   Check to see if telemetry is enabled or disabled.

@blainekasten blainekasten force-pushed the blaine/dx-183-implement-event-tracking-on-python-cli-for-v2-library2 branch 6 times, most recently from a4ad95a to c1e4d5d Compare January 30, 2026 19:09
@stainless-app stainless-app bot force-pushed the next branch 3 times, most recently from bf5b62f to f270535 Compare February 10, 2026 19:02
@blainekasten blainekasten force-pushed the blaine/dx-183-implement-event-tracking-on-python-cli-for-v2-library2 branch 4 times, most recently from d10c649 to 66e6327 Compare February 13, 2026 17:27
@stainless-app stainless-app bot force-pushed the next branch 2 times, most recently from 5bcfbdf to bfb1918 Compare February 19, 2026 21:42
@blainekasten blainekasten force-pushed the blaine/dx-183-implement-event-tracking-on-python-cli-for-v2-library2 branch 2 times, most recently from eb340f4 to 47bdd7c Compare February 22, 2026 15:50
@stainless-app stainless-app bot force-pushed the next branch 2 times, most recently from 2b35ec4 to 86cee4c Compare March 11, 2026 22:54
@blainekasten blainekasten force-pushed the blaine/dx-183-implement-event-tracking-on-python-cli-for-v2-library2 branch 5 times, most recently from 976e374 to 9207cc2 Compare March 19, 2026 20:30
threading.Thread(target=send_event).start()


def auto_track_command(command: str) -> Callable[[F], F]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is used to wrap every command

@blainekasten blainekasten force-pushed the blaine/dx-183-implement-event-tracking-on-python-cli-for-v2-library2 branch 3 times, most recently from 935647e to efcd5e9 Compare March 22, 2026 12:12
@blainekasten blainekasten force-pushed the blaine/dx-183-implement-event-tracking-on-python-cli-for-v2-library2 branch 2 times, most recently from 2bc26a6 to 93dc463 Compare March 22, 2026 12:16
@blainekasten blainekasten force-pushed the blaine/dx-183-implement-event-tracking-on-python-cli-for-v2-library2 branch from 93dc463 to e97c2b4 Compare March 23, 2026 01:55
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.

1 participant