feat: add telemetry adoption funnel#484
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
📝 WalkthroughWalkthroughThis PR migrates telemetry to a structured command+stage (v2) schema, adds CLI controls ChangesTelemetry v2 Schema and Full Instrumentation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
tests/unit/telemetry-doc.test.ts (1)
22-32: ⚡ Quick winLock the remaining documented telemetry fields too.
This contract test now enumerates the stored fields, but it still skips
agent_targetandspi_enabled. If either drops fromdocs/telemetry.md, CI will miss it even though the runtime/docs advertise both.Suggested assertion additions
expect(doc).toContain('node_major') expect(doc).toContain('graph_size_bucket') expect(doc).toContain('repo_size_bucket') + expect(doc).toContain('agent_target') + expect(doc).toContain('spi_enabled') expect(doc).toContain('failure_bucket') expect(doc).toContain('status_bucket')🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/telemetry-doc.test.ts` around lines 22 - 32, The test telemetry-doc.test.ts currently asserts many telemetry fields but omits two documented fields; update the test by adding assertions on the test variable doc to lock the remaining documented telemetry fields by including checks for 'agent_target' and 'spi_enabled' (e.g., add expect(doc).toContain('agent_target') and expect(doc).toContain('spi_enabled') alongside the other expects in the same file).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/telemetry.md`:
- Around line 67-73: The telemetry docs list omits the newly emitted `failed`
event for some CLI commands; update docs/telemetry.md so the entries for `madar
compare`, `madar doctor`, and `madar status` explicitly include `failed` (e.g.,
change `madar compare` (`succeeded`) to include `failed`, and `madar doctor` and
`madar status` to list both `succeeded` and `failed` while preserving
`status_bucket` for `madar status`), ensuring the documented schema matches the
CLI telemetry contract.
In `@src/cli/main.ts`:
- Around line 405-429: The function classifyTelemetryFailure incorrectly returns
'usage_error' immediately for any UsageError, preventing more specific buckets
from matching; change classifyTelemetryFailure to first derive the normalized
message via messageFromError(error) and run the pattern checks for
'invalid_params', 'missing_graph', 'stale_graph', 'stale_context',
'unsupported_corpus', and 'install_error', and only if none match then fall back
to checking error instanceof UsageError to return 'usage_error' (or finally
'unknown'); refer to classifyTelemetryFailure, UsageError, messageFromError, and
TelemetryFailureBucket when making the change.
In `@src/shared/telemetry.ts`:
- Around line 651-659: readTelemetryReport currently calls loadSpool for every
resolved path without guarding against unreadable paths, causing the whole
report to crash; modify readTelemetryReport so when mapping over resolvedPaths
it calls loadSpool inside a try/catch (or checks readability first using
fs.stat/ access) and skips any path that throws or is not a regular readable
file, optionally logging a warning, then continue to collect events; ensure the
logic around telemetrySpoolFilePath, resolvedPaths, and the events aggregation
remains intact so unreadable inputs are ignored rather than aborting the
function.
---
Nitpick comments:
In `@tests/unit/telemetry-doc.test.ts`:
- Around line 22-32: The test telemetry-doc.test.ts currently asserts many
telemetry fields but omits two documented fields; update the test by adding
assertions on the test variable doc to lock the remaining documented telemetry
fields by including checks for 'agent_target' and 'spi_enabled' (e.g., add
expect(doc).toContain('agent_target') and expect(doc).toContain('spi_enabled')
alongside the other expects in the same file).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 15eb1b45-2c35-4b03-a210-0062f4551952
📒 Files selected for processing (12)
README.mddocs/reference/cli-and-mcp.mddocs/telemetry.mdsrc/cli/main.tssrc/cli/parser.tssrc/infrastructure/doctor.tssrc/runtime/stdio-server.tssrc/shared/telemetry.tstests/unit/cli.test.tstests/unit/stdio-server.test.tstests/unit/telemetry-doc.test.tstests/unit/telemetry.test.ts
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/unit/telemetry-doc.test.ts (1)
33-34: ⚡ Quick winAvoid exact prose matching for doc-contract tests.
These assertions are brittle to harmless wording/Markdown edits. Prefer checking the stable tokens independently so the test still enforces the contract without pinning exact sentence text.
Suggested change
- expect(doc).toContain('`madar compare` (`succeeded`, `failed`)') - expect(doc).toContain('`madar doctor` and `madar status` (`succeeded`, `failed`, plus `status_bucket`)') + expect(doc).toContain('madar compare') + expect(doc).toContain('madar doctor') + expect(doc).toContain('madar status') + expect(doc).toContain('succeeded') + expect(doc).toContain('failed') + expect(doc).toContain('status_bucket')🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/unit/telemetry-doc.test.ts` around lines 33 - 34, The assertions in tests/unit/telemetry-doc.test.ts are brittle because they match exact prose; update the two expectations that currently check exact sentence text (the assertions containing '`madar compare` (`succeeded`, `failed`)' and '`madar doctor` and `madar status` (`succeeded`, `failed`, plus `status_bucket`)') to instead assert the presence of stable tokens independently — e.g., check that doc includes '`madar compare`' and separately includes 'succeeded' and 'failed', and similarly check '`madar doctor`', '`madar status`', 'succeeded', 'failed', and 'status_bucket' — so the contract is enforced without exact markdown sentence matching.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/unit/telemetry-doc.test.ts`:
- Around line 33-34: The assertions in tests/unit/telemetry-doc.test.ts are
brittle because they match exact prose; update the two expectations that
currently check exact sentence text (the assertions containing '`madar compare`
(`succeeded`, `failed`)' and '`madar doctor` and `madar status` (`succeeded`,
`failed`, plus `status_bucket`)') to instead assert the presence of stable
tokens independently — e.g., check that doc includes '`madar compare`' and
separately includes 'succeeded' and 'failed', and similarly check '`madar
doctor`', '`madar status`', 'succeeded', 'failed', and 'status_bucket' — so the
contract is enforced without exact markdown sentence matching.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 8f72d325-5a5a-422f-a824-a070ed8c30a0
📒 Files selected for processing (6)
docs/telemetry.mdsrc/cli/main.tssrc/shared/telemetry.tstests/unit/cli.test.tstests/unit/telemetry-doc.test.tstests/unit/telemetry.test.ts
✅ Files skipped from review due to trivial changes (1)
- docs/telemetry.md
🚧 Files skipped from review as they are similar to previous changes (4)
- tests/unit/telemetry.test.ts
- tests/unit/cli.test.ts
- src/shared/telemetry.ts
- src/cli/main.ts
Summary
Testing
Refs #471
Summary by CodeRabbit
New Features
madar telemetry clearto delete local telemetry spoolsmadar telemetry report [spool.json ...]to view anonymized local reportsDocumentation