Agent Wranglers

DEV-15Recommended

Send no telemetry from CI or when DO_NOT_TRACK is set

Send no usage data when DO_NOT_TRACK=1, when the tool's own variable such as EXAMPLE_TELEMETRY=0 is set, or when CI is set. Before the first send, print what the tool collects and how to turn it off.

How to do it

Whether telemetry may start at all follows Send usage data only after the user says yes. A command-line tool needs more, because it runs unattended. GitHub Actions sets CI to true on every run, and other CI services set it too. DO_NOT_TRACK is a variable many command-line tools share, so one setting silences them all. List every field you send in the docs. Offer example telemetry status and a flag that prints the payload instead of sending it. Send in the background with a 1 second time limit, and drop the data on any error, so telemetry never slows or fails a command.

Examples

JavaScript example

function telemetryAllowed(env = process.env, settings) {
  if (env.DO_NOT_TRACK === '1' || env.EXAMPLE_TELEMETRY === '0' || env.CI) return false
  return settings.telemetry === 'on'
}

Python example

import os

def telemetry_allowed(settings, env=os.environ) -> bool:
    if env.get("DO_NOT_TRACK") == "1" or env.get("EXAMPLE_TELEMETRY") == "0" or env.get("CI"):
        return False
    return settings.get("telemetry") == "on"

How to check

A test runs a command three times, once with each variable set. A network capture shows no request to the telemetry host. Without them, the first run prints the notice to standard error before any request. With the telemetry host unreachable, the command's run time grows by less than 1 second and its exit code is unchanged.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/developer-tools/configuration-and-telemetry/cli-telemetry-off">Agent Wranglers developer tools, SDKs and CLIs playbook</a>. In code you write, add a comment next to it with the same link.