Skip to content
Merged
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
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,30 @@ Run `npx e2e run` with `DEVICE_CLOUD_API_KEY` set. The provider uploads `appPath
With e2e's `video` option on (any setting but `'off'`), each test's video in e2e's report is a console link to that test's part of the session's recording. The session is recorded as one video, so the link plays the part from the test's start to its end; it works once the session has ended and its video has uploaded, for as long as the session's files are kept.


## Telemetry

The CLI sends a small amount of usage and error data to the DeviceCloud API. We use it only for debugging and development: to find and fix bugs, and to see which commands and options are used. It is not used for marketing, and it is not sold.

**What is sent**, for each command run:

- the command name and its arguments, with secrets removed (API keys, `--env` values, text typed into a device, and the query part of any URL, which is where signed links keep their credential)
- whether it succeeded, how long it took, and the error message if it failed (URLs redacted the same way)
- the CLI version, how it was installed, the Node.js version, the OS and CPU architecture
- how you signed in (API key or `dcd login`), your organization ID, and a random ID for this run
- whether the app, flows and env vars were encrypted

Nothing is sent until a command has signed in, so `--help`, `--version` and `dcd login` itself send nothing. Telemetry goes to the same API the command uses (`--api-url`, or the default). A failure to send it never affects the command.

**Turning it off.** Set either of these in your environment:

```sh-session
$ export DO_NOT_TRACK=1 # the cross-tool convention, see consoledonottrack.com
$ export DCD_TELEMETRY_DISABLED=1
```

`0`, `false` or an empty value leaves telemetry on. For the MCP server, add the variable to the `env` block of your MCP client's config.


## Development

Requires Node 22.8+ and [pnpm](https://pnpm.io). `pnpm install` builds the CLI and installs the git hooks automatically.
Expand Down
21 changes: 18 additions & 3 deletions src/services/telemetry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
* - `flushSync()` — sync via `curl`, used inside `logger.error` right before
* `process.exit` (no other way to send HTTP after exit is called)
*
* Opt out: `DCD_TELEMETRY_DISABLED=1` in the environment.
* Opt out: `DCD_TELEMETRY_DISABLED=1` or `DO_NOT_TRACK=1` in the environment
* (see telemetryDisabled).
*/
import { execFileSync } from 'node:child_process';
import { randomUUID } from 'node:crypto';
Expand Down Expand Up @@ -82,6 +83,21 @@ interface TelemetryConfig {

const DEFAULT_API_URL = 'https://api.devicecloud.dev';

/** Set to something other than empty, `0` or `false` (in any case). */
function isOn(value: string | undefined): boolean {
const v = value?.trim().toLowerCase();
return v !== undefined && v !== '' && v !== '0' && v !== 'false';
}

/**
* Whether the user has turned telemetry off: `DCD_TELEMETRY_DISABLED`, or
* `DO_NOT_TRACK`, the cross-tool convention (https://consoledonottrack.com).
* `0` or `false` leaves telemetry on, so `DO_NOT_TRACK=0` means what it says.
*/
export function telemetryDisabled(env: NodeJS.ProcessEnv = process.env): boolean {
return isOn(env.DCD_TELEMETRY_DISABLED) || isOn(env.DO_NOT_TRACK);
}

class Telemetry {
private buffer: TelemetryEvent[] = [];
private config: TelemetryConfig | null = null;
Expand All @@ -90,7 +106,7 @@ class Telemetry {
private submitAttempts: number | undefined;
private sessionId: string = randomUUID();
private startedAt: number = Date.now();
private readonly disabled: boolean = !!process.env.DCD_TELEMETRY_DISABLED;
private readonly disabled: boolean = telemetryDisabled();
private readonly release: string = getCliVersion();

/**
Expand Down Expand Up @@ -348,7 +364,6 @@ class Telemetry {
nodeVersion: process.versions.node,
platform: process.platform,
arch: process.arch,
userEmail: this.config.auth.userEmail,
orgId: this.config.auth.orgId,
};
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/telemetry-api-url.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';

import { telemetry } from '../../src/services/telemetry.service.js';
import { telemetry, telemetryDisabled } from '../../src/services/telemetry.service.js';

/**
* Events go to the API the command itself talks to. A login's stored API used
Expand All @@ -14,7 +14,7 @@ describe('telemetry API URL', () => {

beforeEach(function () {
// The singleton reads this once, at import.
if (process.env.DCD_TELEMETRY_DISABLED) this.skip();
if (telemetryDisabled()) this.skip();

urls = [];
globalThis.fetch = (async (input: unknown) => {
Expand Down
29 changes: 29 additions & 0 deletions test/unit/telemetry-disabled.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect } from 'chai';

import { telemetryDisabled } from '../../src/services/telemetry.service.js';

/** The two env vars that turn telemetry off, and the values that don't. */
describe('telemetryDisabled', () => {
it('is off (telemetry on) with neither var set', () => {
expect(telemetryDisabled({})).to.equal(false);
});

for (const name of ['DCD_TELEMETRY_DISABLED', 'DO_NOT_TRACK']) {
for (const value of ['1', 'true', 'TRUE', 'yes', ' 1 ']) {
it(`turns telemetry off for ${name}=${JSON.stringify(value)}`, () => {
expect(telemetryDisabled({ [name]: value })).to.equal(true);
});
}

for (const value of ['', '0', 'false', 'False', ' 0 ']) {
it(`leaves telemetry on for ${name}=${JSON.stringify(value)}`, () => {
expect(telemetryDisabled({ [name]: value })).to.equal(false);
});
}
}

it('turns telemetry off when either var says so', () => {
expect(telemetryDisabled({ DCD_TELEMETRY_DISABLED: '0', DO_NOT_TRACK: '1' })).to.equal(true);
expect(telemetryDisabled({ DCD_TELEMETRY_DISABLED: '1', DO_NOT_TRACK: '0' })).to.equal(true);
});
});
3 changes: 2 additions & 1 deletion test/unit/telemetry-encryption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { jsonResult, runTool } from '../../src/mcp/helpers.js';
import {
type EncryptionTelemetry,
telemetry,
telemetryDisabled,
} from '../../src/services/telemetry.service.js';

/**
Expand All @@ -22,7 +23,7 @@ describe('encryption telemetry (#1138)', () => {

beforeEach(function () {
// The singleton reads this once, at import.
if (process.env.DCD_TELEMETRY_DISABLED) this.skip();
if (telemetryDisabled()) this.skip();

events = [];
globalThis.fetch = (async (_input: unknown, init?: RequestInit) => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/telemetry-submit-attempts.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';

import { telemetry } from '../../src/services/telemetry.service.js';
import { telemetry, telemetryDisabled } from '../../src/services/telemetry.service.js';

/**
* How many attempts the flow submit took (dcd#1617 follow-up) rides on the
Expand All @@ -19,7 +19,7 @@ describe('submit attempts telemetry', () => {

beforeEach(function () {
// The singleton reads this once, at import.
if (process.env.DCD_TELEMETRY_DISABLED) this.skip();
if (telemetryDisabled()) this.skip();

events = [];
globalThis.fetch = (async (_input: unknown, init?: RequestInit) => {
Expand Down
Loading