diff --git a/docs/telemetry.md b/docs/telemetry.md index aa1ff8a3..322074ca 100644 --- a/docs/telemetry.md +++ b/docs/telemetry.md @@ -7,7 +7,7 @@ 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 | @@ -15,7 +15,7 @@ server). It contains: | `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 | diff --git a/packages/diffci-cli/src/client/telemetry.ts b/packages/diffci-cli/src/client/telemetry.ts index df14c2d3..ec25e197 100644 --- a/packages/diffci-cli/src/client/telemetry.ts +++ b/packages/diffci-cli/src/client/telemetry.ts @@ -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"; } diff --git a/packages/diffci-cli/src/client/usage-signal.ts b/packages/diffci-cli/src/client/usage-signal.ts index ef5aefbf..dc668f3e 100644 --- a/packages/diffci-cli/src/client/usage-signal.ts +++ b/packages/diffci-cli/src/client/usage-signal.ts @@ -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; diff --git a/packages/diffci-cli/tests/client/telemetry.test.ts b/packages/diffci-cli/tests/client/telemetry.test.ts index 147a00ed..cc7a7227 100644 --- a/packages/diffci-cli/tests/client/telemetry.test.ts +++ b/packages/diffci-cli/tests/client/telemetry.test.ts @@ -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 }); } +});