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
4 changes: 2 additions & 2 deletions docs/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ sends nothing.
## What is sent

One small HTTPS request to `https://app.diffci.com/v1/usage-events` after each `plan`, `check`,
`observe` and `verify` run (including runs from the GitHub Action, the GitLab component and the MCP
`observe` and `verify` run (including runs from the GitHub Action, the GitLab component, the Azure DevOps task and the MCP
server). It contains:

| Field | Example | Notes |
| --- | --- | --- |
| `command` | `plan` | `plan`, `check`, `observe` or `verify` |
| `outcome` | `selective` | for example `selective`, `full`, `passed`, `failed`, `observed`, `error` |
| `version` | `0.3.30` | CLI version |
| `surface` | `github-action` | `cli`, `local-mcp`, `github-action` or `gitlab-component` |
| `surface` | `github-action` | `cli`, `local-mcp`, `github-action`, `gitlab-component` or `azure-devops-task` |
| `ci` | `true` | whether the run happened in CI |
| `activity` | `external` | `internal` when labelled with `--internal-usage` or `DIFFCI_USAGE_INTERNAL=1` |
| `installation_id` | random UUID | sent only after `diffci telemetry --mode repo` creates and saves one in `~/.diffci/telemetry.json`; a default, never-configured installation sends none; not tied to a person |
Expand Down
3 changes: 2 additions & 1 deletion packages/diffci-cli/src/client/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export function repositoryName(repoPath: string | undefined, env: NodeJS.Process

function surfaceOf(env: NodeJS.ProcessEnv): UsageSurface {
if (env.DIFFCI_MCP === "1") return "local-mcp";
if (env.DIFFCI_SURFACE === "github-action" || env.DIFFCI_SURFACE === "gitlab-component") return env.DIFFCI_SURFACE;
// Each CI wrapper sets its own value: action/, integrations/gitlab and integrations/azure-devops (#303).
if (env.DIFFCI_SURFACE === "github-action" || env.DIFFCI_SURFACE === "gitlab-component" || env.DIFFCI_SURFACE === "azure-devops-task") return env.DIFFCI_SURFACE;
return "cli";
}

Expand Down
2 changes: 1 addition & 1 deletion packages/diffci-cli/src/client/usage-signal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** Best-effort usage signal. Carries a repository name only when given one; never content, paths or machine details. */
export type UsageCommand = "check" | "observe" | "verify" | "plan";
export type UsageOutcome = "observed" | "refused" | "error" | "passed" | "failed" | "blocked" | "selective" | "full";
export type UsageSurface = "cli" | "local-mcp" | "github-action" | "gitlab-component";
export type UsageSurface = "cli" | "local-mcp" | "github-action" | "gitlab-component" | "azure-devops-task";
export interface UsageSignal {
command: UsageCommand;
outcome: UsageOutcome;
Expand Down
18 changes: 18 additions & 0 deletions packages/diffci-cli/tests/client/telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,21 @@ test("delivery distinguishes receipt acceptance, forwarding success, rejection a
}
assert.equal((await deliverUsageSignal({ ...signal, fetchImpl: async () => { throw new DOMException("timeout", "TimeoutError"); } })).status, "timed-out");
});

// #303: the Azure DevOps task runs the CLI with DIFFCI_SURFACE=azure-devops-task
// (integrations/azure-devops/DiffCIObserve/index.js); it was counted as `cli`.
test("each CI wrapper's surface is counted as itself, and unknown values as cli", async () => {
const home = mkdtempSync(join(tmpdir(), "diffci-telemetry-"));
const env = { DIFFCI_TELEMETRY_HOME: home, TF_BUILD: "True" };
const originalFetch = globalThis.fetch;
const originalError = console.error;
const bodies: any[] = [];
globalThis.fetch = async (_url, init) => { bodies.push(JSON.parse(String(init?.body))); return new Response(null, { status: 200 }); };
console.error = () => {};
try {
for (const surface of ["github-action", "gitlab-component", "azure-devops-task", "something-else"]) {
await recordUsage("observe", "observed", "0.3.54", {}, { ...env, DIFFCI_SURFACE: surface });
}
assert.deepEqual(bodies.map((body) => body.surface), ["github-action", "gitlab-component", "azure-devops-task", "cli"]);
} finally { globalThis.fetch = originalFetch; console.error = originalError; rmSync(home, { recursive: true, force: true }); }
});
Loading