Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,11 @@ flag: `dg --output json <command>`. `dg speak --output FILE` writes audio to

## Telemetry

This version of dg sends no telemetry: no error reports, usage data or other telemetry, whether a command succeeds or fails. dg still contacts the Deepgram API for the commands you run, and pypi.org to check for updates.
When a command fails with an unexpected error, dg sends one error report to Deepgram's Sentry project. Nothing is sent when a command succeeds, `--help` and `--version` included, or for a usage error or another error dg reports to you. Nothing is sent either until dg has told you about this: the first run at a terminal prints a one-time notice, and reports start with the run after it.

The `DEEPCTL_TELEMETRY_DISABLED` environment variable and the `telemetry.enabled` setting in `config.yaml` are still accepted, and the new `--no-telemetry` flag is accepted too, but none of them has an effect in this version. `DEEPCTL_TELEMETRY_DSN` is now ignored unless it points at the local machine, which is for tests. The last line of `dg --help` says that dg sends no telemetry.
A report holds the exception type, the module, function and line number of each stack frame, the command path, the names of the flags used, and the dg version, operating system, CPU architecture and Python version. It never holds flag values or arguments, file names or paths, environment variables, API keys, request or response data, error messages, log output, variable values, your hostname or your username. [docs/telemetry.md](docs/telemetry.md) lists every field.

To turn it off, pass `--no-telemetry` for one command, set `DEEPCTL_TELEMETRY_DISABLED=1` or `DO_NOT_TRACK=1`, or put `telemetry.enabled: false` in your `config.yaml`. It is off whenever `CI` is set. To see a report instead of sending it, run a command with `DEEPCTL_TELEMETRY=log`. The last line of `dg --help` says whether telemetry is on.

## Development

Expand Down Expand Up @@ -554,7 +556,7 @@ cli/
│ ├── deepctl-core/ # Core components for deepctl
│ ├── deepctl-plugin-example/ # Example plugin for deepctl
│ ├── deepctl-shared-utils/ # Shared utilities for deepctl
│ └── deepctl-telemetry/ # Error reporting for deepctl; this version sends no telemetry
│ └── deepctl-telemetry/ # Error reporting for deepctl: unexpected errors only, allowlisted fields
├── tests/ # Integration tests
└── Makefile # Development tasks
```
Expand Down Expand Up @@ -630,7 +632,7 @@ cli/
| [`deepctl-core`](packages/deepctl-core) | Core components for deepctl |
| [`deepctl-plugin-example`](packages/deepctl-plugin-example) | Example plugin for deepctl |
| [`deepctl-shared-utils`](packages/deepctl-shared-utils) | Shared utilities for deepctl |
| [`deepctl-telemetry`](packages/deepctl-telemetry) | Error reporting for deepctl; this version sends no telemetry |
| [`deepctl-telemetry`](packages/deepctl-telemetry) | Error reporting for deepctl: unexpected errors only, allowlisted fields |
<!-- END:packages -->

## Release
Expand Down
6 changes: 5 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ def _disable_telemetry(monkeypatch):
"""Keep tests that call `main()` from initializing real telemetry.

The destination also points at a closed loopback port, so a test that
re-enables telemetry can never reach a real endpoint.
re-enables telemetry can never reach a real endpoint. Without that
variable an editable install has no destination, but a suite run against
built wheels would report to dg's Sentry project (once the first-run
notice has been shown on this machine): a test that removes it must
patch the SDK, and one that starts a child process must pass it on.
"""
monkeypatch.setenv("DEEPCTL_TELEMETRY_DISABLED", "1")
monkeypatch.setenv("DEEPCTL_TELEMETRY_DSN", "http://k@127.0.0.1:9/1")
Expand Down
25 changes: 15 additions & 10 deletions docs/telemetry.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# Telemetry

This version of dg sends no telemetry: no error reports, usage data or other telemetry, whether a command succeeds or fails. It has no built-in destination for reports. dg still contacts the Deepgram API for the commands you run, and pypi.org to check for updates.
When a command fails with an unexpected error, dg sends one error report to Deepgram's Sentry project (`deepgram-cli`). That is all the telemetry dg has: it sends no usage data, and nothing at all when a command succeeds. dg also contacts the Deepgram API for the commands you run, and pypi.org to check for updates.

The error-reporting code is still in dg, and it runs only when `DEEPCTL_TELEMETRY_DSN` points at a sink on this machine (a loopback address such as `127.0.0.1`), which is for tests and local development. A value that points anywhere else is ignored. This page describes what that code does with a loopback sink: when it runs, the switches that turn it off, and the exact fields of a report.
Reporting is on by default, and dg tells you so once before it sends anything. This page describes when a report is sent, the switches that turn reporting off, and the exact fields of a report. The last line of `dg --help` says whether it is on.

## When it runs

- **Only with a loopback `DEEPCTL_TELEMETRY_DSN`.** Without one, dg installs no error hooks, never loads the reporting library, and the last line of `dg --help` says "This version of dg sends no telemetry."
- **At most one report per run**, and only for an unexpected error. Nothing is reported when a command succeeds, for a usage error or another error dg reports to you, or for `--help` and `--version`.
- **Not before dg has told you.** The first time you run a command at a terminal, dg prints a one-time notice on stderr that says reporting is on and how to turn it off. That run sends nothing, and neither does any run before it; reports start with the next run. The notice isn't printed under `--quiet`, for `--help`, or when dg isn't run by a person at a terminal (a script, a container, an AI agent session), so an install that is only ever used that way never sends a report.
- **At most one report per run**, and only for an unexpected error. Nothing is reported when a command succeeds, `--help` and `--version` included, or for a usage error or another error dg reports to you.
- **No network or reporting code on the success path.** The reporting library is loaded only after an unexpected error, so a command that succeeds opens no connection for telemetry.
- **A short time budget.** dg waits about 0.6 s at most for a report, loading included, and doesn't wait at all when no report was queued.
- **No proxy.** A report goes straight to Sentry and doesn't use a proxy from your environment or system settings. If Sentry can't be reached that way, the report is dropped.

## Turn it off

With a loopback sink set, any one of these turns reporting off. They are checked in this order:
Any one of these turns reporting off. They are checked in this order:

| Switch | Scope |
|---|---|
Expand All @@ -26,17 +27,21 @@ With a loopback sink set, any one of these turns reporting off. They are checked

For `DEEPCTL_TELEMETRY_DISABLED`, `DO_NOT_TRACK` and `CI`, any value except an empty one, `0`, `false`, `no` or `off` turns reporting off. `DEEPCTL_TELEMETRY` turns it off when set to `off`, `0`, `false`, `no` or `disabled`; `log` is described below, and any other value changes nothing. A config file dg won't load (unreadable, too large, not valid YAML, a repeated `telemetry` key, or one dg doesn't trust in an AI agent session) counts as turned off too. A project's `deepgram.yaml` can't change these settings.

Reporting is also off when dg runs from a source checkout (an editable install, such as `uv sync` or `pip install -e .`). dg reads that from its own install metadata, so there is nothing to set.

`DEEPCTL_TELEMETRY_DSN` is for tests and local development. Set to a sink on this machine (a loopback address such as `127.0.0.1`), it replaces Sentry as the destination. Set to anything else, an empty value included, it turns reporting off; it can't send reports to another host. A local sink doesn't wait for the first-run notice, since nothing leaves your machine.

## See a report

With a loopback sink set, run a command with `DEEPCTL_TELEMETRY=log`. If it fails with an unexpected error and reporting is on, dg prints the report to stderr as one JSON line and sends nothing, not even to the loopback sink.
Run a command with `DEEPCTL_TELEMETRY=log`. If it fails with an unexpected error and reporting is on, dg prints the report to stderr as one JSON line and sends nothing. This works before the first-run notice has been shown too.

```sh
DEEPCTL_TELEMETRY_DSN=http://key@127.0.0.1:9000/1 DEEPCTL_TELEMETRY=log dg listen recording.wav
DEEPCTL_TELEMETRY=log dg listen recording.wav
```

## Field schema

A report holds these fields and nothing else. A value that doesn't match its expected shape (an identifier, a version string, a command path) is dropped, never shortened or escaped. Names from code outside dg and the libraries it calls, such as a plugin's, are sent as `<other>`.
A report holds these fields and nothing else. A value that doesn't match its expected shape (an identifier, a version string, a command path) is dropped, never shortened or escaped. Names from code outside dg and the libraries it calls, such as a plugin's, are sent as `<other>`, and a plugin command's path and flag names are left out.

<!-- fields:start -->
| Field | Contents |
Expand All @@ -49,8 +54,8 @@ A report holds these fields and nothing else. A value that doesn't match its exp
| `environment` | Always `production` |
| `sdk.name` | Name of the reporting library |
| `sdk.version` | Version of the reporting library |
| `tags.cmd.path` | Command path, such as `dg listen` |
| `tags.cmd.flags` | Names of the flags used, never their values, such as `--model,--output` |
| `tags.cmd.path` | Command path, such as `dg listen` (dg's own commands only) |
| `tags.cmd.flags` | Names of the flags used, never their values, such as `--model,--output` (dg's own commands only) |
| `tags.cli.os` | Operating system, such as `Darwin` |
| `tags.cli.arch` | CPU architecture, such as `arm64` |
| `tags.cli.python` | Python version, such as `3.12.4` |
Expand Down
2 changes: 1 addition & 1 deletion packages/deepctl-core/src/deepctl_core/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def _record_telemetry_context(self, ctx: click.Context) -> None:
try:
from .telemetry_context import record_command

record_command(ctx)
record_command(ctx, type(self).__module__)
except Exception:
pass

Expand Down
2 changes: 1 addition & 1 deletion packages/deepctl-core/src/deepctl_core/config_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ToolsConfig(BaseModel):


class TelemetryConfig(BaseModel):
"""Telemetry setting, still accepted. This version sends no telemetry."""
"""Error-report setting. Read from the user config file only."""

enabled: bool = True

Expand Down
4 changes: 2 additions & 2 deletions packages/deepctl-core/src/deepctl_core/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@
),
"W-PF-TELEMETRY": (
"project files can't change telemetry settings.",
"This version of dg sends no telemetry.",
None,
"Set them in {user_config}.",
AGENT_SETTINGS_HINT,
),
"W-PF-UPDATE": (
"project files can't change update settings.",
Expand Down
26 changes: 20 additions & 6 deletions packages/deepctl-core/src/deepctl_core/telemetry_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
has already loaded. Commands record their context here on every run, and the
telemetry client reads it only if an error is reported.

Only the command path and the *names* of flags the user passed are kept.
Flag values, positional arguments and the program name from argv are never
recorded.
Only the command path and the *names* of flags the user passed are kept,
with the module that defines the command, so telemetry can leave out the
path and flags of a command that isn't one of dg's own. Flag values,
positional arguments and the program name from argv are never recorded.
"""

from __future__ import annotations
Expand All @@ -18,6 +19,7 @@
# Names that look like identifiers. Anything else is dropped rather than
# escaped, so a crafted command or option name can't smuggle data out.
_TOKEN_RE = re.compile(r"^-{0,2}[A-Za-z][A-Za-z0-9_-]{0,63}$")
_MODULE_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_.]{0,127}$")

# Replaced as a whole on each record, never mutated, so a reader on another
# thread sees either the old or the new context, not a mix.
Expand All @@ -28,8 +30,16 @@ def _safe(token: str) -> str | None:
return token if _TOKEN_RE.match(token) else None


def record_command(ctx: click.Context) -> None:
"""Record the command path and user-supplied flag names for this run."""
def _safe_module(module: str) -> str:
return module if _MODULE_RE.match(module) else ""


def record_command(ctx: click.Context, module: str) -> None:
"""Record the command path and user-supplied flag names for this run.

`module` is the module of the command class. Telemetry sends the path
and flags only when it is one of dg's own packages.
"""
chain: list[click.Context] = []
node: click.Context | None = ctx
while node is not None:
Expand Down Expand Up @@ -58,7 +68,11 @@ def record_command(ctx: click.Context) -> None:
flags.add(flag)

global _context
_context = {"command": " ".join(parts), "flags": ",".join(sorted(flags))}
_context = {
"command": " ".join(parts),
"flags": ",".join(sorted(flags)),
"module": _safe_module(module),
}


def command_context() -> dict[str, str]:
Expand Down
5 changes: 5 additions & 0 deletions packages/deepctl-core/tests/unit/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,11 @@ def test_records_flag_names_from_every_level_but_no_values(self):
def test_no_flags_records_empty(self):
assert self._invoke(["listen"])["flags"] == ""

@pytest.mark.unit
def test_records_the_module_that_defines_the_command(self):
# Telemetry sends the path and flags only for dg's own packages.
assert self._invoke(["listen"])["module"] == __name__

@pytest.mark.unit
def test_record_swallows_exceptions(self):
class MockCommand(BaseCommand):
Expand Down
2 changes: 1 addition & 1 deletion packages/deepctl-telemetry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Part of [deepctl](https://github.com/deepgram/cli) — Official Deepgram CLI

Error reporting for deepctl; this version sends no telemetry
Error reporting for deepctl: unexpected errors only, allowlisted fields

This package provides internal APIs for deepctl and its command packages. It is not intended for direct use.

Expand Down
2 changes: 1 addition & 1 deletion packages/deepctl-telemetry/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "deepctl-telemetry"
version = "0.5.0" # x-release-please-version
description = "Error reporting for deepctl; this version sends no telemetry"
description = "Error reporting for deepctl: unexpected errors only, allowlisted fields"
readme = "README.md"
license = "MIT"
authors = [{ name = "Deepgram", email = "devrel@deepgram.com" }]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Error reporting for deepctl. This version sends no telemetry."""
"""Error reporting for deepctl: unexpected errors only, allowlisted fields."""

from .client import disable_for_run, init_telemetry, is_enabled, report_exception
from .first_run import claim_first_run_notice
from .notice import install_help_notice, render_notice

__all__ = [
"claim_first_run_notice",
"disable_for_run",
"init_telemetry",
"install_help_notice",
Expand Down
Loading
Loading